Skip to content

Commit

Permalink
Update tests and add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbieker committed Dec 15, 2023
1 parent 3fa5187 commit c99dcb4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
47 changes: 18 additions & 29 deletions src/nwp_consumer/internal/inputs/cmc/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestClient(unittest.TestCase):
def test_mapTemp(self) -> None:
# Test with global file
testFilePath: pathlib.Path = (
pathlib.Path(__file__).parent / "test_icon_global_001_CLCL.grib2"
pathlib.Path(__file__).parent / "CMC_glb_VGRD_ISBL_200_latlon.15x.15_2023080900_P027.grib2"
)
out = testClient.mapTemp(p=testFilePath)

Expand All @@ -28,11 +28,11 @@ def test_mapTemp(self) -> None:
("variable", "init_time", "step", "values"),
)
# Check that the parameter is renamed
self.assertEqual(out["variable"].values[0], "ccl")
self.assertEqual(out["variable"].values[0], "v")

# Test with europe file
testFilePath: pathlib.Path = (
pathlib.Path(__file__).parent / "test_icon_europe_001_CLCL.grib2"
pathlib.Path(__file__).parent / "CMC_glb_CAPE_SFC_0_latlon.15x.15_2023080900_P027.grib2"
)
out = testClient.mapTemp(p=testFilePath)

Expand All @@ -45,64 +45,53 @@ def test_mapTemp(self) -> None:
("variable", "init_time", "step", "latitude", "longitude"),
)
# Check that the parameter is renamed
self.assertEqual(out["variable"].values[0], "ccl")
self.assertEqual(out["variable"].values[0], "cape")


class TestParseIconFilename(unittest.TestCase):
baseurl = "https://opendata.dwd.de/weather/nwp/icon/grib"
class TestParseCMCFilename(unittest.TestCase):
baseurl = "https://dd.weather.gc.ca/model_gem_global/15km/grib2/lat_lon/"

def test_parsesSingleLevel(self) -> None:
filename: str = "icon_global_icosahedral_single-level_2020090100_000_T_HUM.grib2.bz2"
filename: str = "CMC_glb_CAPE_SFC_0_latlon.15x.15_2023080900_P027.grib2"

out: CMCFileInfo | None = _parseCMCFilename(
name=filename,
baseurl=self.baseurl,
)
self.assertIsNotNone(out)
self.assertEqual(out.filename(), filename.removesuffix(".bz2"))
self.assertEqual(out.it(), dt.datetime(2020, 9, 1, 0, tzinfo=dt.timezone.utc))
self.assertEqual(out.filename(), filename)
self.assertEqual(out.it(), dt.datetime(2023, 8, 9, 0, tzinfo=dt.timezone.utc))

def test_parsesTimeInvariant(self) -> None:
filename: str = "icon_global_icosahedral_time-invariant_2020090100_CLAT.grib2.bz2"
def test_parsesHeightAboveGround(self) -> None:
filename: str = "CMC_glb_TMP_TGL_2_latlon.15x.15_2023080900_P027.grib2"

out: CMCFileInfo | None = _parseCMCFilename(
name=filename,
baseurl=self.baseurl,
match_tgl=True,
)
self.assertIsNotNone(out)
self.assertEqual(out.filename(), filename.removesuffix(".bz2"))
self.assertEqual(out.it(), dt.datetime(2020, 9, 1, 0, tzinfo=dt.timezone.utc))

def test_parsesModelLevel(self) -> None:
filename: str = "icon_global_icosahedral_model-level_2020090100_048_32_CLCL.grib2.bz2"

out: CMCFileInfo | None = _parseCMCFilename(
name=filename,
baseurl=self.baseurl,
match_ml=True,
)
self.assertIsNotNone(out)
self.assertEqual(out.filename(), filename.removesuffix(".bz2"))
self.assertEqual(out.it(), dt.datetime(2020, 9, 1, 0, tzinfo=dt.timezone.utc))
self.assertEqual(out.filename(), filename)
self.assertEqual(out.it(), dt.datetime(2023, 8, 9, 0, tzinfo=dt.timezone.utc))

out: CMCFileInfo | None = _parseCMCFilename(
name=filename,
baseurl=self.baseurl,
match_ml=False,
match_tgl=False,
)
self.assertIsNone(out)

def test_parsesPressureLevel(self) -> None:
filename: str = "icon_global_icosahedral_pressure-level_2020090100_048_1000_T.grib2.bz2"
filename: str = "CMC_glb_VGRD_ISBL_200_latlon.15x.15_2023080900_P027.grib2"

out: CMCFileInfo | None = _parseCMCFilename(
name=filename,
baseurl=self.baseurl,
match_pl=True,
)
self.assertIsNotNone(out)
self.assertEqual(out.filename(), filename.removesuffix(".bz2"))
self.assertEqual(out.it(), dt.datetime(2020, 9, 1, 0, tzinfo=dt.timezone.utc))
self.assertEqual(out.filename(), filename)
self.assertEqual(out.it(), dt.datetime(2023, 8, 9, 0, tzinfo=dt.timezone.utc))

out: CMCFileInfo | None = _parseCMCFilename(
name=filename,
Expand Down

0 comments on commit c99dcb4

Please sign in to comment.