ibllib.io.extractors.training_trials

ALF extractors are a collection of functions that extract alf files from the PyBpod rig raw data.

Each DatasetType in the IBL pipeline should have one extractor function.

ibllib.io.extractors.training_trials.check_alf_folder(session_path)

Check if alf folder exists, creates it if it doesn’t.

Parameters:session_path (str) – absolute path of session folder
ibllib.io.extractors.training_trials.get_camera_timestamps(session_path, data=False, save=False, settings=False)

Get the camera timestamps from the Bpod

The camera events are logged only during the events not in between, so the times need to be interpolated

Parameters:
  • session_path – Absolute path of session folder
  • save – bool, optional
Returns:

numpy.ndarray

ibllib.io.extractors.training_trials.get_choice(session_path, save=False, data=False, settings=False)

Get the subject’s choice in every trial. Optional: saves _ibl_trials.choice.npy to alf folder.

Uses signed_contrast and trial_correct. -1 is a CCW turn (towards the left) +1 is a CW turn (towards the right) 0 is a no_go trial If a trial is correct the choice of the animal was the inverse of the sign of the position.

>>> choice[t] = -np.sign(position[t]) if trial_correct[t]
Parameters:
  • session_path (str) – absolute path of session folder
  • save (bool, optional) – wether to save the corresponding alf file to the alf folder, defaults to False
Returns:

numpy.ndarray

Return type:

dtype(‘int64’)

ibllib.io.extractors.training_trials.get_contrastLR(session_path, save=False, data=False, settings=False)

Get left and right contrasts from raw datafile. Optionally, saves _ibl_trials.contrastLeft.npy and _ibl_trials.contrastRight.npy to alf folder.

Uses signed_contrast to create left and right contrast vectors.

Parameters:
  • session_path (str) – absolute path of session folder
  • save (bool, optional) – wether to save the corresponding alf file to the alf folder, defaults to False
Returns:

numpy.ndarray

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_feedbackType(session_path, save=False, data=False, settings=False)

Get the feedback that was delivered to subject. Optional: saves _ibl_trials.feedbackType.npy

Checks in raw datafile for error and reward state. Will raise an error if more than one of the mutually exclusive states have been triggered.

Sets feedbackType to -1 if error state was trigered (applies to no-go) Sets feedbackType to +1 if reward state was triggered

Parameters:
  • session_path (str) – absolute path of session folder
  • save (bool, optional) – wether to save the corresponding alf file to the alf folder, defaults to False
Returns:

numpy.ndarray

Return type:

dtype(‘int64’)

ibllib.io.extractors.training_trials.get_feedback_times(session_path, save=False, data=False, settings=False)

Get the times the water or error tone was delivered to the animal. Optional: saves _ibl_trials.feedback_times.npy

Gets reward and error state init times vectors, checks if theintersection of nans is empty, then merges the 2 vectors.

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – wether to save the corresponding alf file to the alf folder, defaults to False
  • save – bool, optional
Returns:

numpy.ndarray

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_goCueOnset_times(session_path, save=False, data=False, settings=False)

Get trigger times of goCue from state machine.

Current software solution for triggering sounds uses PyBpod soft codes. Delays can be in the order of 10’s of ms. This is the time when the command to play the sound was executed. To measure accurate time, either getting the sound onset from the future microphone OR the new xonar soundcard and setup developed by Sanworks guarantees a set latency (in testing).

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – bool, optional
Returns:

numpy.ndarray

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_goCueTrigger_times(session_path, save=False, data=False, settings=False)

Get trigger times of goCue from state machine.

Current software solution for triggering sounds uses PyBpod soft codes. Delays can be in the order of 10’s of ms. This is the time when the command to play the sound was executed. To measure accurate time, either getting the sound onset from xonar soundcard sync pulse (latencies may vary).

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – wether to save the corresponding alf file to the alf folder, defaults to False
  • save – bool, optional
Returns:

numpy.ndarray

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_intervals(session_path, save=False, data=False, settings=False)

Trial start to trial end. Trial end includes 1 or 2 seconds after feedback, (depending on the feedback) and 0.5 seconds of iti. Optional: saves _ibl_trials.intervals.npy

Uses the corrected Trial start and Trial end timpestamp values form PyBpod.

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – wether to save the corresponding alf file to the alf folder, defaults to False
  • save – bool, optional
Returns:

2D numpy.ndarray (col0 = start, col1 = end)

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_iti_duration(session_path, save=False, data=False, settings=False)

Calculate duration of iti from state timestamps. Optional: saves _ibl_trials.iti_duration.npy

Uses Trial end timestamp and get_response_times to calculate iti.

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – wether to save the corresponding alf file to the alf folder, defaults to False
  • save – bool, optional
Returns:

numpy.ndarray

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_repNum(session_path, save=False, data=False, settings=False)

Count the consecutive repeated trials. Optional: saves _ibl_trials.repNum.npy to alf folder.

Creates trial_repeated from trial[‘contrast’][‘type’] == ‘RepeatContrast’

>>> trial_repeated = [0, 1, 1, 0, 1, 0, 1, 1, 1, 0]
>>> repNum =         [0, 1, 2, 0, 1, 0, 1, 2, 3, 0]
Parameters:
  • session_path (str) – absolute path of session folder
  • save (bool, optional) – wether to save the corresponding alf file to the alf folder, defaults to False
Returns:

numpy.ndarray

Return type:

dtype(‘int64’)

ibllib.io.extractors.training_trials.get_response_times(session_path, save=False, data=False, settings=False)

Time (in absolute seconds from session start) when a response was recorded. Optional: saves _ibl_trials.response_times.npy

Uses the timestamp of the end of the closed_loop state.

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – wether to save the corresponding alf file to the alf folder, defaults to False
  • save – bool, optional
Returns:

numpy.ndarray

Return type:

dtype(‘float64’)

ibllib.io.extractors.training_trials.get_rewardVolume(session_path, save=False, data=False, settings=False)

Load reward volume delivered for each trial. Optional: saves _ibl_trials.rewardVolume.npy

Uses reward_current to accumulate the amount of

Parameters:
  • session_path (str) – Absolute path of session folder
  • save – wether to save the corresponding alf file to the alf folder, defaults to False
  • save – bool, optional
Returns:

numpy.ndarray

Return type:

dtype(‘int64’)

ibllib.io.extractors.training_trials.get_stimOn_times(session_path, save=False, data=False, settings=False)

Find the time of the statemachine command to turn on hte stim (state stim_on start or rotary_encoder_event2) Find the next frame change from the photodiodeafter that TS. Screen is not displaying anything until then. (Frame changes are in BNC1High and BNC1Low)

ibllib.io.extractors.training_trials.get_stimOn_times_ge5(session_path, data=False)

Find first and last stim_sync pulse of the trial. stimOn_times should be the first after the stim_on state. (Stim updates are in BNC1High and BNC1Low - frame2TTL device) Check that all trials have frame changes. Find length of stim_on_state [start, stop]. If either check fails the HW device failed to detect the stim_sync square change Substitute that trial’s missing or incorrect value with a NaN. return stimOn_times

ibllib.io.extractors.training_trials.get_stimOn_times_lt5(session_path, data=False)

Find the time of the statemachine command to turn on hte stim (state stim_on start or rotary_encoder_event2) Find the next frame change from the photodiodeafter that TS. Screen is not displaying anything until then. (Frame changes are in BNC1High and BNC1Low)