Skip to content

Commit 3dadf8f

Browse files
committed
refactor try exception, fix the order of dims
1 parent 6ba4d04 commit 3dadf8f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

PyStemmusScope/save.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ def _update_dataset_attrs_dims(dataset: xr.Dataset, forcing_dict: Dict) -> xr.Da
202202
dataset_expanded = dataset.expand_dims(["x", "y"])
203203

204204
# change the order of dims
205-
try:
206-
dataset_reordered = dataset_expanded.transpose("time", "y", "x", "z")
207-
except ValueError:
205+
if "z" in dataset_expanded.dims:
206+
try:
207+
dataset_reordered = dataset_expanded.transpose("time", "z", "y", "x")
208+
except ValueError as err:
209+
raise ValueError("Data should have dimensions time, y, x, z.") from err
210+
else:
208211
try:
209212
dataset_reordered = dataset_expanded.transpose("time", "y", "x")
210213
except ValueError as err:
211-
raise ValueError("Data should have time dimension.") from err
214+
raise ValueError("Data should have dimensions time, y, x.") from err
212215

213216
# additional metadata
214217
lat = forcing_dict["latitude"]
@@ -264,7 +267,6 @@ def to_netcdf(config: Dict, cf_filename: str) -> str:
264267
"""
265268

266269
# list of required forcing variables, Alma_short_name: forcing_io_name, # model_name
267-
# they called ECdata
268270
var_names = {
269271
"RH": "rh", # RH
270272
"SWdown_ec": "sw_down", # Rin

0 commit comments

Comments
 (0)