def test_compare_ascii_bin(self): res_ascii = windIO.LoadResults(self.respath, self.fascii) res_bin = windIO.LoadResults(self.respath, self.fbin) for k in range(res_ascii.sig.shape[1]): np.testing.assert_allclose(res_ascii.sig[:, k], res_bin.sig[:, k], rtol=1e-02, atol=0.001)
def test_unified_chan_names_extensive(self): # --------------------------------------------------------------------- res = windIO.LoadResults(self.respath, self.f1_chant, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 432)) self.assertEqual(res.ch_df.unique_ch_name.values[0], 'Time') df = res.ch_df self.assertEqual(2, len(df[df['bearing_name'] == 'shaft_rot'])) self.assertEqual(18, len(df[df['sensortype'] == 'State pos'])) self.assertEqual(11, len(df[df['blade_nr'] == 1])) exp = [ [38, 'global-blade2-elem-019-zrel-1.00-State pos-z', 'm'], [200, 'blade2-blade2-node-017-momentvec-z', 'kNm'], [296, 'blade1-blade1-node-008-forcevec-z', 'kN'], [415, 'Cl-1-54.82', 'deg'], [421, 'qwerty-is-azerty', 'is'], [422, 'wind_wake-wake_pos_x_1', 'm'], [423, 'wind_wake-wake_pos_y_2', 'm'], [424, 'wind_wake-wake_pos_z_5', 'm'], [425, 'statevec_new-blade1-c2def-blade1-absolute-014.00-Dx', 'm'], [429, 'statevec_new-blade1-c2def-blade1-elastic-014.00-Ry', 'deg'], ] for k in exp: self.assertEqual(df.loc[k[0], 'unique_ch_name'], k[1]) self.assertEqual(df.loc[k[0], 'units'], k[2]) self.assertEqual(res.ch_dict[k[1]]['chi'], k[0]) self.assertEqual(res.ch_dict[k[1]]['units'], k[2]) # also check we have the tag from a very long description because # we truncate after 150 characters self.assertEqual(df.loc[426, 'sensortag'], 'this is a tag') # --------------------------------------------------------------------- res = windIO.LoadResults(self.respath, self.f2_chant, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 217)) df = res.ch_df self.assertEqual(4, len(df[df['sensortype'] == 'wsp-global'])) self.assertEqual(2, len(df[df['sensortype'] == 'harmonic'])) self.assertEqual(2, len(df[df['blade_nr'] == 3])) # --------------------------------------------------------------------- res = windIO.LoadResults(self.respath, self.f3_chant, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 294)) df1 = res.ch_df self.assertEqual(8, len(df1[df1['sensortype'] == 'CT'])) self.assertEqual(8, len(df1[df1['sensortype'] == 'CQ'])) self.assertEqual(8, len(df1[df1['sensortype'] == 'a_grid'])) self.assertEqual(84, len(df1[df1['blade_nr'] == 1]))
def test_unified_chan_names(self): res = windIO.LoadResults(self.respath, self.fascii, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 28)) self.assertEqual(res.ch_df.unique_ch_name.values[0], 'Time') self.assertEqual(res.ch_df.unique_ch_name.values[27], 'windspeed-global-Vy--2.50-1.00--52.50')
def test_unified_chan_names_extensive2(self): res = windIO.LoadResults(self.respath, self.f3_chant, readdata=False) df1 = res.ch_df fname = os.path.join(self.respath, self.f3_chant.replace('.sel', '.ch_df.csv')) # when changing the tests, update the reference, check, and commit # but keep the same column ordering to not make the diffs to big # cols = ['azimuth', 'bearing_name', 'blade_nr', 'bodyname', # 'component', 'coord', 'direction', 'dll', 'flap_nr', 'io', # 'io_nr', 'output_type', 'pos', 'radius', 'sensortag', # 'sensortype', 'unique_ch_name', 'units', ] # df1[cols].to_csv(fname) # df1.to_excel(fname.replace('.csv', '.xlsx')) # FIXME: read_csv for older pandas versions fails on reading the # mixed str/tuple column. Ignore the pos column for now colref = [ 'azimuth', 'bearing_name', 'blade_nr', 'bodyname', 'component', 'coord', 'direction', 'dll', 'flap_nr', 'io', 'io_nr', 'output_type', 'radius', 'sensortag', 'sensortype', 'unique_ch_name', 'units' ] # 'pos', # keep_default_na: leave empyt strings as empty strings and not nan's # you can't have nice things: usecols in combination with index_col # doesn't work df2 = pd.read_csv(fname, usecols=['chi'] + colref, keep_default_na=False) df2.index = df2['chi'] df2.drop(labels='chi', inplace=True, axis=1) # for the comparison we need to have the columns with empty/number # mixed data types in a consistent data type for col in [ 'azimuth', 'radius', 'blade_nr', 'io_nr', 'flap_nr', 'dll' ]: df1.loc[df1[col] == '', col] = np.nan df1[col] = df1[col].astype(np.float32) df2.loc[df2[col] == '', col] = np.nan df2[col] = df2[col].astype(np.float32) # print(df1.pos[14], df2.pos[14]) # the pos columns contains also tuples, read from csv doesn't get that # df1['pos'] = df1['pos'].astype(np.str) # df1['pos'] = df1['pos'].str.replace("'", "") # print(df1.pos[14], df2.pos[14]) # sort columns in the same way so we can assert the df are equal # df1 = df1[colref].copy() # df2 = df2[colref].copy() # FIXME: when pandas is more recent we can use assert_frame_equal # pd.testing.assert_frame_equal(df1, df2) # ...but there is no testing.assert_frame_equal in pandas 0.14 for col in colref: np.testing.assert_array_equal(df1[col].values, df2[col].values)
def loadresfile(self, resfile): res = windIO.LoadResults(self.respath, resfile) self.assertTrue(hasattr(res, 'sig')) self.assertEqual(res.Freq, 40.0) self.assertEqual(res.N, 800) self.assertEqual(res.Nch, 28) self.assertEqual(res.Time, 20.0) self.assertEqual(res.sig.shape, (800, 28)) return res
def calc(fpath, no_bins=46, m=[3, 4, 6, 8, 10, 12], neq=None, i0=0, i1=None, ftype=False, fsave=False): """ Should we load m, statchans, delchans from another file? This function will be called from a PBS script. """ if fpath[-4:] == '.sel' or fpath[-4:] == '.dat': fpath = fpath[-4:] fdir = os.path.dirname(fpath) fname = os.path.basename(fpath) res = windIO.LoadResults(fdir, fname, debug=False, usecols=None, readdata=True) statsdel = res.statsdel_df(i0=i0, i1=i1, statchans='all', neq=neq, no_bins=no_bins, m=m, delchans='all') if fsave: if fsave[-4:] == '.csv': statsdel.to_csv(fsave) elif fsave[-3:] == '.h5': statsdel.to_hdf(fsave, 'table', complib='zlib', complevel=9) elif ftype == '.csv': statsdel.to_csv(fpath + ftype) elif ftype == '.h5': statsdel.to_hdf(fpath + ftype, 'table', complib='zlib', complevel=9) return res, statsdel
def test_unified_chan_names_extensive(self): # --------------------------------------------------------------------- res = windIO.LoadResults(self.respath, self.f1_chant, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 425)) self.assertEqual(res.ch_df.unique_ch_name.values[0], 'Time') df = res.ch_df self.assertEqual(2, len(df[df['bearing_name'] == 'shaft_rot'])) self.assertEqual(18, len(df[df['sensortype'] == 'State pos'])) self.assertEqual(11, len(df[df['blade_nr'] == 1])) exp = [ [38, 'global-blade2-elem-019-zrel-1.00-State pos-z', 'm'], [200, 'blade2-blade2-node-017-momentvec-z', 'kNm'], [296, 'blade1-blade1-node-008-forcevec-z', 'kN'], [415, 'Cl-1-54.82', 'deg'], [421, 'qwerty-is-azerty', 'is'], [422, 'wind_wake-wake_pos_x_1', 'm'], [423, 'wind_wake-wake_pos_y_2', 'm'], [424, 'wind_wake-wake_pos_z_5', 'm'], ] for k in exp: self.assertEqual(df.loc[k[0], 'unique_ch_name'], k[1]) self.assertEqual(df.loc[k[0], 'units'], k[2]) self.assertEqual(res.ch_dict[k[1]]['chi'], k[0]) self.assertEqual(res.ch_dict[k[1]]['units'], k[2]) # --------------------------------------------------------------------- res = windIO.LoadResults(self.respath, self.f2_chant, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 217)) df = res.ch_df self.assertEqual(4, len(df[df['sensortype'] == 'wsp-global'])) self.assertEqual(2, len(df[df['sensortype'] == 'harmonic'])) self.assertEqual(2, len(df[df['blade_nr'] == 3])) # --------------------------------------------------------------------- res = windIO.LoadResults(self.respath, self.f3_chant, readdata=False) self.assertFalse(hasattr(res, 'sig')) np.testing.assert_array_equal(res.ch_df.index.values, np.arange(0, 294)) df1 = res.ch_df self.assertEqual(8, len(df1[df1['sensortype'] == 'CT'])) self.assertEqual(8, len(df1[df1['sensortype'] == 'CQ'])) self.assertEqual(8, len(df1[df1['sensortype'] == 'a_grid'])) self.assertEqual(84, len(df1[df1['blade_nr'] == 1])) fname = os.path.join(self.respath, self.f3_chant.replace('.sel', '.ch_df.csv')) # FIXME: read_csv for older pandas versions fails on reading the # mixed str/tuple column. Ignore the pos column for now colref = [ 'azimuth', 'bearing_name', 'blade_nr', 'bodyname', 'component', 'coord', 'direction', 'dll', 'flap_nr', 'io', 'io_nr', 'output_type', 'radius', 'sensortag', 'sensortype', 'unique_ch_name', 'units' ] # 'pos', # keep_default_na: leave empyt strings as empty strings and not nan's # you can't have nice things: usecols in combination with index_col # doesn't work df2 = pd.read_csv(fname, usecols=['chi'] + colref, keep_default_na=False) df2.index = df2['chi'] df2.drop(labels='chi', inplace=True, axis=1) # for the comparison we need to have the columns with empty/number # mixed data types in a consistent data type for col in [ 'azimuth', 'radius', 'blade_nr', 'io_nr', 'flap_nr', 'dll' ]: df1.loc[df1[col] == '', col] = np.nan df1[col] = df1[col].astype(np.float32) df2.loc[df2[col] == '', col] = np.nan df2[col] = df2[col].astype(np.float32) # print(df1.pos[14], df2.pos[14]) # the pos columns contains also tuples, read from csv doesn't get that # df1['pos'] = df1['pos'].astype(np.str) # df1['pos'] = df1['pos'].str.replace("'", "") # print(df1.pos[14], df2.pos[14]) # sort columns in the same way so we can assert the df are equal # df1 = df1[colref].copy() # df2 = df2[colref].copy() # FIXME: when pandas is more recent we can use assert_frame_equal # pd.testing.assert_frame_equal(df1, df2) # ...but there is no testing.assert_frame_equal in pandas 0.14 for col in colref: np.testing.assert_array_equal(df1[col].values, df2[col].values)
def test_df_stats(self): """ """ res = windIO.LoadResults(self.respath, self.fascii) df_stats = res.statsdel_df()
from wetb.prepost import hawcstab2 if __name__ == '__main__': # ============================================================================= # READ HAWC2 RESULT FILE # ============================================================================= # METHOD A fname = '../wetb/hawc2/tests/test_files/hawc2io/Hawc2ascii.sel' res = Hawc2io.ReadHawc2(fname) sig = res.ReadAll() # METHOD B path, file = os.path.dirname(fname), os.path.basename(fname) res = windIO.LoadResults(path, file) sig = res.sig sel = res.ch_details # result in dataframe with unique channel names (instead of indices) sig_df = res.sig2df() ch_df = res.ch_df # ============================================================================= # READ HAWCStab2 files # ============================================================================= res = hawcstab2.results() fname = '../wetb/prepost/tests/data/campbell_diagram.cmb' df_cmb = res.load_cmb_df(fname)