Module for feeding ThorLabs imaging datasets into a 2p imaging analysis pipeline
(c) 2015 C. Schmidt-Hieber GPLv3
pipeline2p.ThorExperiment(fn2p, ch2p='A', area2p=None, fnsync=None, fnvr=None, roi_subset='', mc_method='hmmc', detrend=False, nrois_init=200, roi_translate=None, root_path='', ftype='thor', dx=None, dt=None, seg_method='cnmf', maxtime=None, ignore_sync_errors=False)[source]¶Helper class to feed ThorLabs imaging datasets into a 2p imaging analysis pipeline
fn2p¶str – File path (relative to root_path) leading to directory that contains tiff series
ch2p¶str, optional – Channel. Default: “A”
area2p¶str, optional – Brain area code (e.g. “CA1”). Default: None
fnsync¶str, optional – Thorsync directory name. Default: None
fnvr¶str, optional – VR file name trunk. Default: None
roi_subset¶str, optional – String appended to roi label to distinguish between roi subsets. Default: “”
mc_method¶str, optional – Motion correction method. One of “hmmc”, “dft”, “hmmcres”, “hmmcframe”, “hmmcpx”, “calblitz”. Default: “hmmc”
detrend¶bool, optional – Whether to detrend fluorescence traces. Default: False
nrois_init¶int, optional – Estimate of the number of ROIs. Default: 200
roi_translate¶2-tuple of ints, optional – Apply ROI translation in x and y. Default: None
root_path¶str, optional – Root directory leading to fn2p. Default: “”
seg_method¶str, optional – One of “thunder” (ROIs are identified by thunder’s ICA), “sima” (ROIs are identified by SIMA’s stICA), “ij” (an ImageJ RoiSet is used), “cnmf” (constrained non-negative matrix factorization). Default: “cnmf”
maxtime¶float, optional – Limit data to maxtime. Default: None
ignore_sync_errors¶bool, optional – Whether to ignore mismatch between imaging and VR recording file lengths. Default: False
to_haussio(mc=False)[source]¶Convert experiment to haussio.HaussIO
| Parameters: | mc (bool, optional) – Use motion corrected images. Default: False |
|---|---|
| Returns: | dataset – A haussio.HaussIO instance |
| Return type: | haussio.HaussIO |
to_sima(mc=False, haussio_data=None)[source]¶Convert experiment to sima.ImagingDataset
| Parameters: |
|
|---|---|
| Returns: | dataset – A sima.ImagingDataset instance |
| Return type: | sima.ImagingDataset |
pipeline2p.activity_level(data, infer_threshold=0.15, roi_subset='')[source]¶Determine the ratio of active over inactive neurons
| Parameters: |
|
|---|---|
| Returns: | level – Number of active and inactive neurons |
| Return type: | int, int |
pipeline2p.contiguous_stationary(speed, speed_time, speed_thr, time_thr)[source]¶Find contiguous stationary periods
| Parameters: |
|
|---|---|
| Returns: | running_mask – Boolean mask denoting stationary periods |
| Return type: |
pipeline2p.eta(measured, vrdict, evcodelist)[source]¶Compute event-triggered average of fluorescence data
| Parameters: |
|
|---|
pipeline2p.extract_rois(signal_label, dataset, rois, data, haussio_data)[source]¶Extract fluorescence data from ROIs
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.extract_signals(signal_label, rois, data, haussio_data, infer=True)[source]¶Extract fluorescence data from ROIs
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.get_rois_cnmf(data, haussio_data, vrdict, speed_thr, time_thr, nrois_init, roi_iceberg=0.9)[source]¶Identify ROIs, extract fluorescence and infer spikes using constrained non-negative matrix factorization (CNMF)
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.get_rois_ij(data, haussio_data, infer=True)[source]¶Extract fluorescence data from ImageJ ROIs
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.get_rois_sima(data, haussio_data, infer=True)[source]¶Extract fluorescence data from ROIs that are identified by sima’s stICA
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.get_rois_thunder(data, haussio_data, sc, infer=True, speed=None, nrois_init=100)[source]¶Extract fluorescence data from ROIs that are identified by thunder’s ICA. If running speed is available, ROIs will be determined during running periods. Otherwise, MAXFRAMES_ICA at the beginning of the recording will be used.
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.get_vr_maps(data, measured, spikes, vrdict, method)[source]¶Read and assemble VR data
| Parameters: |
|
|---|---|
| Returns: | mapdict – Dictionary with processed VR data. Contains: “t_2p”: Time points of 2p frames, shape (nt2p) “DFoF_2p”: Fluorescence for each roi, shape (nrois, nt2p) “spikes_2p”: Spike inference values for each roi, shape (nrois, nt2p) “t_vr”: Time points of VR values, shape (ntvr) “posy_vr”: Position in VR along y, shape (ntvr) “speed_vr”: Speed in VR, shape (ntvr) “events”: List of events, each containing the time of the event (event.time) and a 2-character event code (event.code) “t_ev_matlab”: List of event times for processing with MATLAB “events_matlab”: Numerical event codes for processing with MATLAB “fluomap”: Mean Fluorescence values against space, shape (nrois, 2, nbins) fluomap[:, 0, :] is position along y fluomap[:, 1, :] is fluorescence along y “infermap”: Spike inference values against space, shape (nrois, 2, nbins) infermap[:, 0, :] is position along y infermap[:, 1, :] is fluorescence along y |
| Return type: | dict |
pipeline2p.infer_spikes(dataset, signal_label, measured)[source]¶Perform spike inference
| Parameters: |
|
|---|---|
| Returns: |
|
pipeline2p.norm(sig)[source]¶Normalize data to have range [0,1]
| Parameters: | sig (numpy.ndarray) – Data to be normalized |
|---|---|
| Returns: | norm – Normalized data |
| Return type: | numpy.ndarray |
pipeline2p.plot_rois(rois, measured, haussio_data, zproj, data_path, pdf_suffix='', spikes=None, infer_threshold=0.15, region='', mapdict=None, lopass=1.0, plot_events=False, minimaps=None, dpi=1200, selected_rois=None, decoded=None)[source]¶Plot ROIs on top of z-projected image, extracted fluorescence, spike inference, fluorescence and spike inference against position (if available)
| Parameters: |
|
|---|
pipeline2p.process_data(data, detrend=False, base_fraction=0.2, zscore=True)[source]¶Compute Delta F / F_0 and detrend if required
| Parameters: |
|
|---|---|
| Returns: | ret_data – Processed data |
| Return type: |
pipeline2p.thor_extract_roi(data, sc=None, infer=True, infer_threshold=0.15, selected_rois=None, roi_iceberg=0.9, decoded_only=False)[source]¶Extract and process fluorescence data from ROIs
| Parameters: |
|
|---|
pipeline2p.thor_preprocess(data, ffmpeg='ffmpeg', compress=False)[source]¶Read in ThorImage dataset, apply motion correction, export motion-corrected tiffs, produce movie of corrected and uncorrected data
| Parameters: |
|
|---|
pipeline2p.xcorr(data, chan, roi_subset1='DG', roi_subset2='CA3', infer_threshold=0.15)[source]¶Compute cross correlation between fluorescence extracted from two roi subsets
| Parameters: |
|
|---|---|
| Returns: | high_xcs – List of roi indices with xcorr values > 0.5 |
| Return type: | list of 2-tuple of ints |
pipeline2p.ThorExperiment(fn2p, ch2p='A', area2p=None, fnsync=None, fnvr=None, roi_subset='', mc_method='hmmc', detrend=False, nrois_init=200, roi_translate=None, root_path='', ftype='thor', dx=None, dt=None, seg_method='cnmf', maxtime=None, ignore_sync_errors=False)[source]Helper class to feed ThorLabs imaging datasets into a 2p imaging analysis pipeline
fn2pstr – File path (relative to root_path) leading to directory that contains tiff series
ch2pstr, optional – Channel. Default: “A”
area2pstr, optional – Brain area code (e.g. “CA1”). Default: None
fnsyncstr, optional – Thorsync directory name. Default: None
fnvrstr, optional – VR file name trunk. Default: None
roi_subsetstr, optional – String appended to roi label to distinguish between roi subsets. Default: “”
mc_methodstr, optional – Motion correction method. One of “hmmc”, “dft”, “hmmcres”, “hmmcframe”, “hmmcpx”, “calblitz”. Default: “hmmc”
detrendbool, optional – Whether to detrend fluorescence traces. Default: False
nrois_initint, optional – Estimate of the number of ROIs. Default: 200
roi_translate2-tuple of ints, optional – Apply ROI translation in x and y. Default: None
root_pathstr, optional – Root directory leading to fn2p. Default: “”
seg_methodstr, optional – One of “thunder” (ROIs are identified by thunder’s ICA), “sima” (ROIs are identified by SIMA’s stICA), “ij” (an ImageJ RoiSet is used), “cnmf” (constrained non-negative matrix factorization). Default: “cnmf”
maxtimefloat, optional – Limit data to maxtime. Default: None
ignore_sync_errorsbool, optional – Whether to ignore mismatch between imaging and VR recording file lengths. Default: False
to_haussio(mc=False)[source]Convert experiment to haussio.HaussIO
| Parameters: | mc (bool, optional) – Use motion corrected images. Default: False |
|---|---|
| Returns: | dataset – A haussio.HaussIO instance |
| Return type: | haussio.HaussIO |
to_sima(mc=False, haussio_data=None)[source]Convert experiment to sima.ImagingDataset
| Parameters: |
|
|---|---|
| Returns: | dataset – A sima.ImagingDataset instance |
| Return type: | sima.ImagingDataset |