-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
Decay of isotopes branch #801
Merged
Merged
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
541897d
added a new structure that can hold isotopes and be decayed
wkerzendorf aa49e27
Add unit test for decay method
vg3095 b609640
Sort dataframe index in IsotopeAbundances class
vg3095 e0e3c04
Merge pull request #756 from vg3095/radioactive_decay
wkerzendorf 96a42c5
Add option to read uniform isotope_abundance in Model
vg3095 aaa218d
Normalize isotope abundances
vg3095 0297ba7
Seperate type of abundances under Model from_config
vg3095 4886a7d
Use pyne to parse isotopes
vg3095 721bc69
Fix import and a typo
vg3095 9992da2
Move isotope_abundance up in initialization list
vg3095 495b874
Move uniform abundance code block to separate func
vg3095 2171cc3
Use pyne to parse uniform normal abundances
vg3095 7ca593a
Merge pull request #762 from vg3095/isotope_config
wkerzendorf 518ae3b
Added a isotope abund. file parser
vg3095 a0db95c
Assign isotope abund. in model
vg3095 bcd7861
Func. to convert old abund. file to new format
vg3095 5ec16dc
Fix typo in comments
vg3095 30d5cfd
Misc changes in isotope abund. file parser
vg3095 23b4001
Add files related to new isotope config options
vg3095 c565565
Add tests for isotope config options
vg3095 6867223
Update docs for uniform abundance config option
vg3095 f36e1b5
Include csv in setup_package.py under io
vg3095 275ad56
Add basic info for new csv format for abund.
vg3095 58d7a20
Rearrange columns in csv file
vg3095 0a45080
Add isotope csv config example and files
vg3095 47bfeb2
Some fixes
vg3095 c25e266
Add example in docs for converting abund. format
vg3095 34a2b0a
Use space delimeter
vg3095 fe0283d
Update csv file to make sum of abund. one
vg3095 a90a1b1
Add note in stratified abundance docs
vg3095 28b52b0
Rearrange Ni isotopes in docs
vg3095 87fe983
Merge pull request #764 from vg3095/isotope_file_config
wkerzendorf 9be16b1
Merge pull request #767 from vg3095/docs_isotope
wkerzendorf 7c517d1
Add a decay method under Model class
vg3095 018922e
Update Model decay method
vg3095 f949d79
Decay model if isotope_abundance parameter is present
vg3095 c399dae
Fix for missing self positional argument
vg3095 f18d012
Added test to check merge operation for abundance
vg3095 6d073b5
Update merge operation for abundance
vg3095 1ccaced
Move as_atomic_numbers method to IsotopeAbundances class
vg3095 ce10dbe
Added test for as_atomic_numbers method
vg3095 b7e528a
Move up isotope_abundance in initialization and use pd.add() while me…
vg3095 9e122be
Move decay of isotope_abundance under Model abundance property
vg3095 174d024
Use pd.groupby to merge isotopes
vg3095 3ad7ebd
Change tests for decay
vg3095 67e9c37
Fix typo in comment
vg3095 007df67
Change name of func. in IsotopeAbundances class
vg3095 a5ed7a2
PEP8 fixes
vg3095 d9a5783
Use changed func. name in decay methods and its test
vg3095 e8c2745
Add cmfgen2tardis script
vg3095 2e02633
Fix for scripts/__int__,py
vg3095 190000f
Use argparse for cmfgen2tardis script
vg3095 c0f17b5
Move cmfgen2tardis script inside tardis package
vg3095 53c2283
Make isotope_abundance instance of IsotopeAbundances in model.from_co…
vg3095 a0f915f
Added doc from cmfgen2tardis script
vg3095 061183a
Add a cmfgen density file parser
vg3095 8a0ad25
Add tardis_model in density schema
vg3095 26399a0
Overwrite electron_densities if already present
vg3095 337c16a
Make electron_densities default None
vg3095 6bf3476
Use _electron_densities instead of electron_densities
vg3095 1690158
Change tardis_model parser structure
vg3095 ac24617
Overwrite electron_densities in IonNumberDensityHeNLTe
vg3095 85b037a
Correction while parsing temp.
vg3095 3dc0e68
Reversing attr. in read_cmfgen_density func.
vg3095 0016858
Added tests for cmfgen density parser
vg3095 1cdd63d
Added tests for new tardis_model density config
vg3095 ad7e379
Changes to cmfgen script
vg3095 f7a5c6f
Mention about DAT files, in scripts doc
vg3095 ae19f84
Some changes in tardis_model density parser
vg3095 42b4ae8
Add a comment about reversing columns in script.
vg3095 56739b2
Remove index col. and change col. names to lowercase
vg3095 32629f3
Add docstring for read_cmfgen_density method
vg3095 ba5eb8e
Change tardis_model abund. parser
vg3095 b5159ee
Common CSV file for tardis_model related parser
vg3095 a31ad72
Delete old tardis_model config and abund,density files
vg3095 6402010
Save cmfgen quantities in one CSV file.
vg3095 edc4ffa
Merge pull request #757 from vg3095/model_decay
wkerzendorf af283e5
Add quantities row
vg3095 503e7d6
Read quantities from CSV file
vg3095 bc8e36b
Rearrange columns in dataframe
vg3095 b2566bc
Update CSV file for tests
vg3095 ad7c784
Update docstring for cmfgen parser
vg3095 4c6119a
Replace gm/cm^3 to g/cm^3
vg3095 5313ddd
Change gm/cm^3 to g/cm^3
vg3095 f6d00b7
Merge pull request #771 from vg3095/tardis_script
wkerzendorf 287e25e
Merge pull request #772 from vg3095/cmf_density
wkerzendorf efcc374
Merge branch 'master' into decay
wkerzendorf ac8e671
Fix when electron_densities is read from a file
vg3095 37c4ebf
Merge pull request #802 from vg3095/plasma_ion_fix
wkerzendorf 5065193
add new scipy version due to failing osx build
wkerzendorf 41c6222
Fix reference dictionary problem
pfreddy 636b18b
Fix 'nan' problem
pfreddy 980716e
Change 'nan' to 0.0 in isotope abundances
pfreddy 080c30c
Fix missing key problem in case of zero isotope abundances
pfreddy 1f516f0
Merge pull request #806 from pfreddy/fix_decay
wkerzendorf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,7 @@ model: | |
Mg: 0.03 | ||
Si: 0.52 | ||
S: 0.19 | ||
Ar: 0.04 | ||
Ar: 0.02 | ||
Ca: 0.03 | ||
Ni56: 0.01 | ||
Ni58: 0.01 |
5 changes: 5 additions & 0 deletions
5
docs/examples/tardis_configv1_isotope_abundance_cust_example.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
model: | ||
abundances: | ||
type: file | ||
filename: tardis_model_abund.csv | ||
filetype: tardis_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
C O Mg Si Ni56 Ni58 | ||
0 0 0 0.6 0.4 0 | ||
0 0 0 0.1 0.5 0.4 | ||
0 0 0 0.3 0 0.7 | ||
0 0.2 0.8 0 0 0 | ||
0 0.3 0.7 0 0 0 | ||
0 0.2 0.8 0 0 0 | ||
0 0.2 0.8 0 0 0 | ||
0 0.2 0.8 0 0 0 | ||
0.5 0.5 0 0 0 0 | ||
0.5 0.5 0 0 0 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
*************** | ||
Running scripts | ||
*************** | ||
|
||
Convert CMFGEN files to TARDIS file format | ||
========================================== | ||
|
||
This script takes a CMFGEN file as an input , and an output path to save converted files in new TARDIS file format. | ||
CSV file contains abundances of both elements and isotopes. | ||
DAT file contains values of velocity, density, electron_density and temperature. | ||
|
||
Format of command - :code:`cmfgen2tardis /path/to/input_file path/to/output/` | ||
|
||
Example, for how to use- | ||
|
||
|
||
.. code-block:: bash | ||
|
||
$ cmfgen2tardis tardis_example/DDC15_SN_HYDRO_DATA_0.976d tardis_example/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import pandas as pd | ||
from pyne import nucname, material | ||
from astropy import units as u | ||
|
||
class IsotopeAbundances(pd.DataFrame): | ||
|
||
@property | ||
def _constructor(self): | ||
return IsotopeAbundances | ||
|
||
def _update_material(self): | ||
self.comp_dicts = [dict() for i in xrange(len(self.columns))] | ||
for (atomic_number, mass_number), abundances in self.iterrows(): | ||
nuclear_symbol = '%s%d'.format(nucname.name(atomic_number), | ||
mass_number) | ||
for i in xrange(len(self.columns)): | ||
self.comp_dicts[i][nuclear_symbol] = abundances[i] | ||
|
||
@classmethod | ||
def from_materials(cls, materials): | ||
multi_index_tuples = set([]) | ||
for material in materials: | ||
multi_index_tuples.update([cls.id_to_tuple(key) | ||
for key in material.keys()]) | ||
|
||
index = pd.MultiIndex.from_tuples( | ||
multi_index_tuples, names=['atomic_number', 'mass_number']) | ||
|
||
|
||
abundances = pd.DataFrame(data=0.0, index=index, columns=xrange(len(materials))) | ||
|
||
for i, material in enumerate(materials): | ||
for key, value in material.items(): | ||
abundances.loc[cls.id_to_tuple(key), i] = value | ||
|
||
return cls(abundances) | ||
|
||
|
||
|
||
|
||
@staticmethod | ||
def id_to_tuple(atomic_id): | ||
return nucname.znum(atomic_id), nucname.anum(atomic_id) | ||
|
||
|
||
def to_materials(self): | ||
""" | ||
Convert DataFrame to a list of materials interpreting the MultiIndex as | ||
atomic_number and mass_number | ||
|
||
Returns | ||
------- | ||
: ~list | ||
list of pyne Materialss | ||
:return: | ||
""" | ||
|
||
comp_dicts = [dict() for i in xrange(len(self.columns))] | ||
for (atomic_number, mass_number), abundances in self.iterrows(): | ||
nuclear_symbol = '{0:s}{1:d}'.format(nucname.name(atomic_number), | ||
mass_number) | ||
for i in xrange(len(self.columns)): | ||
comp_dicts[i][nuclear_symbol] = abundances[i] | ||
return [material.Material(comp_dict) for comp_dict in comp_dicts] | ||
|
||
|
||
|
||
def decay(self, t): | ||
""" | ||
Decay the Model | ||
|
||
Parameters | ||
---------- | ||
|
||
t: ~float or ~astropy.units.Quantity | ||
if float it will be understood as days | ||
|
||
Returns: | ||
: decayed abundances | ||
""" | ||
|
||
materials = self.to_materials() | ||
t_second = u.Quantity(t, u.day).to(u.s).value | ||
decayed_materials = [item.decay(t_second) for item in materials] | ||
for i in range(len(materials)): | ||
materials[i].update(decayed_materials[i]) | ||
df = IsotopeAbundances.from_materials(materials) | ||
df.sort_index(inplace=True) | ||
return df | ||
|
||
def as_atoms(self): | ||
""" | ||
Merge Isotope dataframe according to atomic number | ||
|
||
Returns: | ||
: merged isotope abundances | ||
""" | ||
|
||
return self.groupby('atomic_number').sum() | ||
|
||
def merge(self, other, normalize=True): | ||
""" | ||
Merge Isotope dataframe with abundance passed as parameter | ||
|
||
Parameters | ||
---------- | ||
other: pd.DataFrame | ||
normalize : bool | ||
If true, resultant dataframe will be normalized | ||
|
||
Returns: | ||
: merged abundances | ||
""" | ||
isotope_abundance = self.as_atoms() | ||
isotope_abundance = isotope_abundance.fillna(0.0) | ||
#Merge abundance and isotope dataframe | ||
modified_df = isotope_abundance.add(other, fill_value=0) | ||
|
||
if normalize: | ||
norm_factor = modified_df.sum(axis=0) | ||
modified_df /= norm_factor | ||
|
||
return modified_df |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure what the CMFGEN part has to do with the decay capabilities