diff --git a/examples/tsunami/chile2010_fgmax-fgout/use_xarray_backends.py b/examples/tsunami/chile2010_fgmax-fgout/use_xarray_backends.py index 091f55f4f..7145195c2 100644 --- a/examples/tsunami/chile2010_fgmax-fgout/use_xarray_backends.py +++ b/examples/tsunami/chile2010_fgmax-fgout/use_xarray_backends.py @@ -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") diff --git a/src/python/geoclaw/xarray_backends.py b/src/python/geoclaw/xarray_backends.py index 3738b4e9f..326d0d908 100644 --- a/src/python/geoclaw/xarray_backends.py +++ b/src/python/geoclaw/xarray_backends.py @@ -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. ): @@ -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 = {} @@ -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.