Skip to content

Commit

Permalink
account for ragged columns in reclvl files (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes authored Sep 10, 2024
1 parent 5e730e5 commit bc5b05f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fiasco/io/sources/ion_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,22 @@ def preprocessor(self, table, line, index):

class ReclvlParser(CilvlParser):
filetype = 'reclvl'
dtypes = [int, int, 'object', 'object']
headings = ['lower_level', 'upper_level', 'temperature', 'recombination_rate']
descriptions = ['lower level index', 'upper level index', 'temperature', 'recombination rate coefficient']

def postprocessor(self, df):
# NOTE: For some versions of the database, not all of the temperatures and rates in a given file are
# the same length. As such, the dtype of these columns must be set to "object". However, in cases
# where they are all equal, we want to make sure they are preserved as floats.
for cn in df.colnames:
all_equal = np.all(np.array([row.size for row in df[cn]]) == df[cn][0].size)
if df[cn].dtype == np.dtype('O') and all_equal:
df[cn] = df[cn].astype(np.dtype('float64'))

df = super().postprocessor(df)
return df


class RrparamsParser(GenericIonParser):
"""
Expand Down

0 comments on commit bc5b05f

Please sign in to comment.