From 6b003b400539a4940c26a6d5485aff648c686296 Mon Sep 17 00:00:00 2001 From: BaptisteVandecrux Date: Mon, 8 Jul 2024 08:59:36 +0200 Subject: [PATCH] better handle of empty config and changing length of string --- src/pypromice/process/L2toL3.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pypromice/process/L2toL3.py b/src/pypromice/process/L2toL3.py index 874f0924..c828c70d 100755 --- a/src/pypromice/process/L2toL3.py +++ b/src/pypromice/process/L2toL3.py @@ -609,9 +609,13 @@ def thermistorDepth(df_in, site, station_config): logger.info('Calculating thermistor depth') # Convert maintenance_info to DataFrame for easier manipulation - maintenance_string = pd.DataFrame(station_config.get("string_maintenance",[])) + maintenance_string = pd.DataFrame( + station_config.get("string_maintenance",[]), + columns = ['date', 'installation_depths'] + ) maintenance_string["date"] = pd.to_datetime(maintenance_string["date"]) maintenance_string = maintenance_string.sort_values(by='date', ascending=True) + temp_cols_name = ['t_i_'+str(i) for i in range(12) if 't_i_'+str(i) in df_in.columns] num_therm = len(temp_cols_name) depth_cols_name = ['d_t_i_'+str(i) for i in range(1,num_therm+1)] @@ -647,7 +651,8 @@ def thermistorDepth(df_in, site, station_config): new_depth = maintenance_string.loc[ maintenance_string.date == date ].installation_depths.values[0] - for i, col in enumerate(depth_cols_name): + + for i, col in enumerate(depth_cols_name[:len(new_depth)]): tmp = df_in[col].copy() tmp.loc[date:] = ( new_depth[i]