lt_toolbox.TrajFrame.filter#
- TrajFrame.filter(expr: str | Expr, drop: bool = False) Self[source]#
Filter trajectories using conditional on a single column variable specified with a string or Polars expression.
Filtering returns a reduced TrajFrame where only the complete trajectories meeting the specified condition are retained. The exception is when users specify drop=True, in which case trajectories meeting the specified condition are dropped from the TrajFrame.
When the expression variable is specified as ‘time’ only the observations (obs) meeting the specified date conditions are retained for all trajectories.
- Parameters:
expr (str | Expression) – String expression of the form “{variable} {operator} {value}”, where {variable} represents the column variable contained in the TrajFrame used to filter trajectories, {operator} represents one of the six standard comparison operators and {value} represents the value with which to compare the {variable} to. Users can alternatively specify a polars expression.
drop (bool, default: False) – Indcates if fitered trajectories should be retained in the new TrajFrame (False) or instead dropped from the existing TrajFrame (True).
- Returns:
TrajFrame including the complete Lagrangian trajectories which meet (do not meet) the specified filter condition.
- Return type:
TrajFrame
Examples
Filtering all trajectories where latitude is greater than 50 N.
>>> trajectories.filter(expr='lat > 50', drop=False)
Filtering trajectory observations between two dates using Datetime strings.
>>> trajectories.filter('time > 2000-01-01').filter('time <= 2000-12-31')