Skip to content

Commit 29e7053

Browse files
committed
Workaround for old squashed files with inconsistent y-boundary cells
Older 'squashed' output files for double-null grids often included y-boundary cells for the lower target (ends of the logical grid) but not the upper target (somewhere in the middle of the logical grid). Add some special handling to allow these files to be opened, as long as `keep_yboundaries = False`.
1 parent fb89188 commit 29e7053

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

xbout/load.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def _auto_open_mfboutdataset(
542542

543543
# Open just one file to read processor splitting
544544
nxpe, nype, mxg, myg, mxsub, mysub, is_squashed_doublenull = _read_splitting(
545-
filepaths[0], info
545+
filepaths[0], info, keep_yboundaries
546546
)
547547

548548
if is_squashed_doublenull:
@@ -675,7 +675,7 @@ def _expand_wildcards(path):
675675
return natsorted(filepaths, key=lambda filepath: str(filepath))
676676

677677

678-
def _read_splitting(filepath, info=True):
678+
def _read_splitting(filepath, info, keep_yboundaries):
679679
ds = xr.open_dataset(str(filepath))
680680

681681
# Account for case of no parallelisation, when nxpe etc won't be in dataset
@@ -739,6 +739,23 @@ def get_nonnegative_scalar(ds, key, default=1, info=True):
739739
nxpe = 1
740740
nype = 1
741741
is_squashed_doublenull = (ds["jyseps2_1"] != ds["jyseps1_2"]).values
742+
elif ny_file == ny + 2 * myg:
743+
# Older squashed file from double-null grid but containing only lower
744+
# target boundary cells.
745+
if keep_yboundaries:
746+
raise ValueError(
747+
"Cannot keep y-boundary points: squashed file is missing upper "
748+
"target boundary points."
749+
)
750+
has_yboundaries = not (ny_file == ny)
751+
if not has_yboundaries:
752+
myg = 0
753+
754+
nxpe = 1
755+
nype = 1
756+
# For this case, do not need the special handling enabled by
757+
# is_squashed_doublenull=True, as keeping y-boundaries is not allowed
758+
is_squashed_doublenull = False
742759

743760
# Avoid trying to open this file twice
744761
ds.close()

0 commit comments

Comments
 (0)