pcmdi_metrics.io.select_subset

Contents

pcmdi_metrics.io.select_subset#

pcmdi_metrics.io.select_subset(ds, lat=None, lon=None, time=None)[source]#

Select a subset of the given xarray dataset based on specified latitude, longitude, and time ranges.

Parameters:
  • ds (xr.Dataset) – The input xarray dataset.

  • lat (tuple, optional) – Latitude range in the form of (min, max).

  • lon (tuple, optional) – Longitude range in the form of (min, max).

  • time (tuple, optional) – Time range in the form of (start_time, end_time). start_time and end_time can be integers, floats, strings, or cftime.datetime objects.

Returns:

xr.Dataset – Subset of the input dataset based on the specified latitude, longitude, and time ranges.

Notes

This function allows for flexible subsetting of xarray datasets based on geographical coordinates and time ranges.

Examples

>>> import xarray as xr
>>> import cftime
>>>
>>> # Load your xarray dataset (ds) here
>>> ds = xr.open_dataset('path/to/your/dataset.nc')
>>>
>>> # Define latitude, longitude, and time ranges
>>> lat_tuple = (30, 50)  # Latitude range
>>> lon_tuple = (110, 130)  # Longitude range
>>> time_tuple = ("1850-01-01 00:00:00", "1851-12-31 23:59:59")  # Time range
>>>
>>> # Select subset based on specified ranges
>>> ds_subset = select_subset(ds, lat=lat_tuple, lon=lon_tuple, time=time_tuple)