Skip to content

Commit

Permalink
Mrms bounding box (#222)
Browse files Browse the repository at this point in the history
* Fix bounding box coordinates

* Add missing metadata
  • Loading branch information
dnerini committed Jul 27, 2021
1 parent c8ebc2d commit c3cb993
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
17 changes: 11 additions & 6 deletions pysteps/io/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,27 @@ def import_mrms_grib(filename, extent=None, window_size=4, **kwargs):
pr = pyproj.Proj(proj_params)
proj_def = " ".join([f"+{key}={value} " for key, value in proj_params.items()])

xsize = grib_msg["iDirectionIncrementInDegrees"] * window_size[0]
ysize = grib_msg["jDirectionIncrementInDegrees"] * window_size[1]

x1, y1 = pr(ul_lon, lr_lat)
x2, y2 = pr(lr_lon, ul_lat)

metadata = dict(
xpixelsize=grib_msg["iDirectionIncrementInDegrees"] * window_size[0],
ypixelsize=grib_msg["jDirectionIncrementInDegrees"] * window_size[1],
institution="NOAA National Severe Storms Laboratory",
xpixelsize=xsize,
ypixelsize=ysize,
unit="mm/h",
accutime=2.0,
transform=None,
zerovalue=0,
projection=proj_def.strip(),
yorigin="upper",
threshold=_get_threshold_value(precip),
x1=x1,
x2=x2,
y1=y1,
y2=y2,
x1=x1 - xsize / 2,
x2=x2 + xsize / 2,
y1=y1 - ysize / 2,
y2=y2 + ysize / 2,
cartesian_unit="degrees",
)

Expand Down
22 changes: 14 additions & 8 deletions pysteps/tests/test_io_mrms_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os

import numpy as np
import pytest
from numpy.testing import assert_array_almost_equal

Expand Down Expand Up @@ -34,10 +35,10 @@ def test_io_import_mrms_grib():
"projection": "+proj=longlat +ellps=IAU76",
"yorigin": "upper",
"threshold": 0.1,
"x1": -129.99499999999998,
"x2": -60.00500199999991,
"y1": 20.005001,
"y2": 54.995000000000005,
"x1": -129.99999999999997,
"x2": -60.00000199999991,
"y1": 20.000001,
"y2": 55.00000000000001,
"cartesian_unit": "degrees",
}

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

x = np.arange(metadata["x1"], metadata["x2"], metadata["xpixelsize"])
y = np.arange(metadata["y1"], metadata["y2"], metadata["ypixelsize"])
assert y.size == precip_full.shape[0]
assert x.size == precip_full.shape[1]

# The full latitude range is (20.005, 54.995)
# The full longitude range is (230.005, 299.995)

Expand Down Expand Up @@ -89,10 +95,10 @@ def test_io_import_mrms_grib():
expected_metadata.update(
xpixelsize=0.03,
ypixelsize=0.03,
x1=-129.98500000028577,
x2=-60.02500199942843,
y1=20.03500099914261,
y2=54.985000000285794,
x1=-130.00000000028575,
x2=-60.01000199942843,
y1=20.02000099914261,
y2=55.000000000285794,
)

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

0 comments on commit c3cb993

Please sign in to comment.