Modules Containing Flowtracks Basic Data Structures

The data structures of ParticleSet and its children, ParticleSnapshot (for frames) and Trajectory (for trajectories) are found in the module flowtracks.trajectory. Also in the modules are some functions to create and manipulate these structures. This page provides a reference for the content of this module.

class flowtracks.trajectory.Frame[source]

This is basically a structure with no fancy behaviour. When it is returned from a Flowtracks function, it has two attributes, particles and tracers - each pointing to a ParticleSnapshot object holding data for particles of the respective type.

class flowtracks.trajectory.ParticleSet(pos, velocity, **kwds)[source]

A base class for manipulting particle data. Knows how many particles it has, and holds a varying number of particle properties, each given for the entire set. Properties may be created at construction time or later.

When a property is created, it gets a setter method of the same name and a getter method prefixed with set_. This applies also for mandatory properties.

Arguments

  • pos: a (t,3) array, the position of one particle in t time-points, [m].
  • velocity: (t,3) array, corresponding velocity, [m/s].
  • kwds: keyword arguments should be arrays whose first dimension == t. these are treated as extra attributes to be sliced when creating segments.
__len__()[source]

Return the number of particles in the set.

as_dict()[source]

Returns a dictionary with the “business” properties only, without all the Python bookkeeping and other stuff in the __dict__.

create_property(propname, init_val)[source]

Add a property of the set, expected to be an array whose shape[0] == len(self).

Creates the method <propname>(self, selector=None). If selector is given, it will return only the selected time-points. Also creates set_<propname>(self, value, selector=None) which sets either the value over the entire trajectory or just for the selected time points (this requires the property to already exist for the full trajectory).

Arguments

  • propname: a string, should be a valid Python identifier.
  • init_val: the initial value for the property.
ext_schema()[source]

Extended schema. Like schema() but the values of the returned dictionary are a tuple (type, shape). The shape is scalar, so it only supports 1D or 0D items.

has_property(propname)[source]

Checks whether the looked-after property propname exists for this particle set.

schema()[source]

Creates a dictionary keyed by property name whose values are the shape of one particle’s value for that property. Example: {‘pos’: (3,), ‘velocity’: (3,)}

class flowtracks.trajectory.ParticleSnapshot(pos, velocity, time, trajid, **kwds)[source]

This is one of the two main classes used for iteration over a scene. It inherits from ParticleSet with the added demand for a scalar time and a trajid property for trajectory ID (an integer unique among the scene’s trajectories).

Arguments

  • pos: a (p,3) array, the position of one particle of p, [m].
  • velocity: (p,3) array, corresponding velocity, [m/s].
  • trajid: (p,3) array, for each particle in the snapshot, the unique identifier of the trajectory it belongs to.
  • time: scalar, the identifier of the frame from which this snapshot is taken.
  • kwds: keyword arguments should be arrays whose first dimension == p. these are treated as extra attributes to be sliced when creating segments.
class flowtracks.trajectory.Trajectory(pos, velocity, time, trajid, **kwds)[source]

This is one of the two main classes used for iteration over a scene. It inherits from ParticleSet with the added demand that a scalar trajectory ID (an integer unique amond the scene’s trajectories) and a time property.

Arguments

  • pos: a (t,3) array, the position of one particle in t time-points, [m].
  • velocity: (t,3) array, corresponding velocity, [m/s].
  • time: (t,) array, the clock ticks. No specific units needed.
  • trajid: the unique identifier of this trajectory in the set of trajectories that belong to the same sequence.
  • kwds: keyword arguments should be arrays whose first dimension == t. these are treated as extra attributes to be sliced when creating segments.
__getitem__(selector)[source]

Gets the data for time points selected as a table of shape (n,8), concatenating position, velocity, time, broadcasted trajid.

Arguments

  • selector: any 1d indexing expression known to numpy.
smoothed(smoothness=3.0)[source]

Creates a trajectory generated from this trajectory using cubic B-spline interpolation.

Arguments

  • smoothness: strength of smoothing, larger is smoother. See scipy.interpolate.splprep()‘s s parameter.

Returns

a new Trajectory object with the interpolated positions and velocities. If the length of the trajectory < 4, returns self.

flowtracks.trajectory.mark_unique_rows(all_rows)[source]

Filter out rows whose position columns represent a particle that already appears, so that each particle position appears only once.

Arguments

  • all_rows: an array with n rows and at least 3 columns for position.

Returns

an array with the indices of rows to take from the input such that in the result, the first 3 columns form a unique combination.

flowtracks.trajectory.take_snapshot(trajects, frame, schema)[source]

Goes over a list of trajectories and extracts the particle data at a given time point. If the trajectory list is empty, creates an empty snapshot.

Arguments

  • trajects: a list of :class:Trajectory objects to query.
  • frame: the frame number to which snapshot data belongs.
  • schema: a dict, {propname: shape tuple}, as given by the trajectory’s schema(). This is only needed for consistency in the case of an empty trajectory list resulting in an empty snapshot.

Returns

a ParticleSnapshot object with all the particles in the given frame.

flowtracks.trajectory.trajectories_in_frame(trajects, frame_num, start_times=None, end_times=None, segs=False)[source]

Notes the indices of trajectories participating in the frame for later extraction.

Arguments

  • trajects: a list of :class:Trajectory objects to filter.
  • frame_num: the time value (as found in trajectory.time()) at which the trajectory should be active.
  • start_times, end_times: each a len(trajects) array containing the corresponding start/end frame number of each trajectory, respectively.
  • segs: true if the trajectory should be active also in the following frame.

Returns

traj_nums = the indices of active trajectories in trajects.