New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gammaspec.py changes #1046
base: develop
Are you sure you want to change the base?
gammaspec.py changes #1046
Conversation
@@ -91,7 +91,21 @@ def test_gross_counts(): | |||
def test_net_count(): | |||
nc=sa.net_counts(gspec1, 475, 484, 1) | |||
|
|||
|
|||
def test_read_spec_id_file(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this working? You don't seem to actually call read_spec_id_file()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's called at global scope
@scopatz, It seems I forgot to add another gspec variable to call read_spec_id_file(). Ill edit this file to add gspec3 which calls read_spec_id_file(). |
OK! Just post to this issue when you have it figured out! |
gspec3 variable has been added to test_spectrometry.py and test_read_spec_id_file() has been edited to test the read_spec_id() function. I also added another module called gamma_effect.py that calculates the compton edge energy, backscatter energy ,single escape energy, and double escape energy when given an input energy. A test function has been created for this module and is called test_gamma_effects.py. |
"""Returns compton edge energy from a given gamma energy""" | ||
E_compton = E- E/(1+(2*E/mec2)) | ||
return E_compton | ||
def backscatter(E): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: two spaces between functions.
pyne/gamma_effects.py
Outdated
|
||
""" | ||
|
||
mec2 = 511. #keV # Rest mass energy of an electron #.511 MeV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global variables should be ALL_UPPERCASE
Thanks @KennellyT - just let me know here, when you think this PR is ready to go! |
Changed pull request to mirror comments. Also added srim_read.py, a function that reads srim files. Also added writecsv function in gammaspec.py. |
Update of the above pull requests:
|
pyne/gamma_effects.py
Outdated
@@ -0,0 +1,35 @@ | |||
"""Purpose: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use numpydoc format. So you don't need "purpose" and the following lines shouldn't be indented. thanks!
pyne/gamma_effects.py
Outdated
|
||
def compton_edge(E): | ||
"""Returns compton edge energy from a given gamma energy""" | ||
E_compton = E- E/(1+(2*E/MEC_2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a single space in front of the minus: E - E/
pyne/gamma_effects.py
Outdated
def single_escape(E): | ||
"""Returns single escape energy from a given gamma energy""" | ||
if (E < 1022): #keV | ||
raise RuntimeError('E needs to be equal to or greater than 1022 keV to be valid') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a ValueError instead of a RuntimeError, I would think.
pyne/gamma_effects.py
Outdated
def double_escape(E): | ||
"""Returns double escape energy from a given gamma energy""" | ||
if (E < 1022): #keV | ||
raise RuntimeError('E needs to be equal to or greater than 1022 keV to be valid') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueError again.
pyne/srim_read.py
Outdated
long_straggs=None,long_stragg_units=None,lat_straggs=None, | ||
lat_stragg_units=None): | ||
"""Define srim specific variables """ | ||
super(srim, self).__init__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to call super, but it doesn't hurt.
pyne/srim_read.py
Outdated
warn(__name__ + " is not yet QA compliant.", QAWarning) | ||
|
||
|
||
class srim(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class name should be CapCase
, so this should be Srim
or similar.
pyne/srim_read.py
Outdated
|
||
|
||
class srim(object): | ||
"""srim class includes srim specific variables""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring doesn't help users who don't know what srim is. Could you expand please? Thanks!
pyne/srim_read.py
Outdated
ion_units=None,proj_ranges=None,proj_range_units=None, | ||
long_straggs=None,long_stragg_units=None,lat_straggs=None, | ||
lat_stragg_units=None): | ||
"""Define srim specific variables """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring should include the meaning and type of all of the arguments and keyword arguments (except self
, which doesn't need to be documented.)
pyne/srim_read.py
Outdated
return print_string | ||
|
||
def read_srim_output(filepath): | ||
#def read_srim_output(file_path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented out code line
tests/test_spectrometry.py
Outdated
import warnings | ||
from pyne.utils import QAWarning | ||
warnings.simplefilter("ignore", QAWarning) | ||
|
||
from pyne import gammaspec | ||
#from pyne import gammaspec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove commented out lines like this.
tests/test_spectrometry.py
Outdated
|
||
def test_end_point_average_area(): | ||
nc = sa.end_point_average_area(gspec1,475,484,var=5) | ||
#assert_equal(nc,20355.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the tests here have an assert? Is the problem that you are doing a float comparison? You should probably use assert_almost_equals
in this case
Thanks for the update @KennellyT! |
@scopatz- I took your comments and advice and implemented them into the pull request. readme.rst file had an issue where it states:
but version is not in the conda install -c statement nor is it needed to install pyne via conda via https://anaconda.org/conda-forge/pyne I have updated srim_read and class by adding the meaning of the variables. |
@KennellyT pleased to see this get some attention, its been on my todo list since I first wrote the initial read functions, when I was first learning python |
@py1sl - I'll look at your mariscotti peak find routine/code as I have developed a peak finder function using the second derivative test and Savitzky Golay filter but I have not fully tested the function on a wide variety of gamma spectra. |
@KennellyT ... this seems ready to merge to me. I see that @py1sl has suggested a peak finding method as well. Perhaps we can merge this and add a future issue for peak finding. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution @KennellyT - sorry that it has been sitting untended for so long...
I have a few little comments, but will otherwise look to merge this soon.
y = spec.counts[c1:c2] | ||
n = len(x) | ||
mean = sum(x*y)/n | ||
sigma = np.sqrt(sum(y*(x-mean)**2)/n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this sigma
ever used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the sigma variable goes into the gauss function (line 240) def gauss(x,amp,x_center,sigma):
but in hindsight, this operation can be done in a much cleaner and more efficient manner. I'll take out the gauss function (line 240) and replace it with either its own variable or make the function separate from the gaussian_fit
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this sigma
does NOT get used in the gauss()
function.... that function has an argument named sigma
that gets populated automatically by the curve_fit
method. The initial guess for this value appears to be n/2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I now see the sigma
issue. I'll replace the n/2
with sigma
. Thank you!
return end_point_average | ||
|
||
def gaussian_fit(spec,c1,c2): | ||
"""Plots the gaussian fit to the raw data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to separate the curve fitting from the plotting in case users want to fit without plotting. This would let you reuse it in the fwhm()
function below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur and I will separate this function into two
net_area = p - ((n/2.0)*(count1+count2)) | ||
return net_area | ||
|
||
def end_point_average_area(spec,c1,c2,var=5): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be equivalent to net_area
if var
= 1. I don’t think it is, thanks to python indexing. If it should be, then net_area
should just Call this with var=1
Appears that my additions are failing in |
You might need to rebase your code against |
I'd like to push for a merge on this @KennellyT - let me know if you want any assistance in rebasing and moving this foward |
… gammaspec.py and added test to test_spectometry.py
…d new module srim_read.py with files Helium and test_srim_read.py
…rometry after reviewing comments
fc94593
to
72796b1
Compare
Hi @KennellyT, are you still working on this? |
Functions are now undercase with underscore, added extra line on the bottom of gammaspec.py, and added a test to test spectrometry.py