ibllib.io.extractors.ephys_fpga

Data extraction from raw FPGA output Complete FPGA data extraction depends on Bpod extraction

Functions

data_for_keys

Check keys exist in 'data' dict and contain values other than None

extract_all

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

extract_behaviour_sync

Extract task related event times from the sync.

extract_sync

Reads ephys binary file (s) and extract sync within the binary file folder Assumes ephys data is within a raw_ephys_data folder

extract_wheel_sync

Extract wheel positions and times from sync fronts dictionary for all 16 channels.

get_ibl_sync_map

Gets default channel map for the version/binary file type combination

get_main_probe_sync

From 3A or 3B multiprobe session, returns the main probe (3A) or nidq sync pulses with the attached channel map (default chmap if none)

get_protocol_period

param session_path:

The absolute session path, i.e. '/path/to/subject/yyyy-mm-dd/nnn'.

get_sync_and_chn_map

Return sync and channel map for session based on collection where main sync is stored.

get_sync_fronts

Return the sync front polarities and times for a given channel.

get_wheel_positions

Gets the wheel position from synchronisation pulses

load_channel_map

Load syncing channel map for session path and collection

load_sync

Load sync files from session path and collection.

Classes

FpgaTrials

data_for_keys(keys, data)[source]

Check keys exist in ‘data’ dict and contain values other than None

get_ibl_sync_map(ef, version)[source]

Gets default channel map for the version/binary file type combination

Parameters:

ef – ibllib.io.spikeglx.glob_ephys_file dictionary with field ‘ap’ or ‘nidq’

Returns:

channel map dictionary

get_sync_fronts(sync, channel_nb, tmin=None, tmax=None)[source]

Return the sync front polarities and times for a given channel.

Parameters:
  • sync (dict) – ‘polarities’ of fronts detected on sync trace for all 16 channels and their ‘times’.

  • channel_nb (int) – The integer corresponding to the desired sync channel.

  • tmin (float) – The minimum time from which to extract the sync pulses.

  • tmax (float) – The maximum time up to which we extract the sync pulses.

Returns:

Channel times and polarities.

Return type:

Bunch

extract_wheel_sync(sync, chmap=None, tmin=None, tmax=None)[source]

Extract wheel positions and times from sync fronts dictionary for all 16 channels. Output position is in radians, mathematical convention.

Parameters:
  • sync (dict) – ‘polarities’ of fronts detected on sync trace for all 16 chans and their ‘times’

  • chmap (dict) – Map of channel names and their corresponding index. Default to constant.

  • tmin (float) – The minimum time from which to extract the sync pulses.

  • tmax (float) – The maximum time up to which we extract the sync pulses.

Returns:

  • np.array – Wheel timestamps in seconds.

  • np.array – Wheel positions in radians.

extract_behaviour_sync(sync, chmap=None, display=False, bpod_trials=None, tmin=None, tmax=None)[source]

Extract task related event times from the sync.

Parameters:
  • sync (dict) – ‘polarities’ of fronts detected on sync trace for all 16 chans and their ‘times’

  • chmap (dict) – Map of channel names and their corresponding index. Default to constant.

  • display (bool, matplotlib.pyplot.Axes) – Show the full session sync pulses display

  • bpod_trials (dict) – The same trial events as recorded through Bpod. Assumed to contain an ‘intervals_bpod’ key.

  • tmin (float) – The minimum time from which to extract the sync pulses.

  • tmax (float) – The maximum time up to which we extract the sync pulses.

Returns:

A map of trial event timestamps.

Return type:

dict

extract_sync(session_path, overwrite=False, ephys_files=None, namespace='spikeglx')[source]

Reads ephys binary file (s) and extract sync within the binary file folder Assumes ephys data is within a raw_ephys_data folder

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

  • overwrite – Bool on re-extraction, forces overwrite instead of loading existing files

Returns:

list of sync dictionaries

get_wheel_positions(sync, chmap, tmin=None, tmax=None)[source]

Gets the wheel position from synchronisation pulses

Parameters:
  • sync (dict) – A dictionary with keys (‘times’, ‘polarities’, ‘channels’), containing the sync pulses and the corresponding channel numbers.

  • chmap (dict[str, int]) – A map of channel names and their corresponding indices.

  • tmin (float) – The minimum time from which to extract the sync pulses.

  • tmax (float) – The maximum time up to which we extract the sync pulses.

Returns:

  • Bunch – A dictionary with keys (‘timestamps’, ‘position’), containing the wheel event timestamps and position in radians

  • Bunch – A dictionary of detected movement times with keys (‘intervals’, ‘peakAmplitude’, ‘peakVelocity_times’).

get_main_probe_sync(session_path, bin_exists=False)[source]

From 3A or 3B multiprobe session, returns the main probe (3A) or nidq sync pulses with the attached channel map (default chmap if none)

Parameters:
  • session_path (str, pathlib.Path) – The absolute session path, i.e. ‘/path/to/subject/yyyy-mm-dd/nnn’.

  • bin_exists (bool) – Whether there is a .bin file present.

