Skip to content

Commit

Permalink
Apply black new stable release (22.1.0) (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnerini authored Feb 2, 2022
1 parent 5f162d4 commit 72f3bf5
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion examples/advection_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def advection_correction(R, T=5, t=1):

Rd += (T - i) * R1 + i * R2

return t / T ** 2 * Rd
return t / T**2 * Rd


###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/plot_cascade_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
M, N = F.shape
fig, ax = plt.subplots()
im = ax.imshow(
np.log(F ** 2), vmin=4, vmax=24, cmap=cm.jet, extent=(-N / 2, N / 2, -M / 2, M / 2)
np.log(F**2), vmin=4, vmax=24, cmap=cm.jet, extent=(-N / 2, N / 2, -M / 2, M / 2)
)
cb = fig.colorbar(im)
ax.set_xlabel("Wavenumber $k_x$")
Expand Down
2 changes: 1 addition & 1 deletion pysteps/cascade/bandpass_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self, c, s):

def __call__(self, x):
x = log_e(x) - self.c
return np.exp(-(x ** 2.0) / (2.0 * self.s ** 2.0))
return np.exp(-(x**2.0) / (2.0 * self.s**2.0))

weight_funcs = []
central_wavenumbers = [0.0]
Expand Down
4 changes: 2 additions & 2 deletions pysteps/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def __call__(self, count, block_size, total_size, exact=True):

self._clear_line()

downloaded_size = count * block_size / (1024 ** 2)
downloaded_size = count * block_size / (1024**2)

if self.total_size is None and total_size > 0:
self.total_size = total_size / (1024 ** 2)
self.total_size = total_size / (1024**2)

