Skip to content
Snippets Groups Projects
Commit 8a5c9d5b authored by David Verelst's avatar David Verelst
Browse files

prepost.hawcstab2: force dtype when testing reading methods

parent ea62d741
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ class dummy(object): ...@@ -31,7 +31,7 @@ class dummy(object):
regex_units = re.compile('(\\[.*?\\])') regex_units = re.compile('(\\[.*?\\])')
def ReadFileHAWCStab2Header(fname): def ReadFileHAWCStab2Header(fname, dtype=None):
""" """
Read a file with a weird HAWCStab2 header that starts with a #, and Read a file with a weird HAWCStab2 header that starts with a #, and
includes the column number and units between square brackets. includes the column number and units between square brackets.
...@@ -79,7 +79,7 @@ def ReadFileHAWCStab2Header(fname): ...@@ -79,7 +79,7 @@ def ReadFileHAWCStab2Header(fname):
# and another with frozen wake assumption # and another with frozen wake assumption
columns = get_col_names(line_header, colwidths) columns = get_col_names(line_header, colwidths)
df = pd.read_fwf(fname, widths=colwidths, comment='#', header=None, df = pd.read_fwf(fname, widths=colwidths, comment='#', header=None,
names=columns) names=columns, dtype=dtype)
units = regex_units.findall(''.join(columns)) units = regex_units.findall(''.join(columns))
return df, units return df, units
...@@ -155,8 +155,8 @@ class results(object): ...@@ -155,8 +155,8 @@ class results(object):
return res return res
def load_pwr_df(self, fname): def load_pwr_df(self, fname, dtype=None):
return ReadFileHAWCStab2Header(fname) return ReadFileHAWCStab2Header(fname, dtype=dtype)
def load_cmb(self, fname): def load_cmb(self, fname):
# aero-(servo)-elastic results for HS2>=2.14 have real_eig as 3th set # aero-(servo)-elastic results for HS2>=2.14 have real_eig as 3th set
......
...@@ -118,10 +118,10 @@ class Tests(unittest.TestCase): ...@@ -118,10 +118,10 @@ class Tests(unittest.TestCase):
for fname in fnames: for fname in fnames:
fname = pjoin(pdirname(__file__), 'data', fname) fname = pjoin(pdirname(__file__), 'data', fname)
res = results() res = results()
df_data, units = res.load_pwr_df(fname) df_data, units = res.load_pwr_df(fname, dtype=np.float32)
data = np.loadtxt(fname) data = np.loadtxt(fname, dtype=np.float32)
self.assertEqual(data.shape, df_data.shape) self.assertEqual(data.shape, df_data.shape)
np.testing.assert_almost_equal(data, df_data.values, decimal=2) np.testing.assert_almost_equal(data, df_data.values, decimal=6)
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment