xarray.coding.times.CFDatetimeCoder#
- class xarray.coding.times.CFDatetimeCoder(use_cftime=None, time_unit='ns', infer_dtype='data')[source]#
Coder for CF Datetime coding.
- Parameters:
use_cftime (
bool, optional) – Only relevant if encoded dates come from a standard calendar (e.g. “gregorian”, “proleptic_gregorian”, “standard”, or not specified). If None (default), attempt to decode times tonp.datetime64objects; if this is not possible, decode times tocftime.datetimeobjects. If True, always decode times tocftime.datetimeobjects, regardless of whether or not they can be represented usingnp.datetime64objects. If False, always decode times tonp.datetime64objects; if this is not possible raise an error. May not be supported by all the backends.time_unit (
PDDatetimeUnitOptions) – Target resolution when decoding dates. Defaults to “ns”.infer_dtype (
{"data", "metadata"}, default:"data") – How to infer the dtype of the decoded variable:"data"(default): read the first and last values from the store to verify they decode successfully. Preserves backwards-compatible behavior, including the auto-fallback tocftime.datetimefor values outside thenp.datetime64[ns]range."metadata": infer the dtype fromunits,calendar,use_cftimeandtime_unitalone, assuming the stored dates lie near the reference date inunits. Nothing is read from the store, which speeds up opening remote stores with many time-encoded variables. The first and last values are read, as with"data", only when metadata cannot tell: when, withuse_cftime=Noneand a standard calendar, dates near the reference date needcftime(e.g."hours since 1-1-1"or a reference date before 1582-10-15), or when decoding dates near the reference date fails.The stored values are checked when they are decoded instead, and a
ValueErroris raised then if they need a different dtype than inferred. This happens for dates outside thenp.datetime64[time_unit]range (passuse_cftime=Trueor a coarsertime_unitsuch as"s") and for floating point values with fractions finer thanunits, e.g.0.5with"seconds since ..."(pass atime_unitfine enough to represent them). Index coordinates are decoded when the dataset is opened, other variables when they are loaded.
Methods
__init__([use_cftime, time_unit, infer_dtype])decode(variable[, name])Convert a decoded variable to an encoded variable.
encode(variable[, name])Convert an encoded variable to a decoded variable.