stytra.experiments package

Submodules

stytra.experiments.camera_recording_experiment module

class stytra.experiments.camera_recording_experiment.VideoRecordingExperiment(*args, **kwargs)[source]

Bases: stytra.experiments.tracking_experiments.CameraVisualExperiment

start_protocol()[source]

Start the protocol from the ProtocolRunner. Before that, send a a notification and if required communicate with the microscope to synchronize and read configuration.

end_protocol(save=True)[source]

Function called at Protocol end. Reset Protocol and save data_log.

Parameters

save (bool) – Specify whether to save experiment data (Default value = True).

wrap_up(*args, **kwargs)[source]
Parameters
  • *args

  • **kwargs

stytra.experiments.fish_pipelines module

class stytra.experiments.fish_pipelines.TailTrackingPipeline[source]

Bases: stytra.tracking.pipelines.Pipeline

class stytra.experiments.fish_pipelines.FishTrackingPipeline[source]

Bases: stytra.tracking.pipelines.Pipeline

class stytra.experiments.fish_pipelines.EyeTrackingPipeline[source]

Bases: stytra.tracking.pipelines.Pipeline

class stytra.experiments.fish_pipelines.EyeTailTrackingPipeline[source]

Bases: stytra.tracking.pipelines.Pipeline

stytra.experiments.tracking_experiments module

class stytra.experiments.tracking_experiments.CameraVisualExperiment(*args, camera, camera_queue_mb=100, **kwargs)[source]

Bases: stytra.experiments.VisualExperiment

General class for Experiment that need to handle a camera. It implements a view of frames from the camera in the control GUI, and the respective parameters. For debugging it can be used with a video read from file with the VideoFileSource class.

reset()[source]
initialize_plots()[source]
send_gui_parameters()[source]
start_experiment()[source]
make_window()[source]
go_live()[source]
wrap_up(*args, **kwargs)[source]
Parameters
  • *args

  • **kwargs

excepthook(exctype, value, tb)[source]
Parameters
  • exctype

  • value

  • tb

class stytra.experiments.tracking_experiments.TrackingExperiment(*args, tracking, recording=None, **kwargs)[source]

Bases: stytra.experiments.tracking_experiments.CameraVisualExperiment

Abstract class for an experiment which contains tracking.

This class is the base for any experiment that tracks behavior (being it eyes, tail, or anything else). The general purpose of the class is handle a frame dispatcher, the relative parameters queue and the output queue.

The frame dispatcher take two input queues:

  • frame queue from the camera;

  • parameters queue from parameter window.

and it puts data in three queues:

  • subset of frames are dispatched to the GUI, for displaying;

  • all the frames, together with the parameters, are dispatched to perform tracking;

  • the result of the tracking function, is dispatched to a data accumulator for saving or other purposes (e.g. VR control).

Parameters

tracking (dict) –

containing fields: tracking_method
estimator: can be vigor for embedded fish, position

for freely-swimming, or a custom subclass of Estimator

reset()[source]
make_window()[source]
initialize_plots()[source]
refresh_plots()[source]
send_gui_parameters()[source]

Called upon gui timeout, put tracking parameters in the relative queue.

start_protocol()[source]

Start the protocol from the ProtocolRunner. Before that, send a a notification and if required communicate with the microscope to synchronize and read configuration.

end_protocol(save=True)[source]

Function called at Protocol end. Reset Protocol and save data_log.

Parameters

save (bool) – Specify whether to save experiment data (Default value = True).

save_data()[source]

Save tail position and dynamic parameters and terminate.

set_protocol(protocol)[source]

Connect new protocol start to resetting of the data accumulator.

Parameters

protocol

wrap_up(*args, **kwargs)[source]
Parameters
  • *args

  • **kwargs

excepthook(exctype, value, tb)[source]

If an exception happens in the main loop, close all the processes so nothing is left hanging.

Module contents

stytra.experiments.imports()[source]
class stytra.experiments.Experiment(app=None, protocol=None, dir_save=None, dir_assets='', instance_number=-1, database=None, metadata_general=None, metadata_animal=None, loop_protocol=False, log_format='csv', scope_triggering=None, offline=False, **kwargs)[source]

