From 29e70534f554c923ea096d0d233a26b237b5640f Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 27 Jul 2022 16:26:28 +0100 Subject: [PATCH] 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`. --- xbout/load.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/xbout/load.py b/xbout/load.py index 5a7814b2..39c77d6f 100644 --- a/xbout/load.py +++ b/xbout/load.py @@ -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: @@ -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 @@ -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()