1. James Morrison
  2. hebtools

Commits

James Morrison  committed d151f9b

Corrected dict creation in wave_stats

Using pd.concat instead of awkward join in awac_stats

  • Participants
  • Parent commits 72b33bd
  • Branches default

Comments (0)

Files changed (2)

File hebtools/awac/awac_stats.py

View file
 
 def arrays_to_df_excel(stats_dict, awac_name, path):
     index_df = pd.DatetimeIndex(stats_dict['start_times'])
-    stat_dfs = []
+    stats_dfs = []
     for column in ['h_max', 'h_avg', 'h_std', 'h_1_3_mean','end_times']:
-        stat_dfs.append(pd.DataFrame(stats_dict[column], index=index_df, 
+        stats_dfs.append(pd.DataFrame(stats_dict[column], index=index_df, 
                                      columns=[column]))
-    set_df = stat_dfs[0].join(stat_dfs[1:])
+                                     
+    set_df = pd.concat(stats_dfs, axis=1)
     file_name = 'wave_h_' + str(stats_dict['set_size']) + '_set_' + awac_name
     set_df.save(file_name)
     set_df.to_excel(file_name + '.xlsx')

File hebtools/common/wave_stats.py

View file
         between them for >4*std or signal_error true and if so remove the
         wave height"""
         columns = ['bad_wave', 'max_std_factor', 'heave_file_std']
-        stats_dict = {}
+        stats_dict = dict([(column,[]) for column in columns])
         stats_df = []
         for index, wave_height in enumerate(wave_height_df.iterrows()):
             if index+1 < len(wave_height_df):
         extrema = self.raw_disp
         extrema = extrema.ix[np.invert(np.isnan(extrema['extrema']))]
         differences = np.ediff1d(np.array(extrema[column_name]))
-        wave_height_timestamps = extrema.index[differences<0]
-        wave_heights = np.absolute(differences[differences<0])
+        sub_zero_diff = differences<0
+        wave_height_timestamps = extrema.index[sub_zero_diff]
+        wave_heights = np.absolute(differences[sub_zero_diff])
         wave_height_df = pd.DataFrame(wave_heights, columns=[series_name],
                                       index = wave_height_timestamps)
         logging.info(wave_height_df)
         if error_check:
-            file_names = extrema.file_name[differences<0]
+            file_names = extrema.file_name[sub_zero_diff]
             file_name_df = pd.DataFrame(file_names, columns=['file_name'], 
                                     index = wave_height_timestamps)
             wave_height_df = wave_height_df.join(file_name_df)