Returns:

  • one.alf.io.AlfBunch – A dictionary with keys (‘times’, ‘polarities’, ‘channels’), containing the sync pulses and the corresponding channel numbers.

  • dict – A map of channel names and their corresponding indices.

get_protocol_period(session_path, protocol_number, bpod_sync)[source]
Parameters:
  • session_path (str, pathlib.Path) – The absolute session path, i.e. ‘/path/to/subject/yyyy-mm-dd/nnn’.

  • protocol_number (int) – The order that the protocol was run in.

  • bpod_sync (dict) – The sync times and polarities for Bpod BNC1.

Returns:

  • float – The time of the detected spacer for the protocol number.

  • float, None – The time of the next detected spacer or None if this is the last protocol run.

class FpgaTrials(*args, bpod_trials=None, bpod_extractor=None, **kwargs)[source]

Bases: BaseExtractor

save_names = ('_ibl_trials.intervals_bpod.npy', '_ibl_trials.goCueTrigger_times.npy', None, None, None, None, None, None, None, '_ibl_trials.stimOff_times.npy', None, None, None, '_ibl_trials.quiescencePeriod.npy', '_ibl_trials.table.pqt', '_ibl_wheel.timestamps.npy', '_ibl_wheel.position.npy', '_ibl_wheelMoves.intervals.npy', '_ibl_wheelMoves.peakAmplitude.npy')
var_names = ('intervals_bpod', 'goCueTrigger_times', 'stimOnTrigger_times', 'stimOffTrigger_times', 'stimFreezeTrigger_times', 'errorCueTrigger_times', 'errorCue_times', 'itiIn_times', 'stimFreeze_times', 'stimOff_times', 'valveOpen_times', 'phase', 'position', 'quiescence', 'table', 'wheel_timestamps', 'wheel_position', 'wheelMoves_intervals', 'wheelMoves_peakAmplitude')
bpod_rsync_fields = ('intervals', 'response_times', 'goCueTrigger_times', 'stimOnTrigger_times', 'stimOffTrigger_times', 'stimFreezeTrigger_times', 'errorCueTrigger_times')
bpod_fields = ('feedbackType', 'choice', 'rewardVolume', 'contrastLeft', 'contrastRight', 'probabilityLeft', 'intervals_bpod', 'phase', 'position', 'quiescence')

The Bpod events to synchronize (must be present in sync channel map).

Type:

str

sync_field = 'intervals'
get_wheel_positions(*args, **kwargs)[source]

Extract wheel and wheelMoves objects.

This method is called by the main extract method and may be overloaded by subclasses.

extract_all(session_path, sync_collection='raw_ephys_data', save=True, save_path=None, task_collection='raw_behavior_data', protocol_number=None, **kwargs)[source]
For the IBL ephys task, reads ephys binary file and extract:
  • sync

  • wheel

  • behaviour

  • video time stamps

Parameters:
  • session_path (str, pathlib.Path) – The absolute session path, i.e. ‘/path/to/subject/yyyy-mm-dd/nnn’.

  • sync_collection (str) – The session subdirectory where the sync data are located.

  • save (bool) – If true, save the extracted files to save_path.

  • task_collection (str) – The location of the behaviour protocol data.

  • save_path (str, pathlib.Path) – The save location of the extracted files, defaults to the alf directory of the session path.

  • protocol_number (int) – The order that the protocol was run in.

  • **kwargs – Optional extractor keyword arguments.

Returns:

  • list – The extracted data.

  • list of pathlib.Path, None – If save is True, a list of file paths to the extracted data.

get_sync_and_chn_map(session_path, sync_collection)[source]

Return sync and channel map for session based on collection where main sync is stored.

Parameters:
  • session_path (str, pathlib.Path) – The absolute session path, i.e. ‘/path/to/subject/yyyy-mm-dd/nnn’.

  • sync_collection (str) – The session subdirectory where the sync data are located.

Returns:

  • one.alf.io.AlfBunch – A dictionary with keys (‘times’, ‘polarities’, ‘channels’), containing the sync pulses and the corresponding channel numbers.

  • dict – A map of channel names and their corresponding indices.

load_channel_map(session_path, sync_collection)[source]

Load syncing channel map for session path and collection

Parameters:
  • session_path (str, pathlib.Path) – The absolute session path, i.e. ‘/path/to/subject/yyyy-mm-dd/nnn’.

  • sync_collection (str) – The session subdirectory where the sync data are located.

Returns:

A map of channel names and their corresponding indices.

Return type:

dict

load_sync(session_path, sync_collection)[source]

Load sync files from session path and collection.

Parameters:
  • session_path (str, pathlib.Path) – The absolute session path, i.e. ‘/path/to/subject/yyyy-mm-dd/nnn’.

  • sync_collection (str) – The session subdirectory where the sync data are located.

Returns:

A dictionary with keys (‘times’, ‘polarities’, ‘channels’), containing the sync pulses and the corresponding channel numbers.

Return type:

one.alf.io.AlfBunch