-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add draft loaders for suite2p processed data using pynapple 🍍 and NWB
- Loading branch information
1 parent
2d0f8ec
commit 200f1c5
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pynapple as nap | ||
from skimage.measure import find_contours | ||
|
||
from derotation.postprocessing.neuropil_subtraction import neuropil_subtraction | ||
|
||
|
||
def load_suite2p_data(path: Path) -> nap.NWBFile: | ||
suite2p_data = nap.load_file(path) | ||
return suite2p_data | ||
|
||
|
||
def get_dff(suite2p_data: nap.NWBFile) -> tuple: | ||
raw_fluorescence = suite2p_data["RoiResponseSeries"] | ||
|
||
neuropil = suite2p_data["Neuropil"] | ||
|
||
dff, r = neuropil_subtraction( | ||
raw_fluorescence[:].values.T, neuropil[:].values.T | ||
) | ||
|
||
dff = nap.Tsd(t=raw_fluorescence.t, d=dff.T) | ||
timebase = raw_fluorescence.t | ||
|
||
return dff, timebase | ||
|
||
|
||
def get_plane_segmentation(suite2p_data: nap.NWBFile) -> tuple: | ||
plane_seg = ( | ||
suite2p_data.nwb.processing["ophys"] | ||
.data_interfaces["ImageSegmentation"] | ||
.plane_segmentations["PlaneSegmentation"] | ||
) | ||
|
||
ROI_centroids = plane_seg.ROICentroids[:] | ||
is_cell = plane_seg.Accepted[:] | ||
labels = plane_seg.image_mask[:] | ||
|
||
contours = [find_contours(c)[0] for c in labels[is_cell.astype(bool)]] | ||
|
||
return ROI_centroids, is_cell, labels, contours | ||
|
||
|
||
def load_registered_binary(path: Path, shape: tuple) -> np.memmap: | ||
registered = np.memmap(path, shape=shape, dtype="int16") | ||
return registered |