Skip to content

Commit 1acd5a4

Browse files
committed
Marginal improvements to text and syntax
1 parent 498a74b commit 1acd5a4

File tree

3 files changed

+71
-45
lines changed

3 files changed

+71
-45
lines changed

examples/LK_buffer_mask.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""
1515

1616
from datetime import datetime
17-
from pprint import pprint
1817
from matplotlib import cm, colors
1918

2019
import matplotlib.pyplot as plt

examples/plot_ensemble_verification.py

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,47 @@
44
=====================
55
66
This tutorial shows how to compute and plot an extrapolation nowcast using
7-
Finnish radar data.
7+
MeteoSwiss radar data.
88
99
"""
1010

11-
from pylab import *
1211
from datetime import datetime
12+
import matplotlib.pyplot as plt
13+
import numpy as np
1314
from pprint import pprint
1415
from pysteps import io, nowcasts, rcparams, verification
1516
from pysteps.motion.lucaskanade import dense_lucaskanade
1617
from pysteps.postprocessing import ensemblestats
1718
from pysteps.utils import conversion, dimension, transformation
1819
from pysteps.visualization import plot_precip_field
1920

20-
# Set nowcast parameters
21-
n_ens_members = 20
22-
n_leadtimes = 6
23-
seed = 24
2421

2522
###############################################################################
2623
# Read precipitation field
2724
# ------------------------
2825
#
29-
# First thing, the sequence of Swiss radar composites is imported, converted and
30-
# transformed into units of dBR.
26+
# First, we will import the sequence of MeteoSwiss ("mch") radar composites.
27+
# You need the pysteps-data archive downloaded and the pystepsrc file
28+
# configured with the data_source paths pointing to data folders.
3129

30+
# Selected case
3231
date = datetime.strptime("201607112100", "%Y%m%d%H%M")
33-
data_source = "mch"
32+
data_source = rcparams.data_sources["mch"]
33+
n_ens_members = 20
34+
n_leadtimes = 6
35+
seed = 24
36+
37+
###############################################################################
38+
# Load the data from the archive
39+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3440

35-
# Load data source config
36-
root_path = rcparams.data_sources[data_source]["root_path"]
37-
path_fmt = rcparams.data_sources[data_source]["path_fmt"]
38-
fn_pattern = rcparams.data_sources[data_source]["fn_pattern"]
39-
fn_ext = rcparams.data_sources[data_source]["fn_ext"]
40-
importer_name = rcparams.data_sources[data_source]["importer"]
41-
importer_kwargs = rcparams.data_sources[data_source]["importer_kwargs"]
42-
timestep = rcparams.data_sources[data_source]["timestep"]
41+
root_path = data_source["root_path"]
42+
path_fmt = data_source["path_fmt"]
43+
fn_pattern = data_source["fn_pattern"]
44+
fn_ext = data_source["fn_ext"]
45+
importer_name = data_source["importer"]
46+
importer_kwargs = data_source["importer_kwargs"]
47+
timestep = data_source["timestep"]
4348

4449
# Find the radar files in the archive
4550
fns = io.find_by_date(
@@ -58,6 +63,7 @@
5863

5964
# Plot the rainfall field
6065
plot_precip_field(R[-1, :, :], geodata=metadata)
66+
plt.show()
6167

6268
# Log-transform the data to unit of dBR, set the threshold to 0.1 mm/h,
6369
# set the fill value to -15 dBR
@@ -101,12 +107,13 @@
101107
R_f = transformation.dB_transform(R_f, threshold=-10.0, inverse=True)[0]
102108

103109
# Plot some of the realizations
104-
fig = figure()
110+
fig = plt.figure()
105111
for i in range(4):
106112
ax = fig.add_subplot(221 + i)
107113
ax.set_title("Member %02d" % i)
108114
plot_precip_field(R_f[i, -1, :, :], geodata=metadata, colorbar=False, axis="off")
109-
tight_layout()
115+
plt.tight_layout()
116+
plt.show()
110117

111118
###############################################################################
112119
# Verification
@@ -145,25 +152,37 @@
145152
# compute the exceedance probability of 0.1 mm/h from the ensemble
146153
P_f = ensemblestats.excprob(R_f[:, -1, :, :], 0.1, ignore_nan=True)
147154

148-
# compute and plot the ROC curve
155+
###############################################################################
156+
# ROC curve
157+
# ~~~~~~~~~
158+
149159
roc = verification.ROC_curve_init(0.1, n_prob_thrs=10)
150160
verification.ROC_curve_accum(roc, P_f, R_o[-1, :, :])
151-
fig, ax = subplots()
161+
fig, ax = plt.subplots()
152162
verification.plot_ROC(roc, ax, opt_prob_thr=True)
153163
ax.set_title("ROC curve (+ %i min)" % (n_leadtimes * timestep))
164+
plt.show()
165+
166+
###############################################################################
167+
# Reliability diagram
168+
# ~~~~~~~~~~~~~~~~~~~
154169

155-
# compute and plot the reliability diagram
156170
reldiag = verification.reldiag_init(0.1)
157171
verification.reldiag_accum(reldiag, P_f, R_o[-1, :, :])
158-
fig, ax = subplots()
172+
fig, ax = plt.subplots()
159173
verification.plot_reldiag(reldiag, ax)
160174
ax.set_title("Reliability diagram (+ %i min)" % (n_leadtimes * timestep))
175+
plt.show()
176+
177+
###############################################################################
178+
# Rank histogram
179+
# ~~~~~~~~~~~~~~
161180

162-
# compute and plot the rank histogram
163181
rankhist = verification.rankhist_init(R_f.shape[0], 0.1)
164182
verification.rankhist_accum(rankhist, R_f[:, -1, :, :], R_o[-1, :, :])
165-
fig, ax = subplots()
183+
fig, ax = plt.subplots()
166184
verification.plot_rankhist(rankhist, ax)
167185
ax.set_title("Rank histogram (+ %i min)" % (n_leadtimes * timestep))
186+
plt.show()
168187

169188
# sphinx_gallery_thumbnail_number = 5

examples/plot_extrapolation_nowcast.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
99
"""
1010

