Function to extract data of an experiment from 3rd party programs
from nbdev.showdoc import *
%load_ext autoreload
%autoreload 2

To align timeseries of an experiment, we need to read logs and import data produced by 3rd party softwares used during the experiment. It includes:

  • QDSpy logging
  • Numpy arrays of the stimuli
  • SpykingCircus spike sorting refined with Phy
  • Eye tracking results from MaskRCNN

get_QDSpy_logs[source]

get_QDSpy_logs(log_dir)

Factory function to generate QDSpy_log objects from all the QDSpy logs of the folder log_dir

class QDSpy_log[source]

QDSpy_log(log_path)

Class defining a QDSpy log. It reads the log it represent and extract the stimuli information from it:

  • Start and end time
  • Parameters like the md5 key
  • Frame delays

class Stimulus[source]

Stimulus(start)

Stimulus object containing information about it's presentation.

  • start_time : a datetime object)
  • stop_time : a datetime object)
  • parameters : Parameters extracted from the QDSpy
  • md5 : The md5 hash of that compiled version of the stimulus
  • name : The name of the stimulus

To read QDSpy logs of your experiment, simply provide the folder containing the log you want to read to get_QDSpy_logs

 

It returns a list fo the QDSpy logs. Stimuli are contained in a list inside each log:

 

The stimuli objects contains informations on how their display went:

# print(stim.name, stim.start_time, stim.frame_delay, stim.md5)

Some stimuli are generated shortly before every display. [`get_synced_file`](/theonerig/synchro.nested_stims.html#get_synced_file) matches the compiled stimuli from a directory of your choice to the stimulus (stim_id) you are looking at, based on timestamps.

get_synced_file[source]

get_synced_file(stim_list_dir, stim_id)

Find the stimulus in the stimulus list directory that is temporally closest to the stimulus in the log. Works based on the modification time of the stimulus (i.e. expects stimulus to be compiled shortly before display). Input:

- stim_list_dir: fullpath to stimuli, string
- stim_id: stimulus read from QDSpy log, theonerig.synchro.extracting.Stimulus object

Output:

- stim: filename of the stimulus that needs loading, str

unpack_stim_npy[source]

unpack_stim_npy(npy_dir, md5_hash)

Find the stimuli of a given hash key in the npy stimulus folder. The stimuli are in a compressed version comprising three files. inten for the stimulus values on the screen, marker for the values of the marker read by a photodiode to get the stimulus timing during a record, and an optional shader that is used to specify informations about a shader when used, like for the moving gratings.

 

To unpack the stimulus values, provide the folder of the numpy arrays and the hash of the stimulus:

 

Unpacked is a tuple, where the first element is the intensity of shape (n_frames, n_colors, y, x)

 

The second element of the tuple repesents the marker values for the timing. QDSpy defaults are zero and ones, but I used custom red squares taking intensities [50,100,150,200,250] to time with five different signals

 

Each stimulus is also starting with a barcode, of the form:

0 0 0 0 0 0 4 0 4*[1-4] 0 4*[1-4] 0 4*[1-4] 0 4*[1-4] 0 4 0 0 0 0 0 0

and ends with 0 0 0 0 0 0

extract_spyking_circus_results[source]

extract_spyking_circus_results(dir_, record_basename)

Extract the good cells of a record. Overlap with phy_results_dict.

extract_best_pupil[source]

extract_best_pupil(fn)

From results of MaskRCNN, go over all or None pupil detected and select the best pupil. Each pupil returned is (x,y,width,height,angle,probability)

stack_len_extraction[source]

stack_len_extraction(stack_info_dir)

Extract from ImageJ macro directives the size of the stacks acquired.