Skip to content

Commit 2eaed83

Browse files
authored
Rename MRMS importer (#154)
* Rename import_mrms to import_mrms_grib * Sort importers in alphabetical order * Update interfaces * Update tests for interfaces Co-authored-by: Daniele Nerini
1 parent bf7897f commit 2eaed83

File tree

5 files changed

+77
-51
lines changed

5 files changed

+77
-51
lines changed

pysteps/io/importers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@
6969
.. autosummary::
7070
:toctree: ../generated/
7171
72-
import_mrms
7372
import_bom_rf3
7473
import_fmi_geotiff
7574
import_fmi_pgm
7675
import_knmi_hdf5
7776
import_mch_gif
7877
import_mch_hdf5
7978
import_mch_metranet
79+
import_mrms_grib
8080
import_opera_hdf5
8181
import_saf_crri
8282
"""
@@ -145,7 +145,8 @@
145145

146146

147147
def _check_coords_range(selected_range, coordinate, full_range):
148-
"""Check that the coordinates range arguments follow the expected pattern in the **import_mrms** function."""
148+
"""Check that the coordinates range arguments follow the expected pattern in
149+
the **import_mrms_grib** function."""
149150

150151
if selected_range is None:
151152
return sorted(full_range)
@@ -227,7 +228,7 @@ def _get_threshold_value(precip):
227228

228229

229230
@postprocess_import(dtype='float32')
230-
def import_mrms(filename, extent=None, window_size=4, **kwargs):
231+
def import_mrms_grib(filename, extent=None, window_size=4, **kwargs):
231232
"""
232233
Importer for NSSL's Multi-Radar/Multi-Sensor System
233234
([MRMS](https://www.nssl.noaa.gov/projects/mrms/)) rainrate product

pysteps/io/interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from pysteps.io import importers, exporters
1616

1717
_importer_methods = dict(
18-
mrms=importers.import_mrms,
1918
bom_rf3=importers.import_bom_rf3,
2019
fmi_geotiff=importers.import_fmi_geotiff,
2120
fmi_pgm=importers.import_fmi_pgm,
2221
mch_gif=importers.import_mch_gif,
2322
mch_hdf5=importers.import_mch_hdf5,
2423
mch_metranet=importers.import_mch_metranet,
24+
mrms_grib=importers.import_mrms_grib,
2525
opera_hdf5=importers.import_opera_hdf5,
2626
knmi_hdf5=importers.import_knmi_hdf5,
2727
saf_crri=importers.import_saf_crri
@@ -73,6 +73,8 @@ def get_method(name, method_type):
7373
| mch_metranet | metranet files in the MeteoSwiss (MCH) archive |
7474
| | containing precipitation composites. |
7575
+--------------+------------------------------------------------------+
76+
| mrms_grib | Grib2 files used by the NSSL's MRMS product |
77+
+--------------+------------------------------------------------------+
7678
| opera_hdf5 | ODIM HDF5 file format used by Eumetnet/OPERA. |
7779
+--------------+------------------------------------------------------+
7880
| saf_crri | NetCDF SAF CRRI files |

pysteps/pystepsrc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
"colorscale": "pysteps"
1414
},
1515
"data_sources": {
16-
"mrms": {
17-
"root_path": "./mrms",
18-
"path_fmt": "%Y/%m/%d",
19-
"fn_pattern": "PrecipRate_00.00_%Y%m%d-%H%M%S",
20-
"fn_ext": "grib2",
21-
"importer": "mrms",
22-
"timestep": 2,
23-
"importer_kwargs": {}
24-
},
2516
"bom": {
2617
"root_path": "./radar/bom",
2718
"path_fmt": "prcp-cscn/2/%Y/%m/%d",
@@ -57,6 +48,15 @@
5748
"accutime": 5
5849
}
5950
},
51+
"mrms": {
52+
"root_path": "./mrms",
53+
"path_fmt": "%Y/%m/%d",
54+
"fn_pattern": "PrecipRate_00.00_%Y%m%d-%H%M%S",
55+
"fn_ext": "grib2",
56+
"importer": "mrms_grib",
57+
"timestep": 2,
58+
"importer_kwargs": {}
59+
},
6060
"opera": {
6161
"root_path": "./radar/OPERA",
6262
"path_fmt": "%Y%m%d",

pysteps/tests/test_interfaces.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,46 @@ def test_io_interface():
7878
from pysteps.io import import_bom_rf3
7979
from pysteps.io import import_fmi_geotiff
8080
from pysteps.io import import_fmi_pgm
81+
from pysteps.io import import_knmi_hdf5
8182
from pysteps.io import import_mch_gif
8283
from pysteps.io import import_mch_hdf5
8384
from pysteps.io import import_mch_metranet
85+
from pysteps.io import import_mrms_grib
8486
from pysteps.io import import_opera_hdf5
87+
from pysteps.io import import_saf_crri
88+
89+
from pysteps.io import initialize_forecast_exporter_geotiff
90+
from pysteps.io import initialize_forecast_exporter_kineros
8591
from pysteps.io import initialize_forecast_exporter_netcdf
8692

8793
# Test importers
8894
valid_names_func_pair = [('bom_rf3', import_bom_rf3),
8995
('fmi_geotiff', import_fmi_geotiff),
9096
('fmi_pgm', import_fmi_pgm),
97+
('knmi_hdf5', import_knmi_hdf5),
9198
('mch_gif', import_mch_gif),
9299
('mch_hdf5', import_mch_hdf5),
93100
('mch_metranet', import_mch_metranet),
101+
('mrms_grib', import_mrms_grib),
94102
('opera_hdf5', import_opera_hdf5),
95-
('mch_gif', import_mch_gif),
96-
('mch_gif', import_mch_gif),
97-
('mch_gif', import_mch_gif), ]
103+
('saf_crri', import_saf_crri),
104+
]
98105

99106
def method_getter(name):
100107
return pysteps.io.interface.get_method(name, 'importer')
101108

102-
invalid_names = ['opera', 'mch', 'fmi']
109+
invalid_names = ['bom', 'fmi', 'knmi', 'mch', 'mrms', 'opera', 'saf']
103110
_generic_interface_test(method_getter, valid_names_func_pair, invalid_names)
104111

105112
# Test exporters
106113
def method_getter(name):
107114
return pysteps.io.interface.get_method(name, 'exporter')
108115

109-
valid_names_func_pair = [('netcdf', initialize_forecast_exporter_netcdf)]
116+
valid_names_func_pair = [
117+
('geotiff', initialize_forecast_exporter_geotiff),
118+
('kineros', initialize_forecast_exporter_kineros),
119+
('netcdf', initialize_forecast_exporter_netcdf),
120+
]
110121
invalid_names = ['hdf']
111122

112123
_generic_interface_test(method_getter, valid_names_func_pair, invalid_names)
@@ -124,18 +135,24 @@ def method_getter(name):
124135
def test_motion_interface():
125136
"""Test the motion module interface."""
126137

138+
from pysteps.motion.constant import constant
127139
from pysteps.motion.darts import DARTS
128140
from pysteps.motion.lucaskanade import dense_lucaskanade
141+
from pysteps.motion.proesmans import proesmans
129142
from pysteps.motion.vet import vet
130143

131144
method_getter = pysteps.motion.interface.get_method
132145

133-
valid_names_func_pair = [('lk', dense_lucaskanade),
146+
valid_names_func_pair = [
147+
('constant', constant),
148+
('darts', DARTS),
149+
('lk', dense_lucaskanade),
134150
('lucaskanade', dense_lucaskanade),
151+
('proesmans', proesmans),
135152
('vet', vet),
136-
('DARTS', DARTS)]
153+
]
137154

138-
invalid_names = ['dart', 'pyvet', 'no_method']
155+
invalid_names = ['dart', 'pyvet', 'lukascanade', 'lucas-kanade', 'no_method']
139156

140157
_generic_interface_test(method_getter, valid_names_func_pair, invalid_names)
141158

@@ -174,22 +191,28 @@ def test_noise_interface():
174191
generate_noise_2d_ssft_filter)),
175192
('bps', (initialize_bps, generate_bps))]
176193

