Skip to content

Commit 6cd4b1d

Browse files
authored
Update smoke tests (#286)
* update smoke tests ... removed xfail for calendar fix * added fix for time_bnds in concat operator * added smoke test for regrid op with custom parameter * added smoke test for custom grid with workflow * handle custom grid parsing * lint * update comments
1 parent f880de1 commit 6cd4b1d

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

src/rook/utils/concat_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
}
2626

2727

28+
def drop_time_bnds(ds: xr.Dataset) -> xr.Dataset:
29+
"""
30+
Drop time_bnds variable.
31+
32+
Drop time_bnds to avoid xarray CF encoding failures
33+
with dask + datetime objects.
34+
"""
35+
if "time_bnds" in ds.variables:
36+
ds = ds.drop_vars("time_bnds")
37+
return ds
38+
39+
2840
def patched_normalise(collection):
2941
# TODO: this is a patched function of daops to fix the gregorian calendar issue
3042
norm_collection = collections.OrderedDict()
@@ -108,6 +120,8 @@ def _calculate(self):
108120
{dim: (dim, np.array(processed_ds[dim].values, dtype="int32"))}
109121
)
110122
processed_ds.coords[dim].attrs = {"standard_name": standard_name}
123+
# fix time_bnds issue
124+
processed_ds = drop_time_bnds(processed_ds)
111125
# optional: average
112126
if self.params.get("apply_average", False):
113127
processed_ds = average(processed_ds, dims=[dim])

src/rook/utils/regrid_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
from rook.utils.input_utils import parse_custom_grid
2+
3+
14
def run_regrid(args):
25
from daops.ops.regrid import regrid
36

47
args["apply_fixes"] = False
58

9+
# Handle custom grid parsing
10+
if args.get("grid") == "custom" and "custom_grid" in args:
11+
# parse the string into a tuple/list
12+
args["grid"] = parse_custom_grid(args.pop("custom_grid"))
13+
614
result = regrid(**args)
715

816
return result.file_uris

tests/smoke/test_smoke_checks.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@
126126
}
127127
)
128128

129+
WF_C3S_CMIP6_REGRID_CUSTOM = json.dumps(
130+
{
131+
"doc": "subset+regrid on cmip6 with custom grid",
132+
"inputs": {"ds": [C3S_CMIP6_MON_COLLECTION]},
133+
"outputs": {"output": "regrid/output"},
134+
"steps": {
135+
"subset": {
136+
"run": "subset",
137+
"in": {"collection": "inputs/ds", "time": "2016/2016"},
138+
},
139+
"regrid": {
140+
"run": "regrid",
141+
"in": {
142+
"collection": "subset/output",
143+
"method": "nearest_s2d",
144+
"grid": "custom",
145+
"custom_grid": "0.5",
146+
},
147+
},
148+
},
149+
}
150+
)
151+
129152
TC_ALL_DAYS = "day:01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31"
130153

131154
WF_C3S_CMIP6_360DAY_CALENDAR = json.dumps(
@@ -578,6 +601,21 @@ def test_smoke_execute_c3s_cmip6_regrid(wps):
578601
)
579602

580603

604+
def test_smoke_execute_c3s_cmip6_regrid_custom(wps):
605+
inputs = [
606+
("collection", C3S_CMIP6_MON_COLLECTION),
607+
("grid", "custom"),
608+
("custom_grid", "0.5"),
609+
("method", "nearest_s2d"),
610+
]
611+
urls = wps.execute("regrid", inputs)
612+
assert len(urls) == 1
613+
assert (
614+
"rlds_Amon_INM-CM5-0_ssp245_r1i1p1f1_gr_20150116-21001216_regrid-nearest_s2d-360x720_cells_grid.nc"
615+
in urls[0]
616+
)
617+
618+
581619
def test_smoke_execute_c3s_cmip5_orchestrate(wps):
582620
inputs = [
583621
("workflow", ComplexDataInput(WF_C3S_CMIP5)),
@@ -619,6 +657,18 @@ def test_smoke_execute_c3s_cmip6_regrid_orchestrate(wps):
619657
)
620658

621659

660+
def test_smoke_execute_c3s_cmip6_regrid_custom_orchestrate(wps):
661+
inputs = [
662+
("workflow", ComplexDataInput(WF_C3S_CMIP6_REGRID_CUSTOM)),
663+
]
664+
urls = wps.execute("orchestrate", inputs)
665+
assert len(urls) == 1
666+
assert (
667+
"rlds_Amon_INM-CM5-0_ssp245_r1i1p1f1_gr_20160116-20161216_regrid-nearest_s2d-360x720_cells_grid.nc"
668+
in urls[0]
669+
)
670+
671+
622672
def test_smoke_execute_c3s_cmip6_360day_calendar_orchestrate(wps):
623673
inputs = [
624674
("workflow", ComplexDataInput(WF_C3S_CMIP6_360DAY_CALENDAR)),
@@ -664,7 +714,6 @@ def test_smoke_execute_c3s_cordex_orchestrate(wps):
664714
)
665715

666716

667-
@pytest.mark.xfail(reason="issue with datatime and xarray+dask")
668717
def test_smoke_execute_c3s_cmip6_decadal_orchestrate(wps):
669718
inputs = [
670719
("workflow", ComplexDataInput(WF_C3S_CMIP6_DECADAL)),
@@ -675,7 +724,6 @@ def test_smoke_execute_c3s_cmip6_decadal_orchestrate(wps):
675724
assert "19951116-19951216.nc" in urls[0]
676725

677726

678-
@pytest.mark.xfail(reason="calendar fix does not work with latest xarray")
679727
def test_smoke_execute_c3s_cmip6_decadal_fix_calendar_orchestrate(wps):
680728
inputs = [
681729
("workflow", ComplexDataInput(WF_C3S_CMIP6_DECADAL_2)),

0 commit comments

Comments
 (0)