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 28, 2021
1 parent 2c3c613 commit 6578c88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pysteps/io/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,24 +393,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(
institution="NOAA National Severe Storms Laboratory",
xpixelsize=grib_msg["iDirectionIncrementInDegrees"] * window_size[0],
ypixelsize=grib_msg["jDirectionIncrementInDegrees"] * window_size[1],
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
6 changes: 6 additions & 0 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
import xarray as xr
from numpy.testing import assert_array_almost_equal
Expand Down Expand Up @@ -53,6 +54,11 @@ def test_io_import_mrms_grib():
assert metadata[key] == expected_array_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

0 comments on commit 6578c88

Please sign in to comment.