if count == 0:
self.init_time = time.time()
Expand Down
4 changes: 2 additions & 2 deletions pysteps/downscaling/rainfarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def downscale(precip, alpha=None, ds_factor=16, threshold=None, return_alpha=Fal
if alpha is None:
fp = np.fft.fft2(precip)
fp_abs = abs(fp)
log_power_spectrum = np.log(fp_abs ** 2)
log_power_spectrum = np.log(fp_abs**2)
valid = (k != 0) & np.isfinite(log_power_spectrum)
alpha = _log_slope(np.log(k[valid]), log_power_spectrum[valid])

Expand All @@ -114,7 +114,7 @@ def downscale(precip, alpha=None, ds_factor=16, threshold=None, return_alpha=Fal
P_u = np.repeat(np.repeat(precip, ds_factor, axis=0), ds_factor, axis=1)
rad = int(round(ds_factor / np.sqrt(np.pi)))
(mx, my) = np.mgrid[-rad : rad + 0.01, -rad : rad + 0.01]
tophat = ((mx ** 2 + my ** 2) <= rad ** 2).astype(float)
tophat = ((mx**2 + my**2) <= rad**2).astype(float)
tophat /= tophat.sum()

P_agg = _balanced_spatial_average(P_u, tophat)
Expand Down
16 changes: 8 additions & 8 deletions pysteps/noise/fftgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,21 @@ def initialize_nonparam_2d_nested_filter(field, gridres=1.0, **kwargs):
# prepare indices
Idxi = np.array([[0, dim_y]])
Idxj = np.array([[0, dim_x]])
Idxipsd = np.array([[0, 2 ** max_level]])
Idxjpsd = np.array([[0, 2 ** max_level]])
Idxipsd = np.array([[0, 2**max_level]])
Idxjpsd = np.array([[0, 2**max_level]])

# generate the FFT sample frequencies
freqx = fft.fftfreq(dim_x, gridres)
freqy = fft.fftfreq(dim_y, gridres)
fx, fy = np.meshgrid(freqx, freqy)
freq_grid = np.sqrt(fx ** 2 + fy ** 2)
freq_grid = np.sqrt(fx**2 + fy**2)

# domain fourier filter
F0 = initialize_nonparam_2d_fft_filter(
field, win_fun=win_fun, donorm=True, use_full_fft=True, fft_method=fft
)["field"]
# and allocate it to the final grid
F = np.zeros((2 ** max_level, 2 ** max_level, F0.shape[0], F0.shape[1]))
F = np.zeros((2**max_level, 2**max_level, F0.shape[0], F0.shape[1]))
F += F0[np.newaxis, np.newaxis, :, :]

# now loop levels and build composite spectra
Expand Down Expand Up @@ -710,9 +710,9 @@ def initialize_nonparam_2d_nested_filter(field, gridres=1.0, **kwargs):

# update indices
level += 1
Idxi, Idxj = _split_field((0, dim[0]), (0, dim[1]), 2 ** level)
Idxi, Idxj = _split_field((0, dim[0]), (0, dim[1]), 2**level)
Idxipsd, Idxjpsd = _split_field(
(0, 2 ** max_level), (0, 2 ** max_level), 2 ** level
(0, 2**max_level), (0, 2**max_level), 2**level
)

return {"field": F, "input_shape": field.shape[1:], "use_full_fft": True}
Expand Down Expand Up @@ -842,8 +842,8 @@ def _split_field(idxi, idxj, Segments):
winsizei = int(sizei / Segments)
winsizej = int(sizej / Segments)

Idxi = np.zeros((Segments ** 2, 2))
Idxj = np.zeros((Segments ** 2, 2))
Idxi = np.zeros((Segments**2, 2))
Idxj = np.zeros((Segments**2, 2))

count = -1
for i in range(Segments):
Expand Down
8 changes: 4 additions & 4 deletions pysteps/nowcasts/anvil.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,14 @@ def _moving_window_corrcoef(x, y, window_radius):
if window_radius is not None:
n = gaussian_filter(mask, window_radius, mode="constant")

ssx = gaussian_filter(x ** 2, window_radius, mode="constant")
ssy = gaussian_filter(y ** 2, window_radius, mode="constant")
ssx = gaussian_filter(x**2, window_radius, mode="constant")
ssy = gaussian_filter(y**2, window_radius, mode="constant")
sxy = gaussian_filter(x * y, window_radius, mode="constant")
else:
n = np.mean(mask)

ssx = np.mean(x ** 2)
ssy = np.mean(y ** 2)
ssx = np.mean(x**2)
ssy = np.mean(y**2)
sxy = np.mean(x * y)

stdx = np.sqrt(ssx / n)
Expand Down
2 changes: 1 addition & 1 deletion pysteps/nowcasts/lagrangian_probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ def _get_kernel(size):
else:
xx, yy = np.mgrid[:size, :size]
circle = (xx - middle) ** 2 + (yy - middle) ** 2
return np.asarray(circle <= (middle ** 2), dtype=np.float32)
return np.asarray(circle <= (middle**2), dtype=np.float32)
14 changes: 7 additions & 7 deletions pysteps/nowcasts/linda.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ def _compute_inverse_acf_mapping(target_dist, target_dist_params, n_intervals=10
"""Compute the inverse ACF mapping between two distributions."""
phi = (
lambda x1, x2, rho: 1.0
/ (2 * np.pi * np.sqrt(1 - rho ** 2))
* np.exp(-(x1 ** 2 + x2 ** 2 - 2 * rho * x1 * x2) / (2 * (1 - rho ** 2)))
/ (2 * np.pi * np.sqrt(1 - rho**2))
* np.exp(-(x1**2 + x2**2 - 2 * rho * x1 * x2) / (2 * (1 - rho**2)))
)

rho_1 = np.linspace(-0.9, 0.9, n_intervals)
Expand Down Expand Up @@ -479,7 +479,7 @@ def _compute_kernel_anisotropic(params, cutoff=6.0):

x2 = xy_grid[0, :] * xy_grid[0, :]
y2 = xy_grid[1, :] * xy_grid[1, :]
result = np.exp(-(x2 / sigma1 ** 2 + y2 / sigma2 ** 2))
result = np.exp(-(x2 / sigma1**2 + y2 / sigma2**2))

return np.reshape(result / np.sum(result), x_grid.shape)

Expand Down Expand Up @@ -576,8 +576,8 @@ def _compute_window_weights(coords, grid_height, grid_width, window_radius):
dx = c[1] - grid_x

w[i, :] = np.exp(
-dy * dy / (2 * window_radius_1 ** 2)
- dx * dx / (2 * window_radius_2 ** 2)
-dy * dy / (2 * window_radius_1**2)
- dx * dx / (2 * window_radius_2**2)
)
else:
w[0, :] = np.ones((grid_height, grid_width))
Expand Down Expand Up @@ -873,10 +873,10 @@ def _fit_dist(err, dist, wf, mask):
"""
Fit a lognormal distribution by maximizing the log-likelihood function
with the constraint that the mean value is one."""
f = lambda p: -np.sum(np.log(stats.lognorm.pdf(err[mask], p, -0.5 * p ** 2)))
f = lambda p: -np.sum(np.log(stats.lognorm.pdf(err[mask], p, -0.5 * p**2)))
p_opt = opt.minimize_scalar(f, bounds=(1e-3, 20.0), method="Bounded")

return (p_opt.x, -0.5 * p_opt.x ** 2)
return (p_opt.x, -0.5 * p_opt.x**2)


# TODO: restrict the perturbation generation inside the radar mask
Expand Down
4 changes: 2 additions & 2 deletions pysteps/scripts/fit_vel_pert_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
mu = dp_par_sum / dp_par_n

std_par.append(
np.sqrt((dp_par_sq_sum - 2 * mu * dp_par_sum + dp_par_n * mu ** 2) / dp_par_n)
np.sqrt((dp_par_sq_sum - 2 * mu * dp_par_sum + dp_par_n * mu**2) / dp_par_n)
)

dp_perp_sum = results[lt]["dp_perp_sum"]
Expand All @@ -52,7 +52,7 @@

std_perp.append(
np.sqrt(
(dp_perp_sq_sum - 2 * mu * dp_perp_sum + dp_perp_n * mu ** 2) / dp_perp_n
(dp_perp_sq_sum - 2 * mu * dp_perp_sum + dp_perp_n * mu**2) / dp_perp_n
)
)

Expand Down
4 changes: 2 additions & 2 deletions pysteps/scripts/run_vel_pert_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@
n_samples = DP_par.size

results[lt]["dp_par_sum"] += np.sum(DP_par)
results[lt]["dp_par_sq_sum"] += np.sum(DP_par ** 2)
results[lt]["dp_par_sq_sum"] += np.sum(DP_par**2)
results[lt]["dp_perp_sum"] += np.sum(DP_perp)
results[lt]["dp_perp_sq_sum"] += np.sum(DP_perp ** 2)
results[lt]["dp_perp_sq_sum"] += np.sum(DP_perp**2)
results[lt]["n_samples"] += n_samples

with open("%s" % args.outfile, "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion pysteps/timeseries/autoregression.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def adjust_lag2_corrcoef2(gamma_1, gamma_2):
"""
gamma_2 = np.maximum(gamma_2, 2 * gamma_1 * gamma_2 - 1)
gamma_2 = np.maximum(
gamma_2, (3 * gamma_1 ** 2 - 2 + 2 * (1 - gamma_1 ** 2) ** 1.5) / gamma_1 ** 2
gamma_2, (3 * gamma_1**2 - 2 + 2 * (1 - gamma_1**2) ** 1.5) / gamma_1**2
)

return gamma_2
Expand Down
16 changes: 8 additions & 8 deletions pysteps/timeseries/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,20 @@ def _moving_window_corrcoef(x, y, window_radius, window="gaussian", mask=None):
else:
window_size = window_radius

n = convol_filter(mask, window_size, mode="constant") * window_size ** 2
n = convol_filter(mask, window_size, mode="constant") * window_size**2

sx = convol_filter(x, window_size, mode="constant") * window_size ** 2
sy = convol_filter(y, window_size, mode="constant") * window_size ** 2
sx = convol_filter(x, window_size, mode="constant") * window_size**2
sy = convol_filter(y, window_size, mode="constant") * window_size**2

ssx = convol_filter(x ** 2, window_size, mode="constant") * window_size ** 2
ssy = convol_filter(y ** 2, window_size, mode="constant") * window_size ** 2
sxy = convol_filter(x * y, window_size, mode="constant") * window_size ** 2
ssx = convol_filter(x**2, window_size, mode="constant") * window_size**2
ssy = convol_filter(y**2, window_size, mode="constant") * window_size**2
sxy = convol_filter(x * y, window_size, mode="constant") * window_size**2

mux = sx / n
muy = sy / n

stdx = np.sqrt(ssx - 2 * mux * sx + n * mux ** 2)
stdy = np.sqrt(ssy - 2 * muy * sy + n * muy ** 2)
stdx = np.sqrt(ssx - 2 * mux * sx + n * mux**2)
stdy = np.sqrt(ssy - 2 * muy * sy + n * muy**2)
cov = sxy - muy * sx - mux * sy + n * mux * muy

mask = np.logical_and(stdx > 1e-8, stdy > 1e-8)
Expand Down
4 changes: 2 additions & 2 deletions pysteps/utils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def to_reflectivity(R, metadata, zr_a=None, zr_b=None):
if zr_b is None:
zr_b = metadata.get("zr_b", 1.6) # Default to Marshall–Palmer

R = zr_a * R ** zr_b
R = zr_a * R**zr_b
metadata["threshold"] = zr_a * metadata["threshold"] ** zr_b
metadata["zerovalue"] = zr_a * metadata["zerovalue"] ** zr_b
metadata["zr_a"] = zr_a
Expand All @@ -300,7 +300,7 @@ def to_reflectivity(R, metadata, zr_a=None, zr_b=None):
zr_a = metadata.get("zr_a", 200.0) # Default to Marshall-Palmer
if zr_b is None:
zr_b = metadata.get("zr_b", 1.6) # Default to Marshall-Palmer
R = zr_a * R ** zr_b
R = zr_a * R**zr_b
metadata["threshold"] = zr_a * metadata["threshold"] ** zr_b
metadata["zerovalue"] = zr_a * metadata["zerovalue"] ** zr_b
metadata["zr_a"] = zr_a
Expand Down
4 changes: 2 additions & 2 deletions pysteps/utils/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def boxcox_transform(

else:
R[~zeros] = (R[~zeros] ** Lambda - 1) / Lambda
threshold = (threshold ** Lambda - 1) / Lambda
threshold = (threshold**Lambda - 1) / Lambda

# Set value for zeros
if zerovalue is None:
Expand Down Expand Up @@ -375,7 +375,7 @@ def sqrt_transform(R, metadata=None, inverse=False, **kwargs):
metadata["threshold"] = np.sqrt(metadata["threshold"])
else:
# inverse sqrt transform
R = R ** 2
R = R**2

metadata["transform"] = None
metadata["zerovalue"] = metadata["zerovalue"] ** 2
Expand Down
4 changes: 2 additions & 2 deletions pysteps/verification/detcontscores.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def det_cont_fct_accum(err, pred, obs):
mobs = np.nanmean(obs, axis=axis)
mpred = np.nanmean(pred, axis=axis)
me = np.nanmean(res, axis=axis)
mse = np.nanmean(res ** 2, axis=axis)
mss = np.nanmean(sum ** 2, axis=axis)
mse = np.nanmean(res**2, axis=axis)
mss = np.nanmean(sum**2, axis=axis)
mae = np.nanmean(np.abs(res), axis=axis)

# expand axes for broadcasting
Expand Down
2 changes: 1 addition & 1 deletion pysteps/verification/probscores.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def CRPS_accum(CRPS, X_f, X_o):
beta[mask, -1] = 0.0

p = 1.0 * np.arange(m + 1) / m
res = np.sum(alpha * p ** 2.0 + beta * (1.0 - p) ** 2.0, axis=1)
res = np.sum(alpha * p**2.0 + beta * (1.0 - p) ** 2.0, axis=1)

CRPS["CRPS_sum"] += np.sum(res)
CRPS["n"] += len(res)
Expand Down
4 changes: 2 additions & 2 deletions pysteps/verification/spatialscores.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,9 @@ def fss_accum(fss, X_f, X_o):
S_f = I_f
S_o = I_o

fss["sum_obs_sq"] += np.nansum(S_o ** 2)
fss["sum_obs_sq"] += np.nansum(S_o**2)
fss["sum_fct_obs"] += np.nansum(S_f * S_o)
fss["sum_fct_sq"] += np.nansum(S_f ** 2)
fss["sum_fct_sq"] += np.nansum(S_f**2)


def fss_merge(fss_1, fss_2):
Expand Down
2 changes: 1 addition & 1 deletion pysteps/visualization/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def plot_spectrum1d(
# Y-axis
if y_units is not None:
# { -> {{ with f-strings
power_units = fr"$10log_{{ 10 }}(\frac{{ {y_units}^2 }}{{ {x_units} }})$"
power_units = rf"$10log_{{ 10 }}(\frac{{ {y_units}^2 }}{{ {x_units} }})$"
ax.set_ylabel(f"Power {power_units}")

return ax

0 comments on commit 72f3bf5

Please sign in to comment.