ibllib.io.raw_daq_loaders

Loader functions for various DAQ data formats.

Functions

correct_counter_discontinuities

Correct over- and underflow wrap around values for DAQ counter channel.

extract_sync_timeline

Load sync channels from a timeline object.

load_channels_tdms

Note: This currently cannot deal with arbitrary groups.

load_raw_daq_tdms

Load a raw DAQ TDMS file.

load_sync_tdms

Load a sync channels from a raw DAQ TDMS file.

load_timeline_sync_and_chmap

Load the sync and channel map from disk.

timeline_get_channel

Given a timeline object, returns the vector of values recorded from a given channel name.

timeline_meta2chmap

Convert a timeline meta object to a sync channel map.

timeline_meta2wiring

Given a timeline meta data object, return a dictionary of wiring info.

load_raw_daq_tdms(path) TdmsFile[source]

Load a raw DAQ TDMS file.

Parameters:

path (str, pathlib.Path) – The location of the .tdms file to laod.

Returns:

The loaded TDMS object.

Return type:

nptdms.tdms.TdmsFile

load_channels_tdms(path, chmap=None)[source]

Note: This currently cannot deal with arbitrary groups.

Parameters:
  • path (str, pathlib.Path) – The file or folder path of the raw TDMS data file.

  • chmap (dictionary mapping devices names to channel codes: example {"photometry": 'AI0', 'bpod': 'AI1'}) – if None, will read all of available channel from the DAQ

load_sync_tdms(path, sync_map, fs=None, threshold=2.5, floor_percentile=10)[source]

Load a sync channels from a raw DAQ TDMS file.

Parameters:
  • path (str, pathlib.Path) – The file or folder path of the raw TDMS data file.

  • sync_map (dict) – A map of channel names and channel IDs.

  • fs (float) – Sampling rate in Hz.

  • threshold (float) – The threshold for applying to analogue channels

  • floor_percentile (float) – 10% removes the percentile value of the analog trace before thresholding. This is to avoid DC offset drift.

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.

correct_counter_discontinuities(raw, overflow=4294967296)[source]

Correct over- and underflow wrap around values for DAQ counter channel.

Parameters:
  • raw (numpy.array) – An array of counts.

  • overflow (int) – The maximum representable value of the data before it was cast to float64.

Returns:

An array of counts with the over- and underflow discontinuities removed.

Return type:

numpy.array

load_timeline_sync_and_chmap(alf_path, chmap=None, timeline=None, save=True)[source]

Load the sync and channel map from disk.

If the sync files do not exist, they are extracted from the raw DAQ data and saved.

Parameters:
  • alf_path (str, pathlib.Path) – The folder containing the sync file and raw DAQ data.

  • chmap (dict) – An optional channel map, otherwise extracted based on the union of timeline meta data and default extractor channel map names.

  • timeline (dict) – An optional timeline object, otherwise is loaded from alf_path.

  • save (bool) – If true, save the sync files if they don’t already exist.

Returns:

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

  • dict, optional – A map of channel names and their corresponding indices for sync channels, if chmap is None.

extract_sync_timeline(timeline, chmap=None, floor_percentile=10, threshold=None)[source]

Load sync channels from a timeline object.

Note: Because the scan frequency is typically faster than the sample rate, the position and edge count channels may detect more than one front between samples. Therefore for these, the raw data is more accurate than the extracted polarities.

Parameters:
  • timeline (dict, str, pathlib.Path) – A timeline object or the file or folder path of the _timeline_DAQdata files.

  • chmap (dict) – A map of channel names and channel IDs.

  • floor_percentile (float) – 10% removes the percentile value of the analog trace before thresholding. This is to avoid DC offset drift.

  • threshold (float, dict of str: float) – The threshold for applying to analogue channels. If None, take mean after subtracting floor percentile offset.

Returns:

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

  • dict, optional – A map of channel names and their corresponding indices for sync channels, if chmap is None.

timeline_meta2wiring(path, save=False)[source]

Given a timeline meta data object, return a dictionary of wiring info.

Parameters:
  • path (str, pathlib.Path) – The path of the timeline meta file, _timeline_DAQdata.meta.

  • save (bool) – If true, save the timeline wiring file in the same location as the meta file, _timeline_DAQData.wiring.json.

Returns:

  • dict – A dictionary with base keys {‘SYSTEM’, ‘SYNC_WIRING_DIGITAL’, ‘SYNC_WIRING_ANALOG’}, the latter of which contain maps of channel names and their IDs.

  • pathlib.Path – If save=True, returns the path of the wiring file.

timeline_meta2chmap(meta, exclude_channels=None, include_channels=None)[source]

Convert a timeline meta object to a sync channel map.

Parameters:
  • meta (dict) – A loaded timeline metadata file, i.e. _timeline_DAQdata.meta.

  • exclude_channels (list) – An optional list of channels to exclude from the channel map.

  • include_channels (list) – An optional list of channels to include from the channel map, takes priority over the exclude list.

Returns:

A map of channel names and their corresponding indices for sync channels.

Return type:

dict

timeline_get_channel(timeline, channel_name)[source]

Given a timeline object, returns the vector of values recorded from a given channel name.

Parameters:
  • timeline (one.alf.io.AlfBunch) – A loaded timeline object.

  • channel_name (str) – The name of a channel to extract.

Returns:

The channel data.

Return type:

numpy.array