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

Decay of isotopes branch #801

Merged
merged 95 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
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 Sep 7, 2015
aa49e27
Add unit test for decay method
vg3095 Jul 3, 2017
b609640
Sort dataframe index in IsotopeAbundances class
vg3095 Jul 4, 2017
e0e3c04
Merge pull request #756 from vg3095/radioactive_decay
wkerzendorf Jul 4, 2017
96a42c5
Add option to read uniform isotope_abundance in Model
vg3095 Jul 7, 2017
aaa218d
Normalize isotope abundances
vg3095 Jul 7, 2017
0297ba7
Seperate type of abundances under Model from_config
vg3095 Jul 7, 2017
4886a7d
Use pyne to parse isotopes
vg3095 Jul 7, 2017
721bc69
Fix import and a typo
vg3095 Jul 7, 2017
9992da2
Move isotope_abundance up in initialization list
vg3095 Jul 10, 2017
495b874
Move uniform abundance code block to separate func
vg3095 Jul 11, 2017
2171cc3
Use pyne to parse uniform normal abundances
vg3095 Jul 13, 2017
7ca593a
Merge pull request #762 from vg3095/isotope_config
wkerzendorf Jul 14, 2017
518ae3b
Added a isotope abund. file parser
vg3095 Jul 12, 2017
a0db95c
Assign isotope abund. in model
vg3095 Jul 12, 2017
bcd7861
Func. to convert old abund. file to new format
vg3095 Jul 12, 2017
5ec16dc
Fix typo in comments
vg3095 Jul 12, 2017
30d5cfd
Misc changes in isotope abund. file parser
vg3095 Jul 13, 2017
23b4001
Add files related to new isotope config options
vg3095 Jul 17, 2017
c565565
Add tests for isotope config options
vg3095 Jul 17, 2017
6867223
Update docs for uniform abundance config option
vg3095 Jul 17, 2017
f36e1b5
Include csv in setup_package.py under io
vg3095 Jul 17, 2017
275ad56
Add basic info for new csv format for abund.
vg3095 Jul 17, 2017
58d7a20
Rearrange columns in csv file
vg3095 Jul 17, 2017
0a45080
Add isotope csv config example and files
vg3095 Jul 17, 2017
47bfeb2
Some fixes
vg3095 Jul 17, 2017
c25e266
Add example in docs for converting abund. format
vg3095 Jul 17, 2017
34a2b0a
Use space delimeter
vg3095 Jul 17, 2017
fe0283d
Update csv file to make sum of abund. one
vg3095 Jul 17, 2017
a90a1b1
Add note in stratified abundance docs
vg3095 Jul 17, 2017
28b52b0
Rearrange Ni isotopes in docs
vg3095 Jul 17, 2017
87fe983
Merge pull request #764 from vg3095/isotope_file_config
wkerzendorf Jul 19, 2017
9be16b1
Merge pull request #767 from vg3095/docs_isotope
wkerzendorf Jul 19, 2017
7c517d1
Add a decay method under Model class
vg3095 Jul 4, 2017
018922e
Update Model decay method
vg3095 Jul 4, 2017
f949d79
Decay model if isotope_abundance parameter is present
vg3095 Jul 4, 2017
c399dae
Fix for missing self positional argument
vg3095 Jul 4, 2017
f18d012
Added test to check merge operation for abundance
vg3095 Jul 4, 2017
6d073b5
Update merge operation for abundance
vg3095 Jul 4, 2017
1ccaced
Move as_atomic_numbers method to IsotopeAbundances class
vg3095 Jul 4, 2017
ce10dbe
Added test for as_atomic_numbers method
vg3095 Jul 4, 2017
b7e528a
Move up isotope_abundance in initialization and use pd.add() while me…
vg3095 Jul 5, 2017
9e122be
Move decay of isotope_abundance under Model abundance property
vg3095 Jul 6, 2017
174d024
Use pd.groupby to merge isotopes
vg3095 Jul 6, 2017
3ad7ebd
Change tests for decay
vg3095 Jul 6, 2017
67e9c37
Fix typo in comment
vg3095 Jul 6, 2017
007df67
Change name of func. in IsotopeAbundances class
vg3095 Jul 6, 2017
a5ed7a2
PEP8 fixes
vg3095 Jul 6, 2017
d9a5783
Use changed func. name in decay methods and its test
vg3095 Jul 6, 2017
e8c2745
Add cmfgen2tardis script
vg3095 Jul 20, 2017
2e02633
Fix for scripts/__int__,py
vg3095 Jul 20, 2017
190000f
Use argparse for cmfgen2tardis script
vg3095 Jul 20, 2017
c0f17b5
Move cmfgen2tardis script inside tardis package
vg3095 Jul 21, 2017
53c2283
Make isotope_abundance instance of IsotopeAbundances in model.from_co…
vg3095 Jul 24, 2017
a0f915f
Added doc from cmfgen2tardis script
vg3095 Jul 24, 2017
061183a
Add a cmfgen density file parser
vg3095 Jul 25, 2017
8a0ad25
Add tardis_model in density schema
vg3095 Jul 25, 2017
26399a0
Overwrite electron_densities if already present
vg3095 Jul 25, 2017
337c16a
Make electron_densities default None
vg3095 Jul 25, 2017
6bf3476
Use _electron_densities instead of electron_densities
vg3095 Jul 25, 2017
1690158
Change tardis_model parser structure
vg3095 Jul 26, 2017
ac24617
Overwrite electron_densities in IonNumberDensityHeNLTe
vg3095 Jul 26, 2017
85b037a
Correction while parsing temp.
vg3095 Jul 26, 2017
3dc0e68
Reversing attr. in read_cmfgen_density func.
vg3095 Jul 27, 2017
0016858
Added tests for cmfgen density parser
vg3095 Jul 27, 2017
1cdd63d
Added tests for new tardis_model density config
vg3095 Jul 27, 2017
ad7e379
Changes to cmfgen script
vg3095 Jul 28, 2017
f7a5c6f
Mention about DAT files, in scripts doc
vg3095 Jul 28, 2017
ae19f84
Some changes in tardis_model density parser
vg3095 Jul 28, 2017
42b4ae8
Add a comment about reversing columns in script.
vg3095 Jul 28, 2017
56739b2
Remove index col. and change col. names to lowercase
vg3095 Jul 31, 2017
32629f3
Add docstring for read_cmfgen_density method
vg3095 Jul 31, 2017
ba5eb8e
Change tardis_model abund. parser
vg3095 Jul 31, 2017
b5159ee
Common CSV file for tardis_model related parser
vg3095 Jul 31, 2017
a31ad72
Delete old tardis_model config and abund,density files
vg3095 Jul 31, 2017
6402010
Save cmfgen quantities in one CSV file.
vg3095 Jul 31, 2017
edc4ffa
Merge pull request #757 from vg3095/model_decay
wkerzendorf Aug 1, 2017
af283e5
Add quantities row
vg3095 Aug 1, 2017
503e7d6
Read quantities from CSV file
vg3095 Aug 1, 2017
bc8e36b
Rearrange columns in dataframe
vg3095 Aug 1, 2017
b2566bc
Update CSV file for tests
vg3095 Aug 1, 2017
ad7c784
Update docstring for cmfgen parser
vg3095 Aug 1, 2017
4c6119a
Replace gm/cm^3 to g/cm^3
vg3095 Aug 1, 2017
5313ddd
Change gm/cm^3 to g/cm^3
vg3095 Aug 1, 2017
f6d00b7
Merge pull request #771 from vg3095/tardis_script
wkerzendorf Aug 2, 2017
287e25e
Merge pull request #772 from vg3095/cmf_density
wkerzendorf Aug 7, 2017
efcc374
Merge branch 'master' into decay
wkerzendorf Nov 10, 2017
ac8e671
Fix when electron_densities is read from a file
vg3095 Nov 10, 2017
37c4ebf
Merge pull request #802 from vg3095/plasma_ion_fix
wkerzendorf Nov 10, 2017
5065193
add new scipy version due to failing osx build
wkerzendorf Nov 13, 2017
41c6222
Fix reference dictionary problem
pfreddy Nov 16, 2017
636b18b
Fix 'nan' problem
pfreddy Nov 17, 2017
980716e
Change 'nan' to 0.0 in isotope abundances
pfreddy Nov 17, 2017
080c30c
Fix missing key problem in case of zero isotope abundances
pfreddy Nov 17, 2017
1f516f0
Merge pull request #806 from pfreddy/fix_decay
wkerzendorf Nov 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions docs/examples/abundancecust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Using a custom stratified composition
*************************************