177-
invalid_names = ['nest', 'sft']
194+
invalid_names = ['nest', 'sft', 'ssfft']
178195

179196
_generic_interface_test(method_getter, valid_names_func_pair, invalid_names)
180197

181198

182199
def test_nowcasts_interface():
183200
"""Test the nowcasts module interface."""
184201

185-
from pysteps.nowcasts import steps
186-
from pysteps.nowcasts import extrapolation
202+
from pysteps.nowcasts import anvil, sprog, steps, sseps, extrapolation
187203
method_getter = pysteps.nowcasts.interface.get_method
188204

189-
valid_names_func_pair = [('extrapolation', extrapolation.forecast),
190-
('steps', steps.forecast)]
205+
valid_names_func_pair = [
206+
('anvil', anvil.forecast),
207+
('extrapolation', extrapolation.forecast),
208+
('lagrangian', extrapolation.forecast),
209+
('sprog', sprog.forecast),
210+
('sseps', sseps.forecast),
211+
('steps', steps.forecast),
212+
]
213+
191214

192-
invalid_names = ['extrap', 'step']
215+
invalid_names = ['extrap', 'step', 's-prog', 'pysteps']
193216
_generic_interface_test(method_getter, valid_names_func_pair, invalid_names)
194217

195218
# Test eulerian persistence method

