Skip to content

Commit

Permalink
Workaround for old squashed files with inconsistent y-boundary cells
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
johnomotani committed Jul 27, 2022
1 parent fb89188 commit 29e7053
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions xbout/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def _auto_open_mfboutdataset(

# Open just one file to read processor splitting
nxpe, nype, mxg, myg, mxsub, mysub, is_squashed_doublenull = _read_splitting(
filepaths[0], info
filepaths[0], info, keep_yboundaries
)

if is_squashed_doublenull:
Expand Down Expand Up @@ -675,7 +675,7 @@ def _expand_wildcards(path):
return natsorted(filepaths, key=lambda filepath: str(filepath))


def _read_splitting(filepath, info=True):
def _read_splitting(filepath, info, keep_yboundaries):
ds = xr.open_dataset(str(filepath))

# Account for case of no parallelisation, when nxpe etc won't be in dataset
Expand Down Expand Up @@ -739,6 +739,23 @@ def get_nonnegative_scalar(ds, key, default=1, info=True):
nxpe = 1
nype = 1
is_squashed_doublenull = (ds["jyseps2_1"] != ds["jyseps1_2"]).values
elif ny_file == ny + 2 * myg:
# Older squashed file from double-null grid but containing only lower
# target boundary cells.
if keep_yboundaries:
raise ValueError(
"Cannot keep y-boundary points: squashed file is missing upper "
"target boundary points."
)
has_yboundaries = not (ny_file == ny)
if not has_yboundaries:
myg = 0

nxpe = 1
nype = 1
# For this case, do not need the special handling enabled by
# is_squashed_doublenull=True, as keeping y-boundaries is not allowed
is_squashed_doublenull = False

# Avoid trying to open this file twice
ds.close()
Expand Down

0 comments on commit 29e7053

Please sign in to comment.