Convert a datetime DataArray to decimal years according to its calendar. The decimal year of a timestamp is its year plus its sub-year component converted to the fraction of its year. Ex: '2000-03-01 12:00' is 2000.1653 in a standard calendar, 2000.16301 in a "noleap" or 2000.1680
(times)
| 319 | |
| 320 | |
| 321 | def _decimal_year(times): |
| 322 | """Convert a datetime DataArray to decimal years according to its calendar. |
| 323 | |
| 324 | The decimal year of a timestamp is its year plus its sub-year component |
| 325 | converted to the fraction of its year. |
| 326 | Ex: '2000-03-01 12:00' is 2000.1653 in a standard calendar, |
| 327 | 2000.16301 in a "noleap" or 2000.16806 in a "360_day". |
| 328 | """ |
| 329 | if times.dtype == "O": |
| 330 | function = _decimal_year_cftime |
| 331 | kwargs = {"date_class": get_date_type(times.dt.calendar, True)} |
| 332 | else: |
| 333 | function = _decimal_year_numpy |
| 334 | kwargs = {"dtype": times.dtype} |
| 335 | from xarray.computation.apply_ufunc import apply_ufunc |
| 336 | |
| 337 | return apply_ufunc( |
| 338 | function, |
| 339 | times, |
| 340 | times.dt.year, |
| 341 | times.dt.days_in_year, |
| 342 | kwargs=kwargs, |
| 343 | vectorize=True, |
| 344 | dask="parallelized", |
| 345 | output_dtypes=[np.float64], |
| 346 | ) |
| 347 | |
| 348 | |
| 349 | def interp_calendar(source, target, dim="time"): |
no test coverage detected
searching dependent graphs…