Skip to content

Commit

Permalink
Fixed to black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sidekock committed Jul 16, 2024
1 parent 229bbd9 commit 0664159
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
24 changes: 20 additions & 4 deletions pysteps/blending/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,26 +1458,42 @@ 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(

Check warning on line 1461 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L1460-L1461

Added lines #L1460 - L1461 were not covered by tests
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

Check warning on line 1471 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L1470-L1471

Added lines #L1470 - L1471 were not covered by tests

# 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(

Check warning on line 1474 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L1474

Added line #L1474 was not covered by tests
R_f_new_mod_only, nan=0
)
R_f_new_no_nan = np.nan_to_num(R_f_new, nan=0)

Check warning on line 1477 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L1477

Added line #L1477 was not covered by tests

# 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(

Check warning on line 1480 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L1480

Added line #L1480 was not covered by tests
[
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)

Check warning on line 1489 in pysteps/blending/steps.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/steps.py#L1489

Added line #L1489 was not covered by tests
else:
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)
Expand Down
12 changes: 10 additions & 2 deletions pysteps/blending/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@

try:
import cv2

CV2_IMPORTED = True
except ImportError:
CV2_IMPORTED = False

Check warning on line 44 in pysteps/blending/utils.py

View check run for this annotation

Codecov / codecov/patch

pysteps/blending/utils.py#L43-L44

Added lines #L43 - L44 were not covered by tests


def stack_cascades(R_d, donorm=True):
"""Stack the given cascades into a larger array.
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pysteps/nowcasts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0664159

Please sign in to comment.