From a23df029d3d7b2c9ac9f5d63a8c63e04c3eb015b Mon Sep 17 00:00:00 2001 From: PennyHow Date: Mon, 12 Aug 2024 12:08:38 -0100 Subject: [PATCH] Gap filling step added --- src/pypromice/process/L1toL2.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/pypromice/process/L1toL2.py b/src/pypromice/process/L1toL2.py index c8b32bbc..c1bf3969 100644 --- a/src/pypromice/process/L1toL2.py +++ b/src/pypromice/process/L1toL2.py @@ -217,6 +217,7 @@ def toL2( ds = clip_values(ds, vars_df) + ds = fill_gaps(ds) return ds @@ -770,6 +771,35 @@ def calcCorrectionFactor(Declination_rad, phi_sensor_rad, theta_sensor_rad, return CorFac_all +def fill_gaps(ds): + '''Fill data gaps with nan values + + Parameters + ---------- + ds : xarray.Dataset + Data set to gap fill + + Returns + ------- + ds_filled : xarray.Dataset + Gap-filled dataset + ''' + # Determine time range of dataset + min_date = ds.to_dataframe().index.min() + max_date = ds.to_dataframe().index.max() + + # Determine common time interval + time_diffs = np.diff(ds['time'].values) + common_diff = pd.Timedelta(pd.Series(time_diffs).mode()[0]) + + # Determine gap filled index + full_time_range = pd.date_range(start=min_date, + end=max_date, + freq=common_diff) + + # Apply gap-fille index to dataset + ds_filled = ds.reindex({'time': full_time_range}, fill_value=np.nan) + return ds_filled def _checkSunPos(ds, OKalbedos, sundown, sunonlowerdome, TOA_crit_nopass): '''Check sun position