Skip to content

Commit

Permalink
Merge pull request #240 from boutproject/workaround-for-old-squashed-…
Browse files Browse the repository at this point in the history
…files

Workaround for old squashed files with inconsistent y-boundary cells
  • Loading branch information
johnomotani authored Jul 31, 2022
2 parents fb89188 + 29e7053 commit 91c8a1e
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 91c8a1e

Please sign in to comment.