traja.trajectory.batch_process

traja.trajectory.batch_process(trajectories: list, func: Callable, n_jobs: int = -1, **kwargs) list[source]

Apply function to trajectories in parallel for performance.

Parameters:
  • trajectories (list) – List of TrajaDataFrame trajectories

  • func (Callable) – Function to apply to each trajectory

  • n_jobs (int) – Number of parallel jobs. -1 means use all CPUs. Default -1.

  • **kwargs – Additional arguments passed to func

Returns:

Results from applying func to each trajectory

Return type:

list

Example

>>> import traja
>>> trajs = [traja.generate(n=100) for _ in range(100)]
>>> # Normalize all trajectories in parallel
>>> normalized = traja.trajectory.batch_process(
...     trajs,
...     lambda t: t.traja.normalize_trajectory()
... )

Note

Requires joblib for parallel processing: pip install joblib Falls back to sequential processing if joblib not available.