From 57ddc63ff30375c7765632c00c2455aa8253bfd2 Mon Sep 17 00:00:00 2001 From: Lars Buntemeyer Date: Thu, 4 Jul 2024 13:55:04 +0200 Subject: [PATCH] added crop test --- tests/test_cmor.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_cmor.py b/tests/test_cmor.py index 02e015b..e8cb1dc 100644 --- a/tests/test_cmor.py +++ b/tests/test_cmor.py @@ -12,6 +12,7 @@ from cordex import cmor from cordex.cmor import utils from cordex.tables import cordex_cmor_table +from cordex.cmor.cmor import _crop_to_cordex_domain from . import requires_pint_xarray @@ -185,6 +186,24 @@ def test_month_bounds(): assert np.array_equal(mid, expect) +@pytest.mark.parametrize("domain_id", ["EUR-11", "SAM-44", "AFR-22"]) +def test_crop_to_domain(domain_id): + ds = cx.domain(domain_id) + + cropped = _crop_to_cordex_domain(ds, domain_id) + assert ds.equals(cropped) + # assert larger domain is correctly cropped + pad = ds.pad(rlon=(1, 1), rlat=(1, 1), mode="reflect", reflect_type="odd") + cropped = _crop_to_cordex_domain(pad, domain_id) + assert ds.equals(cropped) + + # check for tolerance + cropped = _crop_to_cordex_domain( + pad.reindex(rlon=pad.rlon * 1.00001, method="nearest"), domain_id + ).assign_coords(rlon=ds.rlon, rlat=ds.rlat) + assert ds.equals(cropped) + + def run_cmorizer(ds, out_name, domain_id, table_id, dataset_table=None, **kwargs): if dataset_table is None: dataset_table = cordex_cmor_table(f"{table_prefix}_remo_example")