Skip to content

Commit

Permalink
support 2001-2011 reanalysis MRMS
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Nov 10, 2021
1 parent edf8f59 commit 280c239
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/pyiem/mrms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def get_url(center, valid, product):
f"https://mtarchive.geol.iastate.edu/{valid:%Y/%m/%d}"
f"/mrms/ncep/{product}/{fn}"
)
if 2000 < valid.year < 2012 and product == "PrecipRate":
uri = (
f"https://mtarchive.geol.iastate.edu/{valid:%Y/%m/%d}"
f"/mrms/reanalysis/{product}/{fn}"
)
else:
uri = f"https://mrms{center}.ncep.noaa.gov/data/2D/{product}/MRMS_{fn}"
return uri
Expand Down
16 changes: 12 additions & 4 deletions tests/test_mrms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
CENTERS = ["mtarchive", "", "bldr", "cprk"]


def test_2001_mrms():
"""Test that we can fetch older MRMS data in a bit different location."""
# NB archive starts at 12z on the 1rst day of 2001
fn = mrms.fetch("PrecipRate", utc(2001, 1, 2), tmpdir="/tmp")
assert fn is not None


def test_nofailback(requests_mock):
"""Test that code bails on old date."""
valid = utc() - datetime.timedelta(days=20)
Expand Down Expand Up @@ -50,8 +57,8 @@ def test_exception(requests_mock):
def test_existing_file():
"""Test that we return once we already have the file on disk."""
valid = utc()
fn = "%s_00.00_%s00.grib2.gz" % (PRODUCT, valid.strftime("%Y%m%d-%H%M"))
with open(f"/tmp/{fn}", "w") as fh:
fn = f"{PRODUCT}_00.00_{valid:%Y%m%d-%H%M}00.grib2.gz"
with open(f"/tmp/{fn}", "w", encoding="utf8") as fh:
fh.write("Hello")
fn = mrms.fetch(PRODUCT, valid, tmpdir="/tmp")
assert fn is not None
Expand Down Expand Up @@ -97,8 +104,9 @@ def test_write_worldfile():

def test_reader():
"""Can we read the legacy file"""
fn = ("%s/../data/product_examples/1hrad.20130920.190000.gz") % (
os.path.dirname(__file__),
fn = (
f"{os.path.dirname(__file__)}/../data/product_examples/"
"1hrad.20130920.190000.gz"
)
metadata, _ = mrms.reader(fn)
assert abs(metadata["ul_lat"] - 54.99) < 0.01

0 comments on commit 280c239

Please sign in to comment.