"""grdlandmask - Create a "wet-dry" mask grid from shoreline data base"""importxarrayasxrfrompygmt.clibimportSessionfrompygmt.exceptionsimportGMTInvalidInputfrompygmt.helpersimport(GMTTempFile,build_arg_string,fmt_docstring,kwargs_to_strings,use_alias,)
[docs]@fmt_docstring@use_alias(G="outgrid",I="spacing",R="region",r="registration",V="verbose",)@kwargs_to_strings(R="sequence")defgrdlandmask(**kwargs):r""" Create a grid file with set values for land and water. Read the selected shoreline database and create a grid to specify which nodes in the specified grid are over land or over water. The nodes defined by the selected region and lattice spacing will be set according to one of two criteria: (1) land vs water, or (2) the more detailed (hierarchical) ocean vs land vs lake vs island vs pond. Full option list at :gmt-docs:`grdlandmask.html` {aliases} Parameters ---------- outgrid : str or None The name of the output netCDF file with extension .nc to store the grid in. {I} {R} {r} Returns ------- ret: xarray.DataArray or None Return type depends on whether the ``outgrid`` parameter is set: - :class:`xarray.DataArray` if ``outgrid`` is not set - None if ``outgrid`` is set (grid output will be stored in file set by ``outgrid``) """if"I"notinkwargs.keys()or"R"notinkwargs.keys():raiseGMTInvalidInput("Both 'region' and 'spacing' must be specified.")withGMTTempFile(suffix=".nc")astmpfile:withSession()aslib:if"G"notinkwargs.keys():# if outgrid is unset, output to tempfilekwargs.update({"G":tmpfile.name})outgrid=kwargs["G"]arg_str=build_arg_string(kwargs)lib.call_module("grdlandmask",arg_str)ifoutgrid==tmpfile.name:# if user did not set outgrid, return DataArraywithxr.open_dataarray(outgrid)asdataarray:result=dataarray.load()_=result.gmt# load GMTDataArray accessor informationelse:result=None# if user sets an outgrid, return Nonereturnresult