Skip to content

Commit a922e45

Browse files
committed
Make kmperpixel and timestep optional keyword arguments
1 parent e37847f commit a922e45

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

examples/ensemble_verification.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,19 @@ def export(X):
240240
## start the nowcast
241241
nwc_method = stp.nowcasts.get_method(p["nwc_method"])
242242
R_fct = nwc_method(R, UV, p["n_lead_times"], p["n_ens_members"],
243-
p["n_cascade_levels"], metadata["xpixelsize"]/1000,
244-
ds.timestep, R_thr=metadata["threshold"], extrap_method=p["adv_method"],
245-
decomp_method=p["decomp_method"], bandpass_filter_method=p["bandpass_filter"],
246-
noise_method=p["noise_method"], noise_stddev_adj=p["noise_adjustment"],
243+
p["n_cascade_levels"], kmperpixel=metadata["xpixelsize"]/1000,
244+
timestep=ds.timestep, R_thr=metadata["threshold"],
245+
extrap_method=p["adv_method"],
246+
decomp_method=p["decomp_method"],
247+
bandpass_filter_method=p["bandpass_filter"],
248+
noise_method=p["noise_method"],
249+
noise_stddev_adj=p["noise_adjustment"],
247250
ar_order=p["ar_order"],conditional=p["conditional"],
248-
use_probmatching=p["prob_matching"], mask_method=p["mask_method"],
251+
use_probmatching=p["prob_matching"],
252+
mask_method=p["mask_method"],
249253
use_precip_mask=p["precip_mask"], callback=export,
250254
return_output=False, seed=p["seed"])
251-
255+
252256
## save results
253257
stp.io.close_forecast_file(exporter)
254258
R_fct = None

examples/run_ensemble_nowcast.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@
108108
# Perform the nowcast
109109
nwc_method = stp.nowcasts.get_method(nwc_method)
110110
R_fct = nwc_method(R, UV, n_lead_times, n_ens_members,
111-
n_cascade_levels, metadata["xpixelsize"]/1000,
112-
ds.timestep, R_thr=metadata["threshold"], extrap_method=adv_method,
113-
decomp_method=decomp_method, bandpass_filter_method=bandpass_filter,
111+
n_cascade_levels, kmperpixel=metadata["xpixelsize"]/1000,
112+
timestep=ds.timestep, R_thr=metadata["threshold"],
113+
extrap_method=adv_method, decomp_method=decomp_method,
114+
bandpass_filter_method=bandpass_filter,
114115
noise_method=noise_method, noise_stddev_adj=adjust_noise,
115116
ar_order=ar_order, conditional=conditional,
116117
use_precip_mask=precip_mask, mask_method=mask_method,

pysteps/nowcasts/steps.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
except ImportError:
1616
dask_imported = False
1717

18-
def forecast(R, V, n_timesteps, n_ens_members, n_cascade_levels,
19-
kmperpixel, timestep, R_thr=None, extrap_method="semilagrangian",
18+
def forecast(R, V, n_timesteps, n_ens_members, n_cascade_levels, R_thr=None,
19+
kmperpixel=None, timestep=None, extrap_method="semilagrangian",
2020
decomp_method="fft", bandpass_filter_method="gaussian",
2121
noise_method="nonparametric", noise_stddev_adj=True, ar_order=2,
2222
vel_pert_method=None, conditional=False, use_precip_mask=True,
@@ -41,16 +41,18 @@ def forecast(R, V, n_timesteps, n_ens_members, n_cascade_levels,
4141
The number of ensemble members to generate.
4242
n_cascade_levels : int
4343
The number of cascade levels to use.
44-
kmperpixel : float
45-
Spatial resolution of the input data (kilometers/pixel).
46-
timestep : float
47-
Time step of the motion vectors (minutes).
4844
4945
Other Parameters
5046
----------------
5147
R_thr : float
5248
Specifies the threshold value for minimum observable precipitation
5349
intensity. Must be set if use_probmatching is True or conditional is True.
50+
kmperpixel : float
51+
Spatial resolution of the input data (kilometers/pixel). Required if
52+
vel_pert_method is not None or mask_method is 'incremental'.
53+
timestep : float
54+
Time step of the motion vectors (minutes). Required if vel_pert_method is
55+
not None or mask_method is 'incremental'.
5456
extrap_method : {'semilagrangian'}
5557
Name of the extrapolation method to use. See the documentation of
5658
pysteps.advection.
@@ -148,15 +150,29 @@ def forecast(R, V, n_timesteps, n_ens_members, n_cascade_levels,
148150
if use_probmatching and R_thr is None:
149151
raise Exception("use_probmatching=True but R_thr is not set")
150152

153+
if kmperpixel is None:
154+
if vel_pert_method is None:
155+
raise Exception("vel_pert_method is set but kmperpixel=None")
156+
if mask_method == "incremental":
157+
raise Exception("mask_method='incremental' but kmperpixel=None")
158+
159+
if timestep is None:
160+
if vel_pert_method is None:
161+
raise Exception("vel_pert_method is set but timestep=None")
162+
if mask_method == "incremental":
163+
raise Exception("mask_method='incremental' but timestep=None")
164+
151165
print("Computing STEPS nowcast:")
152166
print("------------------------")
153167
print("")
154168

155169
print("Inputs:")
156170
print("-------")
157171
print("input dimensions: %dx%d" % (R.shape[1], R.shape[2]))
158-
print("km/pixel: %g" % kmperpixel)
159-
print("time step: %d minutes" % timestep)
172+
if kmperpixel is not None:
173+
print("km/pixel: %g" % kmperpixel)
174+
if timestep is not None:
175+
print("time step: %d minutes" % timestep)
160176
print("")
161177

162178
print("Methods:")

0 commit comments

Comments
 (0)