diff --git a/modules/util/util.py b/modules/util/util.py index 44a034e22ec15a47b2d23b316e65655f24c57945..848e988feb15ebbb2cfd305e16d3c86dd2b489c1 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -12,6 +12,7 @@ import pickle from netCDF4 import Dataset from util.setup import ancillary_path from scipy.interpolate import RectBivariateSpline, interp2d +from scipy.ndimage import gaussian_filter LatLonTuple = namedtuple('LatLonTuple', ['lat', 'lon']) @@ -1426,6 +1427,18 @@ def resample_2d_linear_one(x, y, z, x_new, y_new): return f(x_new, y_new) +# Gaussian filter suitable for model training Data Pipeline +# z: input array. Must have dimensions: [BATCH_SIZE, Y, X] +# sigma: Standard deviation for Gaussian kernel +# returns stacked 2d arrays of same input dimension +def smooth_2d(z, sigma=1.0): + z_smoothed = [] + for j in range(z.shape[0]): + z_j = z[j, :, :] + z_smoothed.append(gaussian_filter(z_j, sigma=sigma)) + return np.stack(z_smoothed) + + def get_training_parameters(day_night='DAY', l1b_andor_l2='both', satellite='GOES16', use_dnb=False): if day_night == 'DAY': train_params_l2 = ['cld_height_acha', 'cld_geo_thick', 'cld_temp_acha', 'cld_press_acha', 'supercooled_cloud_fraction',