Skip to content

Commit

Permalink
Merge pull request #806 from pfreddy/fix_decay
Browse files Browse the repository at this point in the history
Fix reference dictionary problem
  • Loading branch information
wkerzendorf committed Nov 20, 2017
2 parents 5065193 + 080c30c commit 1f516f0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tardis/io/decay.py
Expand Up @@ -9,7 +9,7 @@ def _constructor(self):
return IsotopeAbundances

def _update_material(self):
self.comp_dicts = [{}] * len(self.columns)
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)
Expand All @@ -27,7 +27,7 @@ def from_materials(cls, materials):
multi_index_tuples, names=['atomic_number', 'mass_number'])


abundances = pd.DataFrame(index=index, columns=xrange(len(materials)))
abundances = pd.DataFrame(data=0.0, index=index, columns=xrange(len(materials)))

for i, material in enumerate(materials):
for key, value in material.items():
Expand Down Expand Up @@ -55,7 +55,7 @@ def to_materials(self):
:return:
"""

comp_dicts = [{}] * len(self.columns)
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)
Expand All @@ -81,10 +81,10 @@ def decay(self, t):

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]

df = IsotopeAbundances.from_materials(decayed_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

Expand Down Expand Up @@ -112,6 +112,7 @@ def merge(self, other, normalize=True):
: 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)

Expand Down

0 comments on commit 1f516f0

Please sign in to comment.