lair.transects.lag_positions#

lair.transects.lag_positions(time, xy, lag_s, max_gap_s=600.0)[source]#

Positions where the air of each sample was actually taken in.

A sample logged at time t is air that entered the inlet lag_s seconds earlier, so it belongs at the platform’s position at t - lag. Positions are interpolated linearly in time along xy.

The record is cut into runs at gaps longer than max_gap_s, and t - lag is not allowed to reach back before the start of the sample’s own run: the first seconds of a run keep its first position instead of being interpolated across the gap to wherever the previous run ended.

Parameters:
  • time (array-like) – Sample times, sorted: POSIX seconds or datetime-like (see the module docstring).

  • xy (np.ndarray) – Logged positions, (n, 2), planar or lon/lat.

  • lag_s (float or array-like) – Inlet lag (seconds), a scalar or one value per sample (the lag differs by instrument epoch).

  • max_gap_s (float, optional) – Time gap (seconds) that starts a new run. Default 600.

Returns:

np.ndarray – The positions, (n, 2). Samples without a time (NaN / NaT) get a NaN position and are left out of the interpolation for the others.

Return type:

ndarray

See also

snap_to_route

The next step, the route point of each position.

Examples

A platform logging one position a minute, with the inlet 60 s behind: each sample belongs where the platform was a minute earlier (the first keeps its own position):

>>> import numpy as np
>>> from lair.transects import lag_positions
>>> time = np.arange(0, 6) * 60.0
>>> x = np.array([0, 500, 1000, 1500, 2000, 2500.0])
>>> xy = np.column_stack([x, np.zeros_like(x)])
>>> lag_positions(time, xy, lag_s=60.0)[:, 0]
array([   0.,    0.,  500., 1000., 1500., 2000.])