xarray.Dataset.spatial.mask_land#
- Dataset.spatial.mask_land(data_var, method='regionmask', threshold=None, mask=None, output_mask=False, **options)#
Masks a data variable by land.
- Parameters:
data_var (
str) – The key of the data variable to mask.method (
str, optional) – The masking method, by default “regionmask”. Supported methods: “regionmask”, “pcmdi”.threshold (
float | None, optional) – The threshold used to determine cell classification, values below or equal to this are considered sea, defaults to 0.2.mask (
xr.DataArray | None, optional) – A custom mask to apply, by default None. If None, a mask is generated using the specifiedmethod.output_mask (
bool | str, optional) – If True, returns the mask as a DataArray along with the masked dataset. If a string, the name of the mask variable to add to the dataset. By default False.**options (
Any) – These options are passed directly to themethod. See specific method documentation for available options:xcdat.mask.pcmdi_land_sea_mask()for PCMDI options.
- Returns:
xr.Dataset– The dataset with the data variable masked by land.
Examples
Mask a data variable by land using the default method (regionmask):
>>> ds_masked = ds.spatial.mask_land("tas")
Mask a data variable by land using the PCMDI method with custom threshold:
>>> ds_masked = ds.spatial.mask_land("tas", method="pcmdi", threshold=0.3)
Mask a data variable by land using a custom mask and output the mask:
>>> custom_mask = xr.DataArray(...) # Define your custom mask here >>> ds_masked = ds.spatial.mask_land("tas", mask=custom_mask, output_mask=True)
Mask a data variable by land and add the mask to the dataset with a custom name:
>>> ds_masked = ds.spatial.mask_land("tas", output_mask="land_mask")