pcmdi_metrics.utils.find_overlapping_dates
- pcmdi_metrics.utils.find_overlapping_dates(ds, start_date, end_date)[source]
Find the overlapping period between given dates and a dataset’s time range.
- Parameters:
ds (
xarray.Dataset
) – The dataset containing a time dimension.start_date (
str
) – The start date in ‘YYYY-MM-DD’ format.end_date (
str
) – The end date in ‘YYYY-MM-DD’ format.
- Returns:
tuple
orNone
– A tuple containing the start and end dates of the overlapping period, or None if there is no overlap.
Notes
This function automatically detects the calendar used in the dataset and applies the appropriate datetime conversion.
Examples
>>> from pcmdi_metrics.utils import find_overlapping_dates >>> import xarray as xr >>> dates = xr.cftime_range('2000-01-01', periods=365) >>> ds = xr.Dataset({'time': dates}) >>> find_overlapping_dates(ds, '2000-06-01', '2001-01-01') ('2000-06-01', '2000-12-30')