Skip to content

Commit

Permalink
update use of dry_tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarnhart committed Aug 21, 2024
1 parent 61460c1 commit f61d155
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
14 changes: 13 additions & 1 deletion examples/tsunami/chile2010_fgmax-fgout/use_xarray_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@
# the format, fg number, and frame number are inferred from the filename.

ds = xr.open_dataset(
filename, engine=FGOutBackend, backend_kwargs={"epsg": epsg_code, "qmap": "geoclaw"}
filename,
engine=FGOutBackend,
backend_kwargs={
"epsg": epsg_code,
"qmap": "geoclaw",
# qmap is the qmap specified to the fgout object in setrun.py see
# the following documentation page for more details.
# https://www.clawpack.org/dev/fgout.html#specifying-q-out-vars
"dry_tolerance": None,
# variables that are not eta and B are masked
# where h>dry_tolerance. To turn this functionality
# off set dry_tolerance = None.
},
)
# ds is now an xarray object. It can be interacted with directly or written to netcdf using
ds.to_netcdf("fgout0001_0001.nc")
Expand Down
23 changes: 14 additions & 9 deletions src/python/geoclaw/xarray_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ def open_dataset(
filename, # path to fgout file.
qmap="geoclaw", # qmap value for FGoutGrid ('geoclaw', 'dclaw', or 'geoclaw-bouss')
epsg=None, # epsg code
drytol=0.001, # dry tolerance for masking elements of q that are not eta or B
# used only if h or eta-B is available based on q_out_vars.
dry_tolerance=0.001,
# dry tolerance used for for masking elements of q that are not
# eta or B. Default behavior is to mask all elements of q except for
# eta and B where h>0.001.
# used only if h or eta-B is available based on q_out_vars.
# if dry_tolerance = None, no masking is applied to any variable.
drop_variables=None, # name of any elements of q to drop.
):

Expand Down Expand Up @@ -228,12 +232,13 @@ def open_dataset(
ni = len(y)

# mask based on dry tolerance
try:
mask = fgout.h < drytol
# internally fgout_tools will try fgou.eta-fgout.B if h is not present.
except AttributeError:
print("FGOutBackend: No h, eta, or B. No mask applied.")
mask = np.ones((nj, ni), dtype=bool)
if dry_tolerance is not None:
try:
mask = fgout.h < dry_tolerance
# internally fgout_tools will try fgou.eta-fgout.B if h is not present.
except AttributeError:
print("FGOutBackend: No h, eta, or B. No mask applied.")
mask = np.ones((nj, ni), dtype=bool)

# create data_vars dictionary
data_vars = {}
Expand All @@ -254,7 +259,7 @@ def open_dataset(
Q = fgout.q[i, :, :]

# mask all but eta based on h presence.
if varname not in ("B", "eta"):
if (varname not in ("B", "eta")) and dry_tolerance is not None:
Q[mask] = nodata

# to keep xarray happy, need to transpose and flip ud.
Expand Down

0 comments on commit f61d155

Please sign in to comment.