ibllib.io.extractors.camera

Camera extractor functions This module handles extraction of camera timestamps for both Bpod and FPGA.

Functions

align_with_audio

Groom the raw FPGA or Bpod camera timestamps using the frame embedded audio TTLs and frame counter.

attribute_times

Returns the values of the first array that correspond to those of the second.

extract_all

For the IBL ephys task, reads ephys binary file and extract:

extract_camera_sync

Extract camera timestamps from the sync matrix

get_video_length

Returns video length

groom_pin_state

Align the GPIO pin state to the FPGA audio TTLs.

Classes

CameraTimestampsBpod

Get the camera timestamps from the Bpod

CameraTimestampsCamlog

CameraTimestampsFPGA

extract_camera_sync(sync, chmap=None)[source]

Extract camera timestamps from the sync matrix

Parameters
  • sync – dictionary ‘times’, ‘polarities’ of fronts detected on sync trace

  • chmap – dictionary containing channel indices. Default to constant.

Returns

dictionary containing camera timestamps

get_video_length(video_path)[source]

Returns video length

Parameters

video_path – A path to the video

Returns

class CameraTimestampsFPGA(label, session_path=None)[source]

Bases: BaseExtractor

class CameraTimestampsCamlog(label, session_path=None)[source]

Bases: BaseExtractor

class CameraTimestampsBpod(*args, **kwargs)[source]

Bases: BaseBpodTrialsExtractor

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

save_names = '_ibl_leftCamera.times.npy'
var_names = 'left_camera_timestamps'
align_with_audio(timestamps, audio, pin_state, count, extrapolate_missing=True, display=False)[source]

Groom the raw FPGA or Bpod camera timestamps using the frame embedded audio TTLs and frame counter.

Parameters
  • timestamps – An array of raw FPGA or Bpod camera timestamps

  • audio – An array of FPGA or Bpod audio TTL times

  • pin_state – An array of camera pin states

  • count – An array of frame numbers

  • extrapolate_missing – If true and the number of timestamps is fewer than the number of

frame counts, the remaining timestamps are extrapolated based on the frame rate, otherwise they are NaNs :param display: Plot the resulting timestamps :return: The corrected frame timestamps

attribute_times(arr, events, tol=0.1, injective=True, take='first')[source]

Returns the values of the first array that correspond to those of the second.

Given two arrays of timestamps, the function will return the values of the first array that most likely correspond to the values of the second. For each of the values in the second array, the absolute difference is taken and the index of either the first sufficiently close value, or simply the closest one, is assigned.

If injective is True, once a value has been assigned, to a value it can’t be assigned to another. In other words there is a one-to-one mapping between the two arrays.

Parameters
  • arr – An array of event times to attribute to those in events

  • events – An array of event times considered a subset of arr

  • tol – The max absolute difference between values in order to be considered a match

  • injective – If true, once a value has been assigned it will not be assigned again

  • take – If ‘first’ the first value within tolerance is assigned; if ‘nearest’ the

closest value is assigned :returns Numpy array the same length as values

groom_pin_state(gpio, audio, ts, tolerance=2.0, display=False, take='first', min_diff=0.0)[source]

Align the GPIO pin state to the FPGA audio TTLs. Any audio TTLs not reflected in the pin state are removed from the dict and the times of the detected fronts are converted to FPGA time. At the end of this the number of GPIO fronts should equal the number of audio fronts.

Note

  • This function is ultra safe: we probably don’t need assign all the ups and down fronts

separately and could potentially even align the timestamps without removing the missed fronts - The input gpio and audio dicts may be modified by this function - For training sessions the frame rate is only 30Hz and the TTLs tend to be broken up by small gaps. Setting the min_diff to 5ms helps the timestamp assignment accuracy.

Parameters
  • gpio – array of GPIO pin state values

  • audio – dict of FPGA audio TTLs (see ibllib.io.extractors.ephys_fpga._get_sync_fronts)

  • ts – camera frame times

  • tolerance – two pulses need to be within this many seconds to be considered related

  • take – If ‘first’ the first value within tolerance is assigned; if ‘nearest’ the

closest value is assigned :param display: If true, the resulting timestamps are plotted against the raw audio signal :param min_diff: Audio TTL fronts less than min_diff seconds apart will be removed :returns: dict of GPIO FPGA front indices, polarities and FPGA aligned times :returns: audio times and polarities sans the TTLs not detected in the frame data :returns: frame times in FPGA time

extract_all(session_path, session_type=None, save=True, **kwargs)[source]
For the IBL ephys task, reads ephys binary file and extract:
  • video time stamps

Parameters
  • session_path – ‘/path/to/subject/yyyy-mm-dd/001’

  • session_type – the session type to extract, i.e. ‘ephys’, ‘training’ or ‘biased’. If

None the session type is inferred from the settings file. :param save: Bool, defaults to False :param kwargs: parameters to pass to the extractor :return: outputs, files