CustomTrajectoryGenerator class¶
Create a movement trajectory for a stimulus, according to explicit definition.
The definition can be loaded from a CSV file or specified programmatically.
This class can hold several different trajectories. Each has its own ID. Before the trial starts, set the ID of the trajectory to play.
Use this class in conjunction with StimulusAnimator
After loading trajectories, call validate()
Methods and properties:¶
-
class
trajtracker.movement.
CustomTrajectoryGenerator
(cyclic=False, interpolate=True)¶ -
__init__
(cyclic=False, interpolate=True)¶ Constructor - invoked when you create a new object by writing CustomTrajectoryGenerator()
Parameters: - cyclic – See
cyclic
- interpolate – See
interpolate
- cyclic – See
-
active_traj_id
¶ The ID of the active trajectory
-
clear_all_trajectories
()¶ Forget all previously-defined trajectories
-
cyclic
¶ Whether the trajectory is cyclic or not (bool). In a cyclic trajectory, when the time exceeds the trajectory duration, we return to the starting point.
-
get_traj_point
(time)¶ Generate the trajectory - get one time point data
Parameters: time – in seconds Returns: (x, y, visible)
-
interpolate
¶ This determines what happens when get_traj_point() is called with time that was not specifically defined in the trajectory:
- True: interpolate linearly the two nearest time points
- False: Use data from the last timepoint <= time
-
load_from_csv
(filename, id_type=<type 'str'>)¶ Load trajectories from a CSV file.
The file should have the following columns:
- x, y: the coordinates
- time: a time point of these coordinates
- visible: whether the stimulus should be visible in this time point
- traj_id: use this column to specify several trajectories in a single file. If this column is missing, the class assumes that there is only one trajectory in the file, and its ID will be 1.
The file should be sorter properly: all lines of a single trajectory should be grouped together, and times should appear in ascending order.
Parameters: - filename – Name of the file (full path)
- id_type – Convert the traj_id column in the file from str to this type
-
log_level
¶ Logging level of this object: trajtracker.log_none, log_error (default), log_warn, log_info, log_debug, log_trace
-
set_trajectory
(traj_id, traj_data)¶ Add a single trajectory (or replace an existing one)
Parameters: - traj_id – A logical ID for this trajectory.
- traj_data – The trajectory data - a list/tuple of per-timepoint data. Per time point, specify a list/tuple of with 3 or 4 elements: time (> 0), x coordinate (int), y coordinate (int), and optional “visible” (bool)
-
validate
()¶ Validate that the configuration is correct. Raise an exception if not.
-