diff --git a/tardis/io/model_reader.py b/tardis/io/model_reader.py index a137613195f..e0a76804002 100644 --- a/tardis/io/model_reader.py +++ b/tardis/io/model_reader.py @@ -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: @@ -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]), @@ -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 diff --git a/tardis/util.py b/tardis/util.py index b33e4002d92..7d0c18bdce5 100644 --- a/tardis/util.py +++ b/tardis/util.py @@ -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