MCPcopy
hub / github.com/pydata/xarray / _decimal_year

Function _decimal_year

xarray/coding/calendar_ops.py:321–346  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

319
320
321def _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
349def interp_calendar(source, target, dim="time"):

Callers 2

decimal_yearMethod · 0.90
interp_calendarFunction · 0.85

Calls 2

get_date_typeFunction · 0.90
apply_ufuncFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…