From 0664159cc6e28e7fa3ee5905cca011144bca72ad Mon Sep 17 00:00:00 2001 From: Simon De Kock Date: Tue, 16 Jul 2024 14:18:27 +0200 Subject: [PATCH] Fixed to black formatting --- pysteps/blending/steps.py | 24 ++++++++++++++++++++---- pysteps/blending/utils.py | 12 ++++++++++-- pysteps/nowcasts/utils.py | 3 ++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pysteps/blending/steps.py b/pysteps/blending/steps.py index fe5ae7f2a..562298228 100644 --- a/pysteps/blending/steps.py +++ b/pysteps/blending/steps.py @@ -1458,18 +1458,32 @@ def worker(j): if create_smooth_radar_mask is True: # Compute the smooth dilated mask nan_indices = np.isnan(R_f_new) - new_mask = blending.utils.compute_smooth_dilated_mask(nan_indices, 100, gaussian_kernel_size=9, inverted=False, non_linear_growth_kernel_sizes=False) + new_mask = blending.utils.compute_smooth_dilated_mask( + nan_indices, + 100, + gaussian_kernel_size=9, + inverted=False, + non_linear_growth_kernel_sizes=False, + ) # Ensure mask values are between 0 and 1 mask_model = new_mask mask_radar = 1 - new_mask # Handle NaNs in R_f_new and R_f_new_mod_only by setting NaNs to 0 in the blending step - R_f_new_mod_only_no_nan = np.nan_to_num(R_f_new_mod_only, nan=0) + R_f_new_mod_only_no_nan = np.nan_to_num( + R_f_new_mod_only, nan=0 + ) R_f_new_no_nan = np.nan_to_num(R_f_new, nan=0) # Perform the blending of radar and model inside the radar domain using a weighted combination - R_f_new = np.nansum([mask_model * R_f_new_mod_only_no_nan, mask_radar * R_f_new_no_nan], axis=0) + R_f_new = np.nansum( + [ + mask_model * R_f_new_mod_only_no_nan, + mask_radar * R_f_new_no_nan, + ], + axis=0, + ) # Finally, fill the remaining nan values, if present, with # the minimum value in the forecast R_f_new[np.isnan(R_f_new)] = np.nanmin(R_f_new) @@ -1477,7 +1491,9 @@ def worker(j): nan_indices = np.isnan(R_f_new) R_f_new[nan_indices] = R_f_new_mod_only[nan_indices] nan_indices = np.isnan(R_pm_blended) - R_pm_blended[nan_indices] = R_pm_blended_mod_only[nan_indices] + R_pm_blended[nan_indices] = R_pm_blended_mod_only[ + nan_indices + ] # Finally, fill the remaining nan values, if present, with # the minimum value in the forecast nan_indices = np.isnan(R_f_new) diff --git a/pysteps/blending/utils.py b/pysteps/blending/utils.py index 09f46bbf2..b619e49d0 100644 --- a/pysteps/blending/utils.py +++ b/pysteps/blending/utils.py @@ -38,10 +38,12 @@ try: import cv2 + CV2_IMPORTED = True except ImportError: CV2_IMPORTED = False + def stack_cascades(R_d, donorm=True): """Stack the given cascades into a larger array. @@ -564,8 +566,14 @@ def check_norain(precip_arr, precip_thr=None, norain_thr=0.0): ) return norain -def compute_smooth_dilated_mask(original_mask, max_padding_size_in_px, gaussian_kernel_size=9, - inverted=False, non_linear_growth_kernel_sizes=False): + +def compute_smooth_dilated_mask( + original_mask, + max_padding_size_in_px, + gaussian_kernel_size=9, + inverted=False, + non_linear_growth_kernel_sizes=False, +): """ Compute a smooth dilated mask using Gaussian blur and dilation with varying kernel sizes. diff --git a/pysteps/nowcasts/utils.py b/pysteps/nowcasts/utils.py index baa5c649d..fd111e28d 100644 --- a/pysteps/nowcasts/utils.py +++ b/pysteps/nowcasts/utils.py @@ -24,12 +24,12 @@ try: import dask + DASK_IMPORTED = True except ImportError: DASK_IMPORTED = False - def binned_timesteps(timesteps): """ Compute a binning of the given irregular time steps. @@ -97,6 +97,7 @@ def compute_dilated_mask(input_mask, kr, r): # normalize between 0 and 1 return mask / mask.max() + def compute_percentile_mask(precip, pct): """Compute a precipitation mask, where True/False values are assigned for pixels above/below the given percentile.