Bases: PyQt5.QtCore.QObject

General class that runs an experiment.

Parameters
  • app (QApplication()) – Application to run the Experiment QObject.

  • protocol (object of Protocol) – list of protocols that can be run in this experiment session.

  • directory (str) – (optional) Directory where metadata will be saved. If None, nothing will be saved (default: None).

  • metadata_general (GeneralMetadata object) – (optional) Class for saving general metadata about the experiment. I If not passed, a default GeneralMetadata object will be set.

  • metadata_animal (AnimalMetadata object) – (optional) Class for saving animal metadata about the experiment. If not passed, a default AnimalMetadata object will be set.

  • calibrator (Calibrator object) – (optional) Calibrator object to calibrate the stimulus display. If not set, a CrossCalibrator will be used.

  • asset_directory (str) – (optional) Path where asset files such as movies or images to be displayed can be found.

  • display (dict) – (optional) Dictionary with specifications for the display. Possible key values are full_screen: bool (False) window_size: Tuple(Int, Int) framerate: target framerate, if 0, it is the highest possilbe gl_display : bool (False)

  • rec_stim_framerate (int) – (optional) Set to record a movie of the displayed visual stimulus. It specifies every how many frames one will be saved (set to 1 to record) all displayed frames. The final movie will be saved in the directory in an .h5 file.

  • trigger (Trigger object) – (optional) Trigger class to control the beginning of the stimulation.

  • offline (bool) – if stytra is used in offline analysis, stimulus is not displayed

  • log_format (str) – one of “csv”, “feather”, “hdf5” (pytables-based) or “json”

sig_data_saved
folder_name
filename_prefix()[source]
filename_base()[source]
save_log(log, name, category='tracking')[source]
initialize_plots()[source]
set_id()[source]
reset()[source]
start_experiment()[source]

Start the experiment creating GUI and initialising metadata.

restore_window_state()[source]
make_window()[source]

Make experiment GUI, defined in children depending on experiments.

check_trigger()[source]
read_scope_data()[source]
start_protocol()[source]

Start the protocol from the ProtocolRunner. Before that, send a a notification and if required communicate with the microscope to synchronize and read configuration.

abort_start()[source]
save_data()[source]
end_protocol(save=True)[source]

Function called at Protocol end. Reset Protocol and save data_log.

Parameters

save (bool) – Specify whether to save experiment data (Default value = True).

wrap_up(*args, **kwargs)[source]

Clean up things before closing gui. Called by close button.

Parameters
  • *args

  • **kwargs

excepthook(exctype, value, tb)[source]
Parameters
  • exctype

  • value

  • tb

class stytra.experiments.VisualExperiment(*args, calibrator=None, stim_plot=False, stim_movie_format='h5', record_stim_framerate=None, display=None, **kwargs)[source]

Bases: stytra.experiments.Experiment

General class that runs an experiment.

Parameters
  • calibrator (Calibrator object) – (optional) Calibrator object to calibrate the stimulus display. If not set, a CrossCalibrator will be used.

  • display_config (dict) – (optional) Dictionary with specifications for the display. Possible key values are “full_screen” and “window_size”. gl_display : bool (False)

  • rec_stim_framerate (int) – (optional) Set to record a movie of the displayed visual stimulus. It specifies every how many frames one will be saved (set to 1 to record) all displayed frames. The final movie will be saved in the directory in an .h5 file.

  • offline (bool) – if stytra is used in offline analysis, stimulus is not displayed

sig_data_saved
start_experiment()[source]

Start the experiment creating GUI and initialising metadata.

restore_window_state()[source]
make_window()[source]

Make experiment GUI, defined in children depending on experiments.

start_protocol()[source]

Start the protocol from the ProtocolRunner. Before that, send a a notification and if required communicate with the microscope to synchronize and read configuration.

save_data()[source]
show_stimulus_screen(full_screen=False)[source]

Open window to display the visual stimulus and make it full-screen if necessary.

Parameters

full_screen – (Default value = True)