xarray.Dataset.traj.filter#
- abstract Dataset.traj.filter(method='speed', max_speed=10.0, nsigma=5.0, side_half_width=2)#
Filter outlier positions from trajectories.
- Parameters:
method (
str) – Outlier detection method:'speed': walk through non-NaN positions in order and compare each to the last accepted position. Any position whose speed from the last accepted position exceeds max_speed [m/s] is masked. Crucially, when a position is masked the “last accepted” pointer is not advanced, so entire consecutive runs of invalid positions (e.g. GPS no-fix sentinel values near (0, 0)) are cleared in a single O(N) pass without falsely masking the valid positions that bracket the bad run.'nsigma_sliding': mask positions whose latitude or longitude deviates more than nsigma standard deviations from the local mean computed over a sliding window of half-width side_half_width. Applied independently to latitude and longitude. Note: this method is designed for isolated single- point spikes; it is less effective for consecutive runs of outliers.
max_speed (
float) – Maximum allowed speed [m/s]. Used withmethod='speed'. Default: 10.nsigma (
float) – Outlier threshold in number of standard deviations. Used withmethod='nsigma_sliding'. Default: 5.side_half_width (
int) – Half-width of the sliding window (number of neighbours on each side). Used withmethod='nsigma_sliding'. Default: 2.
- Returns:
xarray.Dataset– Dataset with outlier lat/lon positions set to NaN. Time and other variables are left unchanged.
See also
speedCalculate the speed along trajectories.
Examples
>>> import xarray as xr >>> import trajan as _ >>> import lzma >>> b = lzma.open('examples/barents.nc.xz') >>> ds = xr.open_dataset(b) >>> filtered = ds.traj.filter(method='speed', max_speed=3.) >>> filtered = ds.traj.filter(method='nsigma_sliding', nsigma=5., side_half_width=2)