Skip to content

Commit b5b59b1

Browse files
committed
Small improvements
1 parent a3b5fcb commit b5b59b1

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

examples/plot_extrapolation_nowcast.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151
# Plot the rainfall field
5252
plot_precip_field(R[-1, :, :], geodata=metadata)
5353

54-
# Store the last frame for polotting it later later
54+
# Store the last frame for plotting it later later
5555
R_ = R[-1, :, :].copy()
5656

57-
# Log-transform the data
57+
# Log-transform the data to unit of dBR, set the threshold to 0.1 mm/h,
58+
# set the fill value to -15 dBR
5859
R, metadata = transformation.dB_transform(R, metadata, threshold=0.1, zerovalue=-15.0)
5960

6061
# Nicely print the metadata
@@ -111,12 +112,12 @@
111112
# Compute fractions skill score (FSS) for all lead times, a set of scales and 1 mm/h
112113
fss = verification.get_method("FSS")
113114
scales = [2, 4, 8, 16, 32, 64, 128, 256, 512]
114-
threshold = 1.0
115+
thr = 1.0
115116
score = []
116117
for i in range(n_leadtimes):
117118
score_ = []
118119
for scale in scales:
119-
score_.append(fss(R_f[i, :, :], R_o[i + 1, :, :], threshold, scale))
120+
score_.append(fss(R_f[i, :, :], R_o[i + 1, :, :], thr, scale))
120121
score.append(score_)
121122

122123
figure()
@@ -126,5 +127,5 @@
126127
xlabel("Lead time [min]")
127128
ylabel("FSS ( > 1.0 mm/h ) ")
128129
title("Fractions skill score")
129-
show()
130-
# sphinx_gallery_thumbnail_number = 2
130+
131+
# sphinx_gallery_thumbnail_number = 3

examples/plot_steps_nowcast.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from pylab import *
1212
from datetime import datetime
13+
from pprint import pprint
1314
from pysteps import io, nowcasts, rcparams
1415
from pysteps.motion.lucaskanade import dense_lucaskanade
1516
from pysteps.postprocessing.ensemblestats import excprob
@@ -29,7 +30,6 @@
2930
# transformed into units of dBR.
3031

3132

32-
3333
date = datetime.strptime("201701311200", "%Y%m%d%H%M")
3434
data_source = "mch"
3535

@@ -44,7 +44,7 @@
4444

4545
# Find the radar files in the archive
4646
fns = io.find_by_date(
47-
date, root_path, path_fmt, fn_pattern, fn_ext, timestep, num_prev_files=2,
47+
date, root_path, path_fmt, fn_pattern, fn_ext, timestep, num_prev_files=2
4848
)
4949

5050
# Read the data from the archive
@@ -60,12 +60,16 @@
6060
# Plot the rainfall field
6161
plot_precip_field(R[-1, :, :], geodata=metadata)
6262

63-
# Log-transform the data to unit of dBR, set the threshold to 0.1 mm/h
64-
R = transformation.dB_transform(R, threshold=0.1, zerovalue=-15.0)[0]
63+
# Log-transform the data to unit of dBR, set the threshold to 0.1 mm/h,
64+
# set the fill value to -15 dBR
65+
R, metadata = transformation.dB_transform(R, metadata, threshold=0.1, zerovalue=-15.0)
6566

6667
# Set missing values with the fill value
6768
R[~np.isfinite(R)] = -15.0
6869

70+
# Nicely print the metadata
71+
pprint(metadata)
72+
6973
###############################################################################
7074
# Deterministic nowcast with S-PROG
7175
# ---------------------------------
@@ -96,24 +100,27 @@
96100
R_f = transformation.dB_transform(R_f, threshold=-10.0, inverse=True)[0]
97101

98102
# Plot the S-PROG forecast
99-
plot_precip_field(R_f[-1, :, :], geodata=metadata, title="S-PROG")
103+
plot_precip_field(
104+
R_f[-1, :, :],
105+
geodata=metadata,
106+
title="S-PROG (+ %i min)" % (n_leadtimes * timestep),
107+
)
100108

101109
###############################################################################
102110
# As we can see from the figure above, the forecast produced by S-PROG is a
103111
# smooth field. In other words, the forecast variance is lower than the
104112
# variance of the original observed field.
105-
# However, given applications demand that the forecast retain the same
113+
# However, certain applications demand that the forecast retain the same
106114
# statistical properties of the observations. In such cases, the S-PROG
107-
# forecsats are of limited use and a stochatic approahc might be of more
115+
# forecasts are of limited use and a stochatic approach might be of more
108116
# interest.
109117

110118
###############################################################################
111119
# Stochastic nowcast with STEPS
112120
# -----------------------------
113121
#
114-
#
115122
# The S-PROG approach is extended to include a stochastic term which represents
116-
# the variance linked to the unpredictable development of precipitation. This
123+
# the variance associated to the unpredictable development of precipitation. This
117124
# approach is known as STEPS (short-term ensemble prediction system).
118125

119126
# The STEPES nowcast
@@ -141,25 +148,31 @@
141148

142149
# Plot the ensemble mean
143150
R_f_mean = np.mean(R_f[:, -1, :, :], axis=0)
144-
plot_precip_field(R_f_mean, geodata=metadata, title="Ensemble mean")
151+
plot_precip_field(
152+
R_f_mean,
153+
geodata=metadata,
154+
title="Ensemble mean (+ %i min)" % (n_leadtimes * timestep),
155+
)
145156

146157
###############################################################################
147158
# The mean of the ensemble displays similar properties as the S-PROG
148-
# forecast seen above, although the degree of smoothing strongly depends on
159+
# forecast seen above, although the degree of smoothing also depends on
149160
# the ensemble size. In this sense, the S-PROG forecast can be seen as
150161
# the mean of an ensemble of infinite size.
151162

152163
# Plot the first two realizations
153164
fig = figure()
154-
for i in range(2):
155-
ax = fig.add_subplot(121 + i)
165+
for i in range(4):
166+
ax = fig.add_subplot(221 + i)
156167
ax.set_title("Member %02d" % i)
157168
plot_precip_field(R_f[i, -1, :, :], geodata=metadata, colorbar=False, axis="off")
158169
tight_layout()
159170

160171
###############################################################################
161172
# As we can see from these two members of the ensemble, the stochastic forecast
162173
# mantains the same variance as in the observed rainfall field.
174+
# STEPS also includes a stochatic perturbation of the motion field in order
175+
# to quantify the its uncertainty.
163176

164177
###############################################################################
165178
# Finally, it is possible to derive probabilities from our ensemble forecast.
@@ -175,7 +188,7 @@
175188
type="prob",
176189
units="mm/h",
177190
probthr=0.5,
178-
title="Exceedence probability",
191+
title="Exceedence probability (+ %i min)" % (n_leadtimes * timestep),
179192
)
180193

181194
# sphinx_gallery_thumbnail_number = 5

0 commit comments

Comments
 (0)