Skip to content

Commit

Permalink
added crop test
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbuntemeyer committed Jul 4, 2024
1 parent fef810c commit 57ddc63
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_cmor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 57ddc63

Please sign in to comment.