diff --git a/src/pypromice/process/resample.py b/src/pypromice/process/resample.py index 7c7e2ed7..698a5fab 100644 --- a/src/pypromice/process/resample.py +++ b/src/pypromice/process/resample.py @@ -8,6 +8,7 @@ import logging import numpy as np import xarray as xr +from pypromice.process.L1toL2 import calcDirWindSpeeds logger = logging.getLogger(__name__) def resample_dataset(ds_h, t): @@ -35,12 +36,15 @@ def resample_dataset(ds_h, t): # recalculating wind direction from averaged directional wind speeds for var in ['wdir_u','wdir_l']: + boom = var.split('_')[1] if var in df_d.columns: - if ('wspd_x_'+var.split('_')[1] in df_d.columns) & ('wspd_y_'+var.split('_')[1] in df_d.columns): - df_d[var] = _calcWindDir(df_d['wspd_x_'+var.split('_')[1]], - df_d['wspd_y_'+var.split('_')[1]]) + if ('wspd_x_'+boom in df_d.columns) & ('wspd_y_'+boom in df_d.columns): + df_d[var] = _calcWindDir(df_d['wspd_x_'+boom], df_d['wspd_y_'+boom]) else: - logger.info(var+' in dataframe but not wspd_x_'+var.split('_')[1]+' nor wspd_y_'+var.split('_')[1]) + logger.info(var+' in dataframe but not wspd_x_'+boom+' nor wspd_y_'+boom+', recalculating them') + ds_h['wspd_x_'+boom], ds_h['wspd_y_'+boom] = calcDirWindSpeeds(ds_h['wspd_'+boom], ds_h['wdir_'+boom]) + df_d[['wspd_x_'+boom, 'wspd_y_'+boom]] = ds_h[['wspd_x_'+boom, 'wspd_y_'+boom]].to_dataframe().resample(t).mean() + df_d[var] = _calcWindDir(df_d['wspd_x_'+boom], df_d['wspd_y_'+boom]) # recalculating relative humidity from average vapour pressure and average # saturation vapor pressure