Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions notebooks/quick_start.ipynb

This file was deleted.

34 changes: 10 additions & 24 deletions tests/test_20_open_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def test_open_dataset(tmp_path: Path, index_node: str, download: bool) -> None:
'"pr_Amon_EC-Earth3-CC_ssp245_r1i1p1f1_gr_202001-202012.nc"',
'"pr_Amon_EC-Earth3-CC_ssp585_r1i1p1f1_gr_201901-201912.nc"',
'"pr_Amon_EC-Earth3-CC_ssp585_r1i1p1f1_gr_202001-202012.nc"',
'"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp245.r1i1p1f1.fx.areacella.gr.v20210113.areacella_fx_EC-Earth3-CC_ssp245_r1i1p1f1_gr.nc"',
'"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp585.r1i1p1f1.fx.areacella.gr.v20210113.areacella_fx_EC-Earth3-CC_ssp585_r1i1p1f1_gr.nc"',
]
}
ds = xr.open_dataset(
Expand All @@ -41,6 +43,7 @@ def test_open_dataset(tmp_path: Path, index_node: str, download: bool) -> None:

# Coords
assert set(ds.coords) == {
"areacella",
"experiment_id",
"height",
"lat",
Expand All @@ -50,12 +53,11 @@ def test_open_dataset(tmp_path: Path, index_node: str, download: bool) -> None:
"time",
"time_bnds",
}
assert set(ds[["lat_bnds", "lon_bnds", "time_bnds"]].dims) == {
"bnds",
"lat",
"lon",
"time",
}
assert all(
"experiment_id" not in coord.dims
for name, coord in ds.coords.items()
if name != "experiment_id"
)

# Data vars
assert set(ds.data_vars) == {"tas", "pr"}
Expand All @@ -64,24 +66,8 @@ def test_open_dataset(tmp_path: Path, index_node: str, download: bool) -> None:
assert ds.dataset_ids == [
"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp245.r1i1p1f1.Amon.pr.gr.v20210113",
"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp245.r1i1p1f1.Amon.tas.gr.v20210113",
"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp245.r1i1p1f1.fx.areacella.gr.v20210113",
"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp585.r1i1p1f1.Amon.pr.gr.v20210113",
"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp585.r1i1p1f1.Amon.tas.gr.v20210113",
"CMIP6.ScenarioMIP.EC-Earth-Consortium.EC-Earth3-CC.ssp585.r1i1p1f1.fx.areacella.gr.v20210113",
]


def test_open_dataset_check_dims(tmp_path: Path) -> None:
esgpull_path = tmp_path / "esgpull"
selection = {
"query": [
'"tos_Amon_EC-Earth3-CC_ssp245_r1i1p1f1_gr_201501-201512.nc"',
'"tos_Omon_EC-Earth3-CC_ssp245_r1i1p1f1_gn_201501-201512.nc"',
]
}
with pytest.raises(ValueError, match="Dimensions do not match"):
xr.open_dataset(
selection, # type: ignore[arg-type]
esgpull_path=esgpull_path,
engine="esgf",
download=True,
chunks={},
)
25 changes: 14 additions & 11 deletions xarray_esgf/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,25 @@ def open_dataset(
combined_datasets = {}
for dataset_id, datasets in grouped_objects.items():
dataset_id_dict = dataset_id_to_dict(dataset_id)
ds = xr.concat(
datasets,
dim="time",
data_vars="minimal",
coords="minimal",
compat="override",
combine_attrs="drop_conflicts",
)
if len(datasets) == 1:
(ds,) = datasets
else:
ds = xr.concat(
datasets,
dim="time",
data_vars="minimal",
coords="minimal",
compat="override",
combine_attrs="drop_conflicts",
)
ds = ds.set_coords([
name for name, da in ds.variables.items() if "bnds" in da.dims
name
for name, da in ds.variables.items()
if "bnds" in da.dims or "time" not in da.dims
])
ds = ds.expand_dims({dim: [dataset_id_dict[dim]] for dim in concat_dims})
combined_datasets[dataset_id] = ds

check_dimensions(combined_datasets)

obj = xr.combine_by_coords(
combined_datasets.values(),
join="exact",
Expand Down