Skip to content

Commit

Permalink
Gap filling step added
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyHow committed Aug 12, 2024
1 parent 37527b1 commit a23df02
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/pypromice/process/L1toL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def toL2(


ds = clip_values(ds, vars_df)
ds = fill_gaps(ds)
return ds


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a23df02

Please sign in to comment.