pysteps/tests/test_io_mrms.py renamed to pysteps/tests/test_io_mrms_grib.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
pytest.importorskip('pygrib')
1111

1212

13-
def test_io_import_mrms():
13+
def test_io_import_mrms_grib():
1414
"""Test the importer for NSSL data."""
1515

1616
root_path = pysteps.rcparams.data_sources["mrms"]["root_path"]
1717

1818
filename = os.path.join(root_path, "2019/06/10/", "PrecipRate_00.00_20190610-000000.grib2")
1919

20-
precip_full, _, metadata = pysteps.io.import_mrms(filename,
21-
fillna=0,
22-
window_size=1)
20+
precip_full, _, metadata = pysteps.io.import_mrms_grib(filename,
21+
fillna=0,
22+
window_size=1)
2323
assert precip_full.shape == (3500, 7000)
2424
assert precip_full.dtype == 'single'
2525

@@ -38,46 +38,46 @@ def test_io_import_mrms():
3838
# The full longitude range is (230.005, 299.995)
3939

4040
# Test that if the bounding box is larger than the domain, all the points are returned.
41-
precip_full2 = pysteps.io.import_mrms(filename,
42-
fillna=0,
43-
extent=(220, 300, 20, 55),
44-
window_size=1)[0]
41+
precip_full2 = pysteps.io.import_mrms_grib(filename,
42+
fillna=0,
43+
extent=(220, 300, 20, 55),
44+
window_size=1)[0]
4545
assert precip_full2.shape == (3500, 7000)
4646

4747
assert_array_almost_equal(precip_full, precip_full2)
4848

4949
del precip_full2
5050

5151
# Test that a portion of the domain is returned correctly
52-
precip_clipped = pysteps.io.import_mrms(filename,
53-
fillna=0,
54-
extent=(250, 260, 30, 35),
55-
window_size=1)[0]
52+
precip_clipped = pysteps.io.import_mrms_grib(filename,
53+
fillna=0,
54+
extent=(250, 260, 30, 35),
55+
window_size=1)[0]
5656

5757
assert precip_clipped.shape == (500, 1000)
5858
assert_array_almost_equal(precip_clipped, precip_full[2000:2500, 2000:3000])
5959
del precip_clipped
6060

61-
precip_single = pysteps.io.import_mrms(filename, dtype="double", fillna=0)[0]
61+
precip_single = pysteps.io.import_mrms_grib(filename, dtype="double", fillna=0)[0]
6262
assert precip_single.dtype == 'double'
6363
del precip_single
6464

65-
precip_single = pysteps.io.import_mrms(filename,
66-
dtype="single",
67-
fillna=0)[0]
65+
precip_single = pysteps.io.import_mrms_grib(filename,
66+
dtype="single",
67+
fillna=0)[0]
6868
assert precip_single.dtype == 'single'
6969
del precip_single
7070

71-
precip_donwscaled = pysteps.io.import_mrms(filename,
72-
dtype="single",
73-
fillna=0,
74-
window_size=2)[0]
71+
precip_donwscaled = pysteps.io.import_mrms_grib(filename,
72+
dtype="single",
73+
fillna=0,
74+
window_size=2)[0]
7575
assert precip_donwscaled.shape == (3500 / 2, 7000 / 2)
7676

77-
precip_donwscaled, _, metadata = pysteps.io.import_mrms(filename,
78-
dtype="single",
79-
fillna=0,
80-
window_size=3)
77+
precip_donwscaled, _, metadata = pysteps.io.import_mrms_grib(filename,
78+
dtype="single",
79+
fillna=0,
80+
window_size=3)
8181
expected_metadata = dict(
8282
xpixelsize=0.03,
8383
ypixelsize=0.03,

0 commit comments

Comments
 (0)