From 280c239268e8a8d8097d7ada02b04584d05acd40 Mon Sep 17 00:00:00 2001 From: akrherz Date: Wed, 10 Nov 2021 08:34:32 -0600 Subject: [PATCH] support 2001-2011 reanalysis MRMS refs dailyerosion/dep#82 --- src/pyiem/mrms.py | 5 +++++ tests/test_mrms.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/pyiem/mrms.py b/src/pyiem/mrms.py index 1aeb0eb23..ac8025cf8 100644 --- a/src/pyiem/mrms.py +++ b/src/pyiem/mrms.py @@ -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 diff --git a/tests/test_mrms.py b/tests/test_mrms.py index 26aaf4aa9..80e31769d 100644 --- a/tests/test_mrms.py +++ b/tests/test_mrms.py @@ -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) @@ -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 @@ -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