-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #801 from tardis-sn/decay
Decay of isotopes branch
- Loading branch information
Showing
26 changed files
with
922 additions
and
94 deletions.
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.