Skip to content
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

[TEP007] Isotope stratified file support #764

Merged
merged 11 commits into from
Jul 19, 2017

Conversation

vg3095
Copy link
Contributor

@vg3095 vg3095 commented Jul 12, 2017

This PR is related to adding support for reading stratified abundances with isotopes . This is rebased over PR #762 (Isotope uniform config)

I have added 2 functions -

  • read_simple_isotope_abundances : To read isotope abundances file in new format
  • convert_abundances_format : To convert old abundances file format to new one

For sample seeing output:
Notebook
iso_abund.csv
Config

@vg3095
Copy link
Contributor Author

vg3095 commented Jul 12, 2017

Travis fail is due to Mac build timeout.

@unoebauer unoebauer closed this Jul 13, 2017
@unoebauer unoebauer reopened this Jul 13, 2017
Copy link
Contributor

@unoebauer unoebauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether we can simplify the configuration a bit. In particular, I am thinking of the following changes:

  • Remove the second line in the stratified file (containing E and Is); it is clear from the header whether the column contains abundances of elements or isotopes; if the identifier in the header contains a number it is an isotope, otherwise an element
  • remove the additional config identifier filetype: isotopes; we could achieve legacy support by checking for a header line; if it is present we assume the new csv format, if not we assume the old format.

Thoughts on this, @vg3095, @wkerzendorf, @yeganer ?

@vg3095
Copy link
Contributor Author

vg3095 commented Jul 13, 2017

  • I agree on the 1st point, I think we can remove this. I found out that pyne module has a dictionary/mapping between element symbol and its atomic number , and it takes only normal elements( not isotopes). It is found in pyne.nucname.name_zz . If present in this dictionary/mapping, it means its a normal element else isotope.

  • For second point, I think, if we remove isotopes option, then also , we have to somehow specify that header is present in the config , or I have to check for the first row, if it contains numbers or elements. We can also use try/except inside existing abundances parser. If it can't parse file, then it will re-route to isotope-parser. I don`t know , if this good or not . So, for 2nd point , I am not sure.

@@ -85,19 +85,66 @@ def read_abundances_file(abundance_filename, abundance_filetype,
"""

file_parsers = {'simple_ascii': read_simple_ascii_abundances,
'artis': read_simple_ascii_abundances}
'artis': read_simple_ascii_abundances,
'isotopes': read_simple_isotope_abundances}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually call this tardis_model. I think this can be some sort of default model. where you specify things in this way

@vg3095 vg3095 force-pushed the isotope_file_config branch from 9043a33 to b1799e7 Compare July 14, 2017 06:06
@vg3095
Copy link
Contributor Author

vg3095 commented Jul 14, 2017

I have removed the 2nd header line('E' or 'I') and changed filetype name to tardis_model. Notebook in the description is updated.

#Assign header row
df.columns = [nucname.name(i)
for i in range(1, df.shape[1] + 1)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nucname.name(i) will throw an error, if somebody a wrong specifies an element or isotope identifier, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will throw a Runtime Error with the wrong name of element/isotope. Ex- RuntimeError: Not a Nuclide! XYZ --> 0, where XYZ is wrongly specified element.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

abundance_filename)
else:
index, abundances = file_parsers[abundance_filetype](
abundance_filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we improve here? Something like

index, abundances, isotope_abundance = file_parser[abundance-filetype]

such that we don't need the if clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If, read_simple_ascii_abundances function returns an extra None (instead of (index,abundance), returning index,abundance,None)) , then we can remove this. But I don`t think , its a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine with me

@wkerzendorf
Copy link
Member

@vg3095 I overlooked that before - but we definitely need tests and documentation for all of this.

@vg3095 vg3095 force-pushed the isotope_file_config branch from b1799e7 to c565565 Compare July 17, 2017 03:42
@vg3095
Copy link
Contributor Author

vg3095 commented Jul 17, 2017

@wkerzendorf I have now updated this PR with tests.

@wkerzendorf
Copy link
Member

@vg3095 in your examples - you should try to make the abundances add up to one 😉

@@ -256,3 +264,31 @@ def read_simple_ascii_abundances(fname):
abundances = pd.DataFrame(data[1:,1:].transpose(), index=np.arange(1, data.shape[1]))

return index, abundances


def read_simple_isotope_abundances(fname, delimiter=','):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default delimiter should be a whitespace. this is a special option in read_csv.

@@ -0,0 +1,11 @@
C,Mg,Si,Ni56,Ni58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default delimiter should be whitespace.

@vg3095
Copy link
Contributor Author

vg3095 commented Jul 17, 2017

@wkerzendorf I have now updated csv files

@wkerzendorf
Copy link
Member

@vg3095 can you rebase this. @tardis-sn/tardis-core looks good from my side - can someone else have a look?

abundance_filename)
else:
index, abundances = file_parsers[abundance_filetype](
abundance_filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine with me

#Assign header row
df.columns = [nucname.name(i)
for i in range(1, df.shape[1] + 1)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

@wkerzendorf wkerzendorf merged commit 87fe983 into tardis-sn:decay Jul 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants