0
0
Просмотр исходного кода

Improve table formatting

* Fix missing symbol in function
compton 11 месяцев назад
Родитель
Сommit
653ae0e912
2 измененных файлов с 10 добавлено и 5 удалено
  1. 7 2
      src/avg/compton_combiner.py
  2. 3 3
      src/avg/compton_filter.py

+ 7 - 2
src/avg/compton_combiner.py

@@ -540,7 +540,7 @@ def final_table_to_clbrdb(df: pd.DataFrame, clbrdb: CalibrdbHandler, runs_df: pd
     
 def save_csv(df: pd.DataFrame, filepath: str, update_current: bool = True):
     """Saves csv file. Updates current file in filepath if exists"""
-    
+
     logging.info(f'Saving csv file: len(df)={len(df)}, filepath={filepath}, update_current={update_current}')
     if (os.path.isfile(filepath) and update_current):
         df_current = pd.read_csv(filepath)
@@ -548,7 +548,12 @@ def save_csv(df: pd.DataFrame, filepath: str, update_current: bool = True):
         df_current = pd.concat([df_current, df], ignore_index=True)
         df_current = df_current.drop_duplicates(subset=['energy_point', 'first_run'], keep='last')
         df = df_current
-    
+
+    # Format columns
+    df['mean_energy'] = df['mean_energy'].map("{:.3f}".format)
+    for col in ['mean_energy_stat_err', 'mean_energy_sys_err', 'mean_spread', 'mean_spread_stat_err']:
+        df[col] = df[col].map("{:.4f}".format)
+
     df.to_csv(filepath, index=False, float_format='%g')
     return
 

+ 3 - 3
src/avg/compton_filter.py

@@ -409,9 +409,9 @@ def processing_from_file(path):
         row = row.strip().split()
 
         timestamp_mean, dt = int(row[0]), int(row[1])
-        timetamp_to_date = lambda timestamp: (datetime.utcfromtimestamp(timestamp) + current_timezone).astimezone(timezone(current_timezone))
-        t_start = timetamp_to_date(timestamp_mean - dt)
-        t_stop = timetamp_to_date(timestamp_mean + dt)
+        timestamp_to_date = lambda timestamp: (datetime.utcfromtimestamp(timestamp) + current_timezone).astimezone(timezone(current_timezone))
+        t_start = timestamp_to_date(timestamp_mean - dt)
+        t_stop = timestamp_to_date(timestamp_mean + dt)
         
         t_write = t_stop