Overview
========
ASCII Format
=============

To use a stratified ejecta composition in TARDIS, the elemental abundances may
be specified on a per-cell basis via an external ascii file (similar to setting
Expand Down Expand Up @@ -46,12 +46,76 @@ The example file shown here has three simple layers:
including details of how to develop your own dataset to suit your
needs, please contact us.

TARDIS input file
=================
TARDIS ascii input file
=======================

If you create a correctly formatted abundance profile file (called "abund.dat"
in this example), you can use it in TARDIS by putting the following lines in
the model section of the yaml file:

.. literalinclude:: tardis_configv1_abundance_cust_example.yml
:language: yaml


CSV Format
==========

In this format, both elemental and isotopic abundances may
be specified on a per-cell basis via an external csv file. A csv file that could
work on a mesh with ten cells should be formatted like this:

.. csv-table:: Example
:file: tardis_model_abund.csv
:delim: space
:header-rows: 1

In this file:

- Header row contains element and isotopes symbol
- the remaining entries in each row give the set of elemental and isotopic abundances.

The abundances are specified as mass fractions (i.e. the sum of columns
in each row should be 1.0). The mass fractions specified will be adopted directly in
the TARDIS calculations.

The example file shown here has three simple layers:

- an innermost region that is composed of Si and two Nickel Isotopes Ni56 and Ni58

- a middle region that is composed of O and Mg

- an outer region that is composed of C and O.

.. note::

Suppose you specify Elemental and Isotopic abundances for the same element. For ex-
:code:`Ni` and :code:`Ni56`.
Here, Ni will refer to the stable Nickel, i.e. (Z=26, A=58).

.. warning::

The example given here is to show the format only. It is not a
realistic model. In any real calculation better resolution
(i.e. more grid points) should be used.

TARDIS csv input file
=====================

If you create a correctly formatted abundance profile file (called "tardis_model_abund.csv"
in this example), you can use it in TARDIS by putting the following lines in
the model section of the yaml file:

.. literalinclude:: tardis_configv1_isotope_abundance_cust_example.yml
:language: yaml

Convert ascii abundance file format to csv format
=================================================

If you want to convert an ASCII abundance file(say "abund.dat") to CSV format, you can use
:code:`convert_abundances_format` function for it. Here is an example to demonstrate this:

.. code:: python

from tardis.util import convert_abundances_format
df = convert_abundances_format('abund.dat')
df.to_csv('converted_abund.csv', index=False, sep=' ')
18 changes: 15 additions & 3 deletions docs/examples/abundanceuni.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ Overview
The simplest possibility for specifying an ejecta composition is to use a
uniform abundance pattern in all cells specified in the density profile setup
step. These constant abundances can be supplied directly in the input (yaml)
file. Elemental abundances are set in the "abundances" subsection of the "model"
file. Elemental and Isotopic abundances are set in the "abundances" subsection of the "model"
section, following the "type: uniform" specifier (see example input
file below). They are specified as mass fractions. E.g.

.. code-block:: none

Si: 0.6
S: 0.4
S: 0.2
Ni56: 0.2

will set the mass fraction of silicon (Z=14) to 0.6 and sulphur (Z=16) to 0.4.
will set the mass fraction of silicon (Z=14) to 0.6, sulphur (Z=16) to 0.2 and Nickel(Z=26, A=56) to 0.2.

.. note::

Suppose you specify Elemental and Isotopic abundance for the same element. For ex-

.. code-block:: none

Ni: 0.8
Ni56: 0.2

Here, Ni will refer to the stable Nickel, i.e. (Z=26, A=58).

.. note::

Expand Down
4 changes: 3 additions & 1 deletion docs/examples/tardis_configv1_abundance_uniform_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
11 changes: 11 additions & 0 deletions docs/examples/tardis_model_abund.csv
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
19 changes: 19 additions & 0 deletions docs/scripts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
***************
Running scripts
***************

Convert CMFGEN files to TARDIS file format
==========================================
Copy link
Contributor

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


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/
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
entry_points[hook_ep] = ['%s = %s' % (hook_name, hook_func)]

entry_points['console_scripts'] = [
'tardis_test_runner = tardis.tests.integration_tests.runner:run_tests'
'tardis_test_runner = tardis.tests.integration_tests.runner:run_tests',
'cmfgen2tardis = tardis.scripts.cmfgen2tardis:main'
]

#from Cython.Build import cythonize
Expand Down
123 changes: 123 additions & 0 deletions tardis/io/decay.py
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
Loading