Skip to content

Commit 72f3bf5

Browse files
authored
Apply black new stable release (22.1.0) (#261)
1 parent 5f162d4 commit 72f3bf5

19 files changed

+50
-50
lines changed

examples/advection_correction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def advection_correction(R, T=5, t=1):
111111

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

114-
return t / T ** 2 * Rd
114+
return t / T**2 * Rd
115115

116116

117117
###############################################################################

examples/plot_cascade_decomposition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
M, N = F.shape
6262
fig, ax = plt.subplots()
6363
im = ax.imshow(
64-
np.log(F ** 2), vmin=4, vmax=24, cmap=cm.jet, extent=(-N / 2, N / 2, -M / 2, M / 2)
64+
np.log(F**2), vmin=4, vmax=24, cmap=cm.jet, extent=(-N / 2, N / 2, -M / 2, M / 2)
6565
)
6666
cb = fig.colorbar(im)
6767
ax.set_xlabel("Wavenumber $k_x$")

pysteps/cascade/bandpass_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def __init__(self, c, s):
208208

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

213213
weight_funcs = []
214214
central_wavenumbers = [0.0]

pysteps/datasets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ def __call__(self, count, block_size, total_size, exact=True):
117117

118118
self._clear_line()
119119

120-
downloaded_size = count * block_size / (1024 ** 2)
120+
downloaded_size = count * block_size / (1024**2)
121121

122122
if self.total_size is None and total_size > 0:
123-
self.total_size = total_size / (1024 ** 2)
123+
self.total_size = total_size / (1024**2)
124124

125125
if count == 0:
126126
self.init_time = time.time()

pysteps/downscaling/rainfarm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def downscale(precip, alpha=None, ds_factor=16, threshold=None, return_alpha=Fal
9898
if alpha is None:
9999
fp = np.fft.fft2(precip)
100100
fp_abs = abs(fp)
101-
log_power_spectrum = np.log(fp_abs ** 2)
101+
log_power_spectrum = np.log(fp_abs**2)
102102
valid = (k != 0) & np.isfinite(log_power_spectrum)
103103
alpha = _log_slope(np.log(k[valid]), log_power_spectrum[valid])
104104

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

120120
P_agg = _balanced_spatial_average(P_u, tophat)

pysteps/noise/fftgenerators.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,21 @@ def initialize_nonparam_2d_nested_filter(field, gridres=1.0, **kwargs):
637637
# prepare indices
638638
Idxi = np.array([[0, dim_y]])
639639
Idxj = np.array([[0, dim_x]])
640-
Idxipsd = np.array([[0, 2 ** max_level]])
641-
Idxjpsd = np.array([[0, 2 ** max_level]])
640+
Idxipsd = np.array([[0, 2**max_level]])
641+
Idxjpsd = np.array([[0, 2**max_level]])
642642

643643
# generate the FFT sample frequencies
644644
freqx = fft.fftfreq(dim_x, gridres)
645645
freqy = fft.fftfreq(dim_y, gridres)
646646
fx, fy = np.meshgrid(freqx, freqy)
647-
freq_grid = np.sqrt(fx ** 2 + fy ** 2)
647+
freq_grid = np.sqrt(fx**2 + fy**2)
648648

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

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

711711
# update indices
712712
level += 1
713-
Idxi, Idxj = _split_field((0, dim[0]), (0, dim[1]), 2 ** level)
713+
Idxi, Idxj = _split_field((0, dim[0]), (0, dim[1]), 2**level)
714714
Idxipsd, Idxjpsd = _split_field(
715-
(0, 2 ** max_level), (0, 2 ** max_level), 2 ** level
715+
(0, 2**max_level), (0, 2**max_level), 2**level
716716
)
717717

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

845-
Idxi = np.zeros((Segments ** 2, 2))
846-
Idxj = np.zeros((Segments ** 2, 2))
845+
Idxi = np.zeros((Segments**2, 2))
846+
Idxj = np.zeros((Segments**2, 2))
847847

848848
count = -1
849849
for i in range(Segments):

pysteps/nowcasts/anvil.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,14 @@ def _moving_window_corrcoef(x, y, window_radius):
475475
if window_radius is not None:
476476
n = gaussian_filter(mask, window_radius, mode="constant")
477477

478-
ssx = gaussian_filter(x ** 2, window_radius, mode="constant")
479-
ssy = gaussian_filter(y ** 2, window_radius, mode="constant")
478+
ssx = gaussian_filter(x**2, window_radius, mode="constant")
479+
ssy = gaussian_filter(y**2, window_radius, mode="constant")
480480
sxy = gaussian_filter(x * y, window_radius, mode="constant")
481481
else:
482482
n = np.mean(mask)
483483

484-
ssx = np.mean(x ** 2)
485-
ssy = np.mean(y ** 2)
484+
ssx = np.mean(x**2)
485+
ssy = np.mean(y**2)
486486
sxy = np.mean(x * y)
487487

488488
stdx = np.sqrt(ssx / n)

pysteps/nowcasts/lagrangian_probability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ def _get_kernel(size):
128128
else:
129129
xx, yy = np.mgrid[:size, :size]
130130
circle = (xx - middle) ** 2 + (yy - middle) ** 2
131-
return np.asarray(circle <= (middle ** 2), dtype=np.float32)
131+
return np.asarray(circle <= (middle**2), dtype=np.float32)

pysteps/nowcasts/linda.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ def _compute_inverse_acf_mapping(target_dist, target_dist_params, n_intervals=10
430430
"""Compute the inverse ACF mapping between two distributions."""
431431
phi = (
432432
lambda x1, x2, rho: 1.0
433-
/ (2 * np.pi * np.sqrt(1 - rho ** 2))
434-
* np.exp(-(x1 ** 2 + x2 ** 2 - 2 * rho * x1 * x2) / (2 * (1 - rho ** 2)))
433+
/ (2 * np.pi * np.sqrt(1 - rho**2))
434+
* np.exp(-(x1**2 + x2**2 - 2 * rho * x1 * x2) / (2 * (1 - rho**2)))
435435
)
436436

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

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

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

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

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

879-
return (p_opt.x, -0.5 * p_opt.x ** 2)
879+
return (p_opt.x, -0.5 * p_opt.x**2)
880880

881881

882882
# TODO: restrict the perturbation generation inside the radar mask

pysteps/scripts/fit_vel_pert_params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
mu = dp_par_sum / dp_par_n
4343

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

4848
dp_perp_sum = results[lt]["dp_perp_sum"]
@@ -52,7 +52,7 @@
5252

5353
std_perp.append(
5454
np.sqrt(
55-
(dp_perp_sq_sum - 2 * mu * dp_perp_sum + dp_perp_n * mu ** 2) / dp_perp_n
55+
(dp_perp_sq_sum - 2 * mu * dp_perp_sum + dp_perp_n * mu**2) / dp_perp_n
5656
)
5757
)
5858

0 commit comments

Comments
 (0)