pcmdi_metrics.utils.apply_oceanmask
- pcmdi_metrics.utils.apply_oceanmask(obj, data_var=None, landfrac=None, land_criteria=0.8, ocean_criteria=0.2)[source]
Apply an ocean mask to a given DataArray or Dataset.
This function is a wrapper around apply_landmask that specifically masks land areas, effectively creating an ocean mask.
- Parameters:
obj (
Union[xr.Dataset
,xr.DataArray]
) – The Dataset or DataArray to which the ocean mask will be applied.data_var (
str
, optional) – Name of the DataArray in the Dataset. Required if obj is a Dataset.landfrac (
xr.DataArray
, optional) – Land fraction data array. Values should range from 0 (ocean) to 1 (land). If None, a land-sea mask will be created automatically.land_criteria (
float
, optional) – Threshold for considering a grid cell as land. Default is 0.8.ocean_criteria (
float
, optional) – Threshold for considering a grid cell as ocean. Default is 0.2.
- Returns:
xr.DataArray
– DataArray with the ocean mask applied (land areas masked).
See also
apply_landmask
The underlying function used to apply the mask.
Examples
>>> from pcmdi_metrics.utils import apply_oceanmask >>> da_ocean = apply_oceanmask(da, landfrac=mask) >>> ds_ocean = apply_oceanmask(ds, data_var="ts", landfrac=mask)