Skip to content

Commit

Permalink
Misc changes in isotope abund. file parser
Browse files Browse the repository at this point in the history
  • Loading branch information
vg3095 committed Jul 13, 2017
1 parent a5f0b29 commit b1799e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
22 changes: 11 additions & 11 deletions tardis/io/model_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def read_abundances_file(abundance_filename, abundance_filetype,

file_parsers = {'simple_ascii': read_simple_ascii_abundances,
'artis': read_simple_ascii_abundances,
'isotopes': read_simple_isotope_abundances}
'tardis_model': read_simple_isotope_abundances}

isotope_abundance = pd.DataFrame()
if abundance_filetype == 'isotopes':
if abundance_filetype == 'tardis_model':
index, abundances, isotope_abundance = read_simple_isotope_abundances(
abundance_filename)
else:
Expand Down Expand Up @@ -267,7 +267,7 @@ def read_simple_ascii_abundances(fname):


def read_simple_isotope_abundances(fname, delimiter=','):
df = pd.read_csv(fname, header=[0, 1], comment='#', delimiter=delimiter)
df = pd.read_csv(fname, comment='#', delimiter=delimiter)
df = df.transpose()

abundance = pd.DataFrame(columns=np.arange(df.shape[1]),
Expand All @@ -281,14 +281,14 @@ def read_simple_isotope_abundances(fname, delimiter=','):
index=isotope_index,
dtype=np.float64)

for element, type_of_element in df.index:
if type_of_element == 'E':
z = element_symbol2atomic_number(element)
abundance.loc[z, :] = df.loc[element, type_of_element].tolist()
elif type_of_element == 'I':
z = nucname.znum(element)
mass_no = nucname.anum(element)
for element_symbol_string in df.index:
if element_symbol_string in nucname.name_zz:
z = nucname.name_zz[element_symbol_string]
abundance.loc[z, :] = df.loc[element_symbol_string].tolist()
else:
z = nucname.znum(element_symbol_string)
mass_no = nucname.anum(element_symbol_string)
isotope_abundance.loc[(
z, mass_no), :] = df.loc[element, type_of_element].tolist()
z, mass_no), :] = df.loc[element_symbol_string].tolist()

return abundance.index, abundance, isotope_abundance
13 changes: 4 additions & 9 deletions tardis/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,7 @@ def convert_abundances_format(fname, delimiter='\s+'):
df = pd.read_csv(fname, delimiter=delimiter, comment='#', header=None)
#Drop shell index column
df.drop(df.columns[0], axis=1, inplace=True)

#Creating Header rows of Element Symbol and Type of Element
header_df = pd.DataFrame([(nucname.name(i), 'E')
for i in range(1, df.shape[1] + 1)]).transpose()
#Align columns index with abundance dataframe
header_df.columns = header_df.columns + 1

# Adding header rows to top and return resultant DataFrame
return pd.concat([header_df, df])
#Assign header row
df.columns = [nucname.name(i)
for i in range(1, df.shape[1] + 1)]
return df

0 comments on commit b1799e7

Please sign in to comment.