11-
from pylab import *
1211
from datetime import datetime
12+
import matplotlib.pyplot as plt
1313
import numpy as np
1414
from pprint import pprint
1515
from pysteps import io, motion, nowcasts, rcparams, verification
@@ -20,21 +20,26 @@
2020
# Read the radar input images
2121
# ---------------------------
2222
#
23-
# First thing, the sequence of radar composites is imported, converted and
24-
# transformed into units of dBR.
23+
# First, we will import the sequence of radar composites.
24+
# You need the pysteps-data archive downloaded and the pystepsrc file
25+
# configured with the data_source paths pointing to data folders.
2526

27+
# Selected case
2628
date = datetime.strptime("201609281600", "%Y%m%d%H%M")
27-
data_source = "fmi"
29+
data_source = rcparams.data_sources["fmi"]
2830
n_leadtimes = 12
2931

30-
# Load data source config
31-
root_path = rcparams.data_sources[data_source]["root_path"]
32-
path_fmt = rcparams.data_sources[data_source]["path_fmt"]
33-
fn_pattern = rcparams.data_sources[data_source]["fn_pattern"]
34-
fn_ext = rcparams.data_sources[data_source]["fn_ext"]
35-
importer_name = rcparams.data_sources[data_source]["importer"]
36-
importer_kwargs = rcparams.data_sources[data_source]["importer_kwargs"]
37-
timestep = rcparams.data_sources[data_source]["timestep"]
32+
###############################################################################
33+
# Load the data from the archive
34+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
36+
root_path = data_source["root_path"]
37+
path_fmt = data_source["path_fmt"]
38+
fn_pattern = data_source["fn_pattern"]
39+
fn_ext = data_source["fn_ext"]
40+
importer_name = data_source["importer"]
41+
importer_kwargs = data_source["importer_kwargs"]
42+
timestep = data_source["timestep"]
3843

3944
# Find the input files from the archive
4045
fns = io.archive.find_by_date(
@@ -50,6 +55,7 @@
5055

5156
# Plot the rainfall field
5257
plot_precip_field(R[-1, :, :], geodata=metadata)
58+
plt.show()
5359

5460
# Store the last frame for plotting it later later
5561
R_ = R[-1, :, :].copy()
@@ -66,7 +72,7 @@
6672
# -------------------
6773
#
6874
# The extrapolation nowcast is based on the estimation of the motion field,
69-
# which is here performed using a local tacking approach (Lucas-Kanade).
75+
# which is here performed using a local tracking approach (Lucas-Kanade).
7076
# The most recent radar rainfall field is then simply advected along this motion
7177
# field in oder to produce an extrapolation forecast.
7278

@@ -85,6 +91,7 @@
8591
# Plot the motion field
8692
plot_precip_field(R_, geodata=metadata)
8793
quiver(V, geodata=metadata, step=50)
94+
plt.show()
8895

8996
###############################################################################
9097
# Verify with FSS
@@ -120,12 +127,13 @@
120127
score_.append(fss(R_f[i, :, :], R_o[i + 1, :, :], thr, scale))
121128
score.append(score_)
122129

123-
figure()
130+
plt.figure()
124131
x = np.arange(1, n_leadtimes + 1) * timestep
125-
plot(x, score)
126-
legend(scales, title="Scale [km]")
127-
xlabel("Lead time [min]")
128-
ylabel("FSS ( > 1.0 mm/h ) ")
129-
title("Fractions skill score")
132+
plt.plot(x, score)
133+
plt.legend(scales, title="Scale [km]")
134+
plt.xlabel("Lead time [min]")
135+
plt.ylabel("FSS ( > 1.0 mm/h ) ")
136+
plt.title("Fractions skill score")
137+
plt.show()
130138

131139
# sphinx_gallery_thumbnail_number = 3

0 commit comments

Comments
 (0)