Page 2 of 2 First 12
1. #### Something like this

See attached .pdf . We handled the graph back in post 8, and the curve fitting in post 12.

If I weren't a nuclear engineer I wouldn't help so much.
Code:
def reports(output):
with open(output) as f:
count = 1                  #this defines the number of tallies in the output file
x = 101                    #this is the first surface number
r = str('surface  %d' % x) #r is a variable used to help find the point where the results start.
d = 0 #initializes depth variable
c = 0 #intilizes the c variable used in the while loop
p = 0 #initializes variable for calculating percent change
#The following while loop skips each line until it comes across the line defined in r
Flux = []
SEM = []
Depth = []
Change = []
while count < 10:
while c != r:
c = line.strip()
numbers = line.strip().split()
Flux.append(numbers[0])
SEM.append(numbers[1])
Depth.append(d)
p = '%g'%(100*((float(Flux[0])-float(Flux[-1])) / float(Flux[0]))) #calculates percent change
Change.append(p)
d += 4
count += 1
x += 4
r = str('surface  %d' %x)
with open('Report.tex', 'w') as table:
table.write(START)
for T in zip(Depth,Flux,Change,SEM,):
table.write('%d & %9.3e & %5.1f & %6.4f\\\\\n'%tuple(float(x) for x in T))
table.write('\\hline\n')
table.write(END)

print('Report.tex created, now command   pdflatex Report  .')

START = r'''
\documentclass[12pt]{report} %

\begin{document} %

MCNPX Simulation For XXXXX %

\begin{tabular}{|lrrr|} %
\hline %
Depth&\multicolumn{1}{c}{Flux}&\multicolumn{1}{c}{Reduction}&\multicolumn{1}{c|}{SEM}\\ %
&\multicolumn{1}{c}{$\frac{n}{cm^2s}$}&\multicolumn{1}{c}{\%}&\multicolumn{1}{c|}{\ }\\ \hline %
'''

END = r'''
\end{tabular}
\end{document}
'''
Last edited by b49P23TIvg; January 8th, 2013 at 08:11 PM.
2. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
25
Rep Power
0
Wow...I guess you know your stuff. It all makes sense now though! So I guess you recognized the MCNP output file right away then? I could tell you were a scientist/engineer of some sort just because of how familiar you were with processing data. But nuclear engineer as well, no too many of us out there.

So now we are geting into LaTex with creating a pdf report. I don't have LaTex installed right now. The mac installer file is quite large (>2 gigs) so I am going to wait until I am at school tomorrow to download at install it. Since I am not familiar with LaTex in order to create the pdf report I will have to exit out of the python command line and run pdflatex separately correct?

I am looking into gnuplot. It looks like the graphs I typically see in the literature I read so it is nice to finally know where they come from. It looks like it has a small learning curve but not much, really just command line stuff. From my limited research it is probably best to have the data output into a text document like I had earlier for gnuplot right?
3. I recognized neutron flux.

Python has a subprocess module; you could run pdflatex from python. For standard reports this might even be a good plan. Form letters to a zillion people with only name address changes, for example. I customize my reports in a text editor (emacs) and run latex by hand.

This online book is pretty good.
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
25
Rep Power
0
Here is the output from the a full blown output file. Looks really nice!

https://dl [dot] dropbox [dot] com/u/14334980/Report.pdf

I think something with the mac command line doesn't allow me to execute latex while in python but it is easy to just ctrl+d out and then type the command.
5. awesome!

The row starting with 148 is messed up.

You might be able to suspend python with C-z
(^Z), run latex and xdvi, then resume python.

Commands like

fg
jobs
bg

are built into the shell. man bg' won't help, you need
man bash

You can also open many terminal windows.

I use about 4 shell buffers in emacs.
6. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
25
Rep Power
0
I'm doing a slight modification to this program now to read a different kind of file. I am currently getting this error:

Code:
>>> from rnaa import reports
>>> reports('naa')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rnaa.py", line 22, in reports
energy.append(numbers[0])
IndexError: list index out of range
>>>
This happens when my second while loop is as follows with the variable b being anything greater than 1:
Code:
 while b<4097:
numbers = line.strip().split()
energy.append(numbers[0])
counts.append(numbers[1])
SEM.append(numbers[2])
b+=1
If I set b to less than 1 the file runs but of course my graph and report come up as only the first line of the data I want. The entire program is as follows:

Code:
def reports(output):
with open(output) as f:
r = str('cell  400') #r is a variable used to help find the point where the results start.
c = 0 #intilizes the c variable used in the while loop
#The following while loop skips each line until it comes across the line defined in r
import numpy as np
import matplotlib.pyplot as plt

while c != r:
c = line.strip()

b=0
energy = []
counts = []
SEM = []
while b<4097:
numbers = line.strip().split()
energy.append(numbers[0])
counts.append(numbers[1])
SEM.append(numbers[2])
b+=1

table = open('Report.txt', 'w')
table.write('================================================================ \n')
table.write('MCNPX NAA Simulation For XXXXX                                   \n')
table.write('================================================================ \n')
table.write('================================================================ \n')
table.write('Energy(MeV)          Counts          SEM             \n')
table.write('================================================================ \n')
for (E,C,S,) in zip(energy,counts,SEM,):    ####### zip is roughly a matrix transposition.
table.write(str(E).ljust(8) + '     ' +
str(C).ljust(10) + '     ' +
str(S) + '\n')
print('Report created')
table.close()

plt.rcParams['legend.loc'] = 'best'
plt.figure(1)
plt.xlim(1e-6, 3)
plt.autoscale(enable=True, axis='y', tight=None)
plt.plot(energy, counts, 'b')
plt.xlabel('Energy (MeV)')
plt.ylabel('Counts')
plt.title('Gamma Spectrum')

print('plots created')
plt.show()`
The input file I am using is located here:
https://dl [dot] dropbox [dot] com/u/14334980/naa

So I understand the problem based on the output is that the program is not going onto and reading the next line but I do not understand why it is not.
7. I deleted the plt lines, which don't seem like they'd interfere, and was unable to duplicate the problem.

Something weird happens at
5.11E-01 7.25E-08 0.0027
8. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
25
Rep Power
0
Originally Posted by b49P23TIvg
I deleted the plt lines, which don't seem like they'd interfere, and was unable to duplicate the problem.

Something weird happens at
5.11E-01 7.25E-08 0.0027
Well this is very weird then. I to deleted them to see if I could duplicate your results but I still get the index out of range error. What happens for you at that 0.0027 line? That's roughly 25-30% through the data which is odd. I'm going to try running this on some other computers at school tomorrow to see if I can duplicate the results there.
9. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
25
Rep Power
0
Well I figured it out. The program worked just fine. Something about how OSX makes .txt files is messed up. I shortened the original MCNPX output file just for testing purposes and something happened in that process. After being frustrated with the program all morning I finally ran the original output file and everything worked like it should. Stupid mac. Thanks again for your continued help. Here is the final output for this program:

https://dl [dot] dropbox [dot] com/u/14334980/naa.png
Page 2 of 2 First 12