Skip to content

Commit e734c17

Browse files
authored
Remove deprecated plotting options (#266)
* Mock pyplot.show during tests * Deprecate keyword arguments * Test with windows-2019 * Use micromamba 0.20
1 parent 72f3bf5 commit e734c17

File tree

4 files changed

+63
-78
lines changed

4 files changed

+63
-78
lines changed

.github/workflows/test_pysteps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- name: Install mamba and create environment
3333
uses: mamba-org/provision-with-micromamba@main
3434
with:
35+
micromamba-version: 0.20.0
3536
environment-file: ci/ci_test_env.yml
3637
environment-name: test_environment
3738
extra-specs: python=${{ matrix.python-version }}

pysteps/tests/test_plt_animate.py

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,79 @@
44

55
import numpy as np
66
import pytest
7+
from unittest.mock import patch
78

89
from pysteps.tests.helpers import get_precipitation_fields
910
from pysteps.visualization.animations import animate
1011

1112

12-
def test_animate(tmp_path):
13+
PRECIP, METADATA = get_precipitation_fields(
14+
num_prev_files=2,
15+
num_next_files=0,
16+
return_raw=True,
17+
metadata=True,
18+
upscale=2000,
19+
)
1320

14-
# test data
15-
precip, metadata = get_precipitation_fields(
16-
num_prev_files=2,
17-
num_next_files=0,
18-
return_raw=True,
19-
metadata=True,
20-
upscale=2000,
21-
)
21+
VALID_ARGS = (
22+
([PRECIP], {}),
23+
([PRECIP], {"title": "title"}),
24+
([PRECIP], {"timestamps_obs": METADATA["timestamps"]}),
25+
([PRECIP], {"geodata": METADATA, "map_kwargs": {"plot_map": None}}),
26+
([PRECIP], {"motion_field": np.ones((2, *PRECIP.shape[1:]))}),
27+
(
28+
[PRECIP],
29+
{"precip_kwargs": {"units": "mm/h", "colorbar": True, "colorscale": "pysteps"}},
30+
),
31+
([PRECIP, PRECIP], {}),
32+
([PRECIP, PRECIP], {"title": "title"}),
33+
([PRECIP, PRECIP], {"timestamps_obs": METADATA["timestamps"]}),
34+
([PRECIP, PRECIP], {"timestamps_obs": METADATA["timestamps"], "timestep_min": 5}),
35+
([PRECIP, PRECIP], {"ptype": "prob", "prob_thr": 1}),
36+
([PRECIP, PRECIP], {"ptype": "mean"}),
37+
([PRECIP, np.stack((PRECIP, PRECIP))], {"ptype": "ensemble"}),
38+
)
2239

23-
# obs only
24-
animate(precip)
25-
animate(precip, title="title")
26-
animate(precip, timestamps_obs=metadata["timestamps"])
27-
animate(precip, geodata=metadata, map_kwargs={"plot_map": None})
28-
with pytest.raises(ValueError):
29-
animate(precip, timestamps_obs=metadata["timestamps"][:2])
30-
animate(precip, motion_field=np.ones((2, *precip.shape[1:])))
31-
with pytest.raises(ValueError):
32-
animate(precip, motion_plot="test")
3340

34-
# with forecast
35-
animate(precip, precip)
36-
animate(precip, precip, title="title")
37-
animate(precip, precip, timestamps_obs=metadata["timestamps"])
38-
animate(precip, precip, timestamps_obs=metadata["timestamps"], timestep_min=5)
41+
@pytest.mark.parametrize(["anim_args", "anim_kwargs"], VALID_ARGS)
42+
def test_animate(anim_args, anim_kwargs):
43+
with patch("matplotlib.pyplot.show"):
44+
animate(*anim_args, **anim_kwargs)
45+
46+
47+
VALUEERROR_ARGS = (
48+
([PRECIP], {"timestamps_obs": METADATA["timestamps"][:2]}),
49+
([PRECIP], {"motion_plot": "test"}),
50+
([PRECIP, PRECIP], {"ptype": "prob"}),
51+
)
52+
53+
54+
@pytest.mark.parametrize(["anim_args", "anim_kwargs"], VALUEERROR_ARGS)
55+
def test_animate_valueerrors(anim_args, anim_kwargs):
3956
with pytest.raises(ValueError):
40-
animate(precip, precip, ptype="prob")
41-
animate(precip, precip, ptype="prob", prob_thr=1)
42-
animate(precip, precip, ptype="mean")
43-
animate(precip, np.stack((precip, precip)), ptype="ensemble")
57+
animate(*anim_args, **anim_kwargs)
58+
59+
60+
TYPEERROR_ARGS = (
61+
([PRECIP], {"timestamps": METADATA["timestamps"]}),
62+
([PRECIP], {"plotanimation": True}),
63+
([PRECIP], {"units": "mm/h"}),
64+
([PRECIP], {"colorbar": True}),
65+
([PRECIP], {"colorscale": "pysteps"}),
66+
([PRECIP, PRECIP], {"type": "ensemble"}),
67+
)
68+
69+
70+
@pytest.mark.parametrize(["anim_args", "anim_kwargs"], TYPEERROR_ARGS)
71+
def test_animate_typeerrors(anim_args, anim_kwargs):
72+
with pytest.raises(TypeError):
73+
animate(*anim_args, **anim_kwargs)
74+
4475

45-
# save frames
76+
def test_animate_save(tmp_path):
4677
animate(
47-
precip,
48-
np.stack((precip, precip)),
78+
PRECIP,
79+
np.stack((PRECIP, PRECIP)),
4980
display_animation=False,
5081
savefig=True,
5182
path_outputs=tmp_path,

pysteps/visualization/animations.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
import pysteps as st
1919

2020
PRECIP_VALID_TYPES = ("ensemble", "mean", "prob")
21-
PRECIP_DEPRECATED_ARGUMENTS = (
22-
"units",
23-
"colorbar",
24-
"colorscale",
25-
) # TODO: remove in version >= 1.6
2621
MOTION_VALID_METHODS = ("quiver", "streamplot")
2722

2823

@@ -47,7 +42,6 @@ def animate(
4742
precip_kwargs=None,
4843
motion_kwargs=None,
4944
map_kwargs=None,
50-
**kwargs,
5145
):
5246
"""
5347
Function to animate observations and forecasts in pysteps.
@@ -181,39 +175,6 @@ def animate(
181175
f"Supported: {str(PRECIP_VALID_TYPES)}"
182176
)
183177

184-
# TODO: remove in version >= 1.6
185-
if "type" in kwargs:
186-
warnings.warn(
187-
"The 'type' keyword will be deprecated in version 1.6. "
188-
"Use 'ptype' instead."
189-
)
190-
ptype = kwargs.get("type")
191-
192-
# TODO: remove in version >= 1.6
193-
if "timestamps" in kwargs:
194-
warnings.warn(
195-
"The 'timestamps' keyword will be deprecated in version 1.6. "
196-
"Use 'timestamps_obs' instead."
197-
)
198-
timestamps_obs = kwargs.get("timestamps")
199-
200-
# TODO: remove in version >= 1.6
201-
if "plotanimation" in kwargs:
202-
warnings.warn(
203-
"The 'plotanimation' keyword will be deprecated in version 1.6. "
204-
"Use 'display_animation' instead."
205-
)
206-
display_animation = kwargs.get("timestamps")
207-
208-
# TODO: remove in version >= 1.6
209-
for depr_key in PRECIP_DEPRECATED_ARGUMENTS:
210-
if depr_key in kwargs:
211-
warnings.warn(
212-
f"The {depr_key} argument will be deprecated in version 1.6. "
213-
"Add it to 'precip_kwargs' instead."
214-
)
215-
precip_kwargs[depr_key] = kwargs.get(depr_key)
216-
217178
if timestamps_obs is not None:
218179
if len(timestamps_obs) != precip_obs.shape[0]:
219180
raise ValueError(

pysteps/visualization/precipfields.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def plot_precip_field(
4343
axis="on",
4444
cax=None,
4545
map_kwargs=None,
46-
**kwargs,
4746
):
4847
"""
4948
Function to plot a precipitation intensity or probability field with a
@@ -131,13 +130,6 @@ def plot_precip_field(
131130
if map_kwargs is None:
132131
map_kwargs = {}
133132

134-
if "type" in kwargs:
135-
warnings.warn(
136-
"The 'type' keyword use to indicate the type of plot will be "
137-
"deprecated in version 1.6. Use 'ptype' instead."
138-
)
139-
ptype = kwargs.get("type")
140-
141133
if ptype not in PRECIP_VALID_TYPES:
142134
raise ValueError(
143135
f"Invalid precipitation type '{ptype}'."

0 commit comments

Comments
 (0)