ibllib.io.extractors.mesoscope

Mesoscope (timeline) data extraction.

Functions

patch_imaging_meta

Patch imaging metadata for compatibility across versions.

plot_timeline

Plot the timeline data.

Classes

MesoscopeSyncTimeline

Extraction of mesoscope imaging times.

TimelineTrials

Similar extraction to the FPGA, however counter and position channels are treated differently.

patch_imaging_meta(meta: dict) dict[source]

Patch imaging metadata for compatibility across versions.

A copy of the dict is NOT returned.

Parameters:

meta (dict) – A folder path that contains a rawImagingData.meta file.

Returns:

The loaded metadata file, updated to the most recent version.

Return type:

dict

plot_timeline(timeline, channels=None, raw=True)[source]

Plot the timeline data.

Parameters:
  • timeline (one.alf.io.AlfBunch) – The timeline data object.

  • channels (list of str) – An iterable of channel names to plot.

  • raw (bool) – If true, plot the raw DAQ samples; if false, apply TTL thresholds and plot changes.

Returns:

  • matplotlib.pyplot.Figure – The figure containing timeline subplots.

  • list of matplotlib.pyplot.Axes – The axes for each timeline channel plotted.

class TimelineTrials(*args, sync_collection='raw_sync_data', **kwargs)[source]

Bases: FpgaTrials

Similar extraction to the FPGA, however counter and position channels are treated differently.

timeline = None
extract_wheel_sync(ticks=1024, radius=1, coding='x4', tmin=None, tmax=None)[source]

Gets the wheel position from Timeline counter channel.

Parameters:
  • ticks (int) – Number of ticks corresponding to a full revolution (1024 for IBL rotary encoder).

  • radius (float) – Radius of the wheel. Defaults to 1 for an output in radians.

  • coding (str {'x1', 'x2', 'x4'}) – Rotary encoder encoding (IBL default is x4).

  • 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.

get_wheel_positions(ticks=1024, radius=1, coding='x4', tmin=None, tmax=None, display=False, **kwargs)[source]

Gets the wheel position and detected movements from Timeline counter channel.

Called by the super class extractor (FPGATrials._extract).

Parameters:
  • ticks (int) – Number of ticks corresponding to a full revolution (1024 for IBL rotary encoder).

  • radius (float) – Radius of the wheel. Defaults to 1 for an output in radians.

  • coding (str {'x1', 'x2', 'x4'}) – Rotary encoder encoding (IBL default is x4).

  • 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.

  • display (bool) – If true, plot the wheel positions from bpod and the DAQ.

Returns:

  • dict – wheel object with keys (‘timestamps’, ‘position’).

  • dict – wheelMoves object with keys (‘intervals’ ‘peakAmplitude’).

get_valve_open_times(display=False, threshold=-2.5, floor_percentile=10, driver_ttls=None)[source]

Get the valve open times from the raw timeline voltage trace.

Parameters:
  • display (bool) – Plot detected times on the raw voltage trace.

  • 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.

  • driver_ttls (numpy.array) – An optional array of driver TTLs to use for assigning with the valve times.

Returns:

  • numpy.array – The detected valve open times.

  • TODO extract close times too

class MesoscopeSyncTimeline(session_path, n_FOVs)[source]

Bases: BaseExtractor

Extraction of mesoscope imaging times.

rawImagingData = None
var_names = ('mpci_times', 'mpciStack_timeshift')
save_names = ('mpci.times.npy', 'mpciStack.timeshift.npy')

The raw imaging meta data and frame times

Type:

one.alf.io.AlfBunch

get_bout_edges(frame_times, collections=None, events=None, min_gap=1.0, display=False)[source]

Return an array of edge times for each imaging bout corresponding to a raw_imaging_data collection.

Parameters:
  • frame_times (numpy.array) – An array of all neural frame count times.

  • collections (iterable of str) – A set of raw_imaging_data collections, used to extract selected imaging periods.

  • events (pandas.DataFrame) – A table of UDP event times, corresponding to times when recordings start and end.

  • min_gap (float) – If start or end events not present, split bouts by finding gaps larger than this value.

  • display (bool) – If true, plot the detected bout edges and raw frame times.

Returns:

An array of imaging bout intervals.

Return type:

numpy.array

static get_timeshifts(raw_imaging_meta)[source]

Calculate the time shifts for each field of view (FOV) and the relative offsets for each scan line.

Parameters:

raw_imaging_meta (dict) – Extracted ScanImage meta data (_ibl_rawImagingData.meta.json).

Returns:

  • list of numpy.array – A list of arrays, one per FOV, containing indices of each image scan line.

  • numpy.array – An array of FOV time offsets (one value per FOV) relative to each frame acquisition time.

  • list of numpy.array – A list of arrays, one per FOV, containing the time offsets for each scan line, relative to each FOV offset.