Skip to content

Commit c3cb993

Browse files
authored
Mrms bounding box (#222)
* Fix bounding box coordinates * Add missing metadata
1 parent c8ebc2d commit c3cb993

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

pysteps/io/importers.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,22 +392,27 @@ def import_mrms_grib(filename, extent=None, window_size=4, **kwargs):
392392
pr = pyproj.Proj(proj_params)
393393
proj_def = " ".join([f"+{key}={value} " for key, value in proj_params.items()])
394394

395+
xsize = grib_msg["iDirectionIncrementInDegrees"] * window_size[0]
396+
ysize = grib_msg["jDirectionIncrementInDegrees"] * window_size[1]
397+
395398
x1, y1 = pr(ul_lon, lr_lat)
396399
x2, y2 = pr(lr_lon, ul_lat)
397400

398401
metadata = dict(
399-
xpixelsize=grib_msg["iDirectionIncrementInDegrees"] * window_size[0],
400-
ypixelsize=grib_msg["jDirectionIncrementInDegrees"] * window_size[1],
402+
institution="NOAA National Severe Storms Laboratory",
403+
xpixelsize=xsize,
404+
ypixelsize=ysize,
401405
unit="mm/h",
406+
accutime=2.0,
402407
transform=None,
403408
zerovalue=0,
404409
projection=proj_def.strip(),
405410
yorigin="upper",
406411
threshold=_get_threshold_value(precip),
407-
x1=x1,
408-
x2=x2,
409-
y1=y1,
410-
y2=y2,
412+
x1=x1 - xsize / 2,
413+
x2=x2 + xsize / 2,
414+
y1=y1 - ysize / 2,
415+
y2=y2 + ysize / 2,
411416
cartesian_unit="degrees",
412417
)
413418

pysteps/tests/test_io_mrms_grib.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44

5+
import numpy as np
56
import pytest
67
from numpy.testing import assert_array_almost_equal
78

@@ -34,10 +35,10 @@ def test_io_import_mrms_grib():
3435
"projection": "+proj=longlat +ellps=IAU76",
3536
"yorigin": "upper",
3637
"threshold": 0.1,
37-
"x1": -129.99499999999998,
38-
"x2": -60.00500199999991,
39-
"y1": 20.005001,
40-
"y2": 54.995000000000005,
38+
"x1": -129.99999999999997,
39+
"x2": -60.00000199999991,
40+
"y1": 20.000001,
41+
"y2": 55.00000000000001,
4142
"cartesian_unit": "degrees",
4243
}
4344

@@ -47,6 +48,11 @@ def test_io_import_mrms_grib():
4748
else:
4849
assert metadata[key] == expected_metadata[key]
4950

51+
x = np.arange(metadata["x1"], metadata["x2"], metadata["xpixelsize"])
52+
y = np.arange(metadata["y1"], metadata["y2"], metadata["ypixelsize"])
53+
assert y.size == precip_full.shape[0]
54+
assert x.size == precip_full.shape[1]
55+
5056
# The full latitude range is (20.005, 54.995)
5157
# The full longitude range is (230.005, 299.995)
5258

@@ -89,10 +95,10 @@ def test_io_import_mrms_grib():
8995
expected_metadata.update(
9096
xpixelsize=0.03,
9197
ypixelsize=0.03,
92-
x1=-129.98500000028577,
93-
x2=-60.02500199942843,
94-
y1=20.03500099914261,
95-
y2=54.985000000285794,
98+
x1=-130.00000000028575,
99+
x2=-60.01000199942843,
100+
y1=20.02000099914261,
101+
y2=55.000000000285794,
96102
)
97103

98104
# Remove the threshold keyword from the test when the window_size>1 is used.

0 commit comments

Comments
 (0)