pcmdi_metrics.utils.create_land_sea_mask

pcmdi_metrics.utils.create_land_sea_mask(obj, lon_key=None, lat_key=None, as_boolean=False, method='regionmask')[source]

Generate a land-sea mask (1 for land, 0 for sea) for a given xarray Dataset or DataArray.

Parameters:
  • obj (Union[xr.Dataset, xr.DataArray]) – The Dataset or DataArray object.

  • lon_key (str, optional) – Name of DataArray for longitude, by default None

  • lat_key (str, optional) – Name of DataArray for latitude, by default None

  • as_boolean (bool, optional) – Set mask value to True (land) or False (ocean), by default False, thus 1 (land) and 0 (ocean).

  • method (str, optional) – Method to use for creating the mask, either ‘regionmask’ or ‘pcmdi’, by default ‘regionmask’.

Returns:

xr.DataArray – A DataArray of land-sea mask (1 or 0 for land or sea, or True or False for land or sea).

Examples

>>> from pcmdi_metrics.utils import create_land_sea_mask  # import function
>>> mask = create_land_sea_mask(ds)  #  Generate land-sea mask (land: 1, sea: 0)
>>> mask = create_land_sea_mask(ds, as_boolean=True)  # Generate land-sea mask (land: True, sea: False)
>>> mask = create_land_sea_mask(ds, method="pcmdi")  # Use PCMDI method