get_time_coord#
- ethograph.utils.xr_utils.get_time_coord(da)[source]#
Return the time coordinate of a DataArray, regardless of its name.
Every feature variable in an ethograph dataset must have at least one dimension whose name contains
"time"(e.g.time,time_aux,time_labels). Different features can use different time dimensions at different sampling rates — this function finds the right one for a given DataArray. See Data Format Requirements for the full specification.Lookup order: dimension coordinates (
da.dims) are checked before non-dimension coordinates (da.coords), so the primary time axis that actually indexes the data is returned even when a shorter auxiliary coordinate is also attached.- Parameters:
da (xarray.DataArray) – Any DataArray from an ethograph dataset.
- Returns:
The time coordinate values, or
Noneif no coordinate name contains"time".- Return type:
xarray.DataArray or None
Examples
>>> import ethograph as eto >>> dt = eto.open("experiment.nc") >>> ds = dt.itrial(0)
Feature with the default
timedimension:>>> eto.get_time_coord(ds["speed"]) <xarray.DataArray 'time' (time: 9000)> ...
Audio stored on a higher-rate
time_auxaxis:>>> eto.get_time_coord(ds["audio_waveform"]) <xarray.DataArray 'time_aux' (time_aux: 441000)> ...
Used internally by
add_changepoints_to_dsto discover which time dimension to vectorise over.