From 81b741867c64d7324a3993243a13de5f646a012d Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Thu, 1 Feb 2024 13:13:44 -0500 Subject: [PATCH] applied review comments suggestions --- .../analysis_db/B06_correct_separate_var.py | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/icesat2_tracks/analysis_db/B06_correct_separate_var.py b/src/icesat2_tracks/analysis_db/B06_correct_separate_var.py index ab2420f1..8c2962bc 100644 --- a/src/icesat2_tracks/analysis_db/B06_correct_separate_var.py +++ b/src/icesat2_tracks/analysis_db/B06_correct_separate_var.py @@ -87,7 +87,7 @@ def dict_weighted_mean(Gdict, weight_key): N_photons = np.zeros(GSUM.N_per_stancil.size) counter = 0 - for k, I in Gdict.items(): + for _,I in Gdict.items(): I = I.squeeze() print(len(I.x)) if len(I.x) != 0: @@ -742,28 +742,25 @@ def reconstruct_displacement(Gx_1, Gk_1, T3, k_thresh): # save collected spectral data Gk_v2.to_netcdf(save_path + "/B06_" + ID_name + "_gFT_k_corrected.nc") -Gx + # save real space data Gx.to_netcdf(save_path + "/B06_" + ID_name + "_gFT_x_corrected.nc") -try: - io.save_pandas_table( - B2_v2, "B06_" + ID_name + "_B06_corrected_resid", save_path - ) # all photos but heights adjusted and with distance coordinate -except: - os.remove(save_path + "B06_" + ID_name + "_B06_corrected_resid.h5") - io.save_pandas_table( - B2_v2, "B06_" + ID_name + "_B06_corrected_resid", save_path - ) # all photos but heights adjusted and with distance coordinate -try: - io.save_pandas_table( - B3_v2, "B06_" + ID_name + "_binned_resid", save_path - ) # regridding heights -except: - os.remove(save_path + "B06_" + ID_name + "_binned_resid.h5") - io.save_pandas_table( - B3_v2, "B06_" + ID_name + "_binned_resid", save_path - ) # regridding heights + +def save_table(data, tablename, save_path): + try: + io.save_pandas_table(data, tablename, save_path) + except Exception as e: + tabletoremove = save_path + tablename + ".h5" + print(e, f"Failed to save table. Removing {tabletoremove} and re-trying..") + os.remove(tabletoremove) + io.save_pandas_table(data, tablename, save_path) + +B06_ID_name = "B06_" + ID_name +table_names = [B06_ID_name + suffix for suffix in ["_B06_corrected_resid", "_binned_resid"]] +data = [B2_v2, B3_v2] +for tablename, data in zip(table_names, data): + save_table(data, tablename, save_path) MT.json_save( "B06_success",