From 2ecab21fdd43411ff515504cff169fd29479dfb5 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Sun, 3 Dec 2023 14:56:54 +0100 Subject: [PATCH 1/4] fix custom widefield segmentation --- ...defield_processed_segmentationextractor.py | 56 ++++++++++--------- ...defield_processed_segmentationinterface.py | 26 +++++++-- ..._segmentation_images_blue_datainterface.py | 42 +++++++++----- ...egmentation_images_violet_datainterface.py | 20 +++---- 4 files changed, 88 insertions(+), 56 deletions(-) diff --git a/src/pinto_lab_to_nwb/widefield/extractors/widefield_processed_segmentationextractor.py b/src/pinto_lab_to_nwb/widefield/extractors/widefield_processed_segmentationextractor.py index 3b74312..fabcea6 100644 --- a/src/pinto_lab_to_nwb/widefield/extractors/widefield_processed_segmentationextractor.py +++ b/src/pinto_lab_to_nwb/widefield/extractors/widefield_processed_segmentationextractor.py @@ -2,7 +2,7 @@ from typing import Tuple import numpy as np -from neuroconv.utils import FolderPathType +from neuroconv.utils import FolderPathType, FilePathType from pymatreader import read_mat from roiextractors import SegmentationExtractor @@ -15,7 +15,10 @@ class WidefieldProcessedSegmentationExtractor(SegmentationExtractor): def __init__( self, - folder_path: FolderPathType, + info_mat_file_path: FilePathType, + roi_from_ref_mat_file_path: FilePathType, + vasculature_mask_file_path: FilePathType, + blue_pca_mask_file_path: FilePathType, ): """ The SegmentationExtractor for the downsampled (binned) Widefield imaging data. @@ -25,7 +28,6 @@ def __init__( - ROIfromRef.mat : contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. - vasculature_mask_2.mat : contains the vasculature mask on the downsampled (binned) session image. - blue_pca_vasculature_mask_2.mat : contains the PCA mask for the blue channel. - - violet_pca_vasculature_mask_2.mat.mat : contains the PCA mask for the violet channel. that contain the following variables: - The Allen area label for each binned pixel @@ -34,33 +36,28 @@ def __init__( Parameters ---------- - folder_path: FolderPathType - The path that points to the folder that contains the .mat files. + info_mat_file_path : FilePathType + The file path to the 'info.mat' file. + roi_from_ref_mat_file_path : FilePathType + The file that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. + vasculature_mask_file_path: FilePathType + The file that contains the vasculature mask on the downsampled (binned) session image. + blue_pca_mask_file_path: FilePathType + The file that contains the PCA mask for the blue channel. """ super().__init__() - self.folder_path = Path(folder_path) - - expected_files = [ - "info.mat", - "ROIfromRef.mat", - "vasculature_mask_2.mat", - "blue_pca_vasculature_mask_2.mat", - ] - mat_file_paths = list(self.folder_path.glob("*.mat")) - assert mat_file_paths, f"The .mat files are missing from {folder_path}." - # assert all expected files are in the folder_path - for expected_file in expected_files: - assert ( - self.folder_path / expected_file - ).exists(), f"The file {expected_file} is missing from {folder_path}." - - info_mat = read_mat(self.folder_path / "info.mat") + info_mat_file_path = Path(info_mat_file_path) + assert info_mat_file_path.exists(), f"The file '{info_mat_file_path}' does not exist." + + info_mat = read_mat(str(info_mat_file_path)) assert "info" in info_mat, f"Could not find 'info' struct in 'info.mat'." self._num_frames = info_mat["info"]["numFrames"] self._sampling_frequency = info_mat["info"]["frameRate"] - roi_mat = read_mat(self.folder_path / "ROIfromRef.mat") + roi_from_ref_mat_file_path = Path(roi_from_ref_mat_file_path) + assert roi_from_ref_mat_file_path.exists(), f"The file '{roi_from_ref_mat_file_path}' does not exist." + roi_mat = read_mat(str(roi_from_ref_mat_file_path)) assert "ROIcentroids" in roi_mat, f"Could not find 'ROIcentroids' in 'ROIfromRef.mat'." self._roi_locations = roi_mat[ "ROIcentroids" @@ -78,12 +75,16 @@ def __init__( self._dtype = self._image_masks.dtype # Contrast based vasculature mask - vasculature_mask = read_mat(self.folder_path / "vasculature_mask_2.mat") - assert "mask_binned" in vasculature_mask, f"Could not find 'mask_binned' in 'vasculature_mask_2.mat'." + vasculature_mask_file_path = Path(vasculature_mask_file_path) + assert vasculature_mask_file_path.exists(), f"The file '{vasculature_mask_file_path}' does not exist." + vasculature_mask = read_mat(str(vasculature_mask_file_path)) + assert "mask_binned" in vasculature_mask, f"Could not find 'mask_binned' in '{vasculature_mask_file_path}'." self._image_vasculature = vasculature_mask["mask_binned"] # PCA mask (separate for blue and violet) - pca_mask_blue = read_mat(self.folder_path / f"blue_pca_vasculature_mask_2.mat") + blue_pca_mask_file_path = Path(blue_pca_mask_file_path) + assert blue_pca_mask_file_path.exists(), f"The file '{blue_pca_mask_file_path}' does not exist." + pca_mask_blue = read_mat(str(blue_pca_mask_file_path)) assert "mask" in pca_mask_blue, f"Could not find 'mask' in 'blue_pca_vasculature_mask_2.mat'." self._image_pca_blue = pca_mask_blue["mask"] @@ -92,7 +93,8 @@ def _compute_image_masks(self, pixel_mask): num_rois = self.get_num_rois() image_mask = np.zeros(shape=(*self._image_size, num_rois), dtype=np.uint8) for roi_ind, pixel_mask_roi in enumerate(pixel_mask): - pixel_mask_roi = pixel_mask_roi[0] + if isinstance(pixel_mask_roi, list): + pixel_mask_roi = pixel_mask_roi[0] if len(pixel_mask_roi) == 0: # there are rois with no pixels continue diff --git a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py index 692e627..e27da11 100644 --- a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py +++ b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py @@ -2,7 +2,7 @@ from neuroconv.datainterfaces.ophys.basesegmentationextractorinterface import BaseSegmentationExtractorInterface from neuroconv.tools import get_module -from neuroconv.utils import FolderPathType +from neuroconv.utils import FilePathType from pynwb import NWBFile from pinto_lab_to_nwb.widefield.extractors.widefield_processed_segmentationextractor import ( @@ -15,15 +15,33 @@ class WidefieldProcessedSegmentationinterface(BaseSegmentationExtractorInterface Extractor = WidefieldProcessedSegmentationExtractor - def __init__(self, folder_path: FolderPathType, verbose: bool = True): + def __init__( + self, + info_mat_file_path: FilePathType, + roi_from_ref_mat_file_path: FilePathType, + vasculature_mask_file_path: FilePathType, + blue_pca_mask_file_path: FilePathType, + verbose: bool = True): """ Parameters ---------- - folder_path : FolderPathType + info_mat_file_path : FilePathType + The file path to the 'info.mat' file. + roi_from_ref_mat_file_path : FilePathType + The file that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. + vasculature_mask_file_path: FilePathType + The file that contains the vasculature mask on the downsampled (binned) session image. + blue_pca_mask_file_path: FilePathType + The file that contains the PCA mask for the blue channel. verbose : bool, default: True """ - super().__init__(folder_path=folder_path) + super().__init__( + info_mat_file_path=info_mat_file_path, + roi_from_ref_mat_file_path=roi_from_ref_mat_file_path, + vasculature_mask_file_path=vasculature_mask_file_path, + blue_pca_mask_file_path=blue_pca_mask_file_path, + ) self.verbose = verbose def get_metadata(self) -> dict: diff --git a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py index 7742acc..376eae9 100644 --- a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py +++ b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py @@ -3,7 +3,7 @@ import numpy as np from neuroconv import BaseDataInterface from neuroconv.tools import get_module -from neuroconv.utils import FolderPathType +from neuroconv.utils import FolderPathType, FilePathType from pymatreader import read_mat from pynwb import NWBFile from pynwb.base import Images @@ -13,37 +13,51 @@ class WidefieldSegmentationImagesBlueInterface(BaseDataInterface): """The custom interface to add the blue channel manual and vasculature mask to the NWBFile.""" - def __init__(self, folder_path: FolderPathType, verbose: bool = True): + def __init__( + self, + vasculature_mask_file_path: FilePathType, + manual_mask_file_path: FilePathType, + manual_mask_struct_name: str, + verbose: bool = True, + ): """ The interface to add the summary images to the NWBFile. Parameters ---------- - folder_path : FolderPathType + vasculature_mask_file_path : FilePathType + The file path to the vasculature mask file. + manual_mask_file_path : FilePathType + The file path to the manual mask file. + manual_mask_struct_name: str + The name of the struct in the manual mask file that contains the manual mask (e.g. "regMask" or "reg_manual_mask"). verbose : bool, default: True """ - super().__init__(folder_path=folder_path) - self.folder_path = Path(folder_path) + super().__init__(vasculature_mask_file_path=vasculature_mask_file_path) + self.vasculature_mask_file_path = Path(vasculature_mask_file_path) + assert self.vasculature_mask_file_path.exists(), f"The vasculature mask file '{vasculature_mask_file_path}' does not exist." + + self.manual_mask_file_path = Path(manual_mask_file_path) + assert self.manual_mask_file_path.exists(), f"The manual mask file '{manual_mask_file_path}' does not exist." + + self.manual_mask_struct_name = manual_mask_struct_name + self.verbose = verbose self._image_vasculature = self._load_vasculature_mask() self._image_manual = self._load_manual_mask() def _load_vasculature_mask(self) -> np.ndarray: - vasculature_mask_file_path = self.folder_path / "vasculature_mask_2.mat" - assert vasculature_mask_file_path.exists(), f"The vasculature mask file is missing from {self.folder_path}." - vasculature_mask_mat = read_mat(str(vasculature_mask_file_path)) - assert "mask" in vasculature_mask_mat, f"The vasculature mask is missing from {vasculature_mask_file_path}." + vasculature_mask_mat = read_mat(str(self.vasculature_mask_file_path)) + assert "mask" in vasculature_mask_mat, f"The vasculature mask is missing from {self.vasculature_mask_file_path}." vasculature_mask = vasculature_mask_mat["mask"] return vasculature_mask def _load_manual_mask(self): - manual_mask_file_path = Path(self.folder_path) / "regManualMask.mat" - assert manual_mask_file_path.exists(), f"The manual mask file is missing from {self.folder_path}." - manual_mask_mat = read_mat(str(manual_mask_file_path)) - assert "regMask" in manual_mask_mat, f"The manual mask is missing from {manual_mask_file_path}." - manual_mask = manual_mask_mat["regMask"] + manual_mask_mat = read_mat(self.manual_mask_file_path) + assert self.manual_mask_struct_name in manual_mask_mat, f"The manual mask is missing from {self.manual_mask_file_path}." + manual_mask = manual_mask_mat[self.manual_mask_struct_name] return manual_mask diff --git a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py index e025a7c..dc48d37 100644 --- a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py +++ b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py @@ -3,7 +3,7 @@ import numpy as np from neuroconv import BaseDataInterface from neuroconv.tools import get_module -from neuroconv.utils import FolderPathType +from neuroconv.utils import FilePathType from pymatreader import read_mat from pynwb import NWBFile from pynwb.base import Images @@ -13,28 +13,26 @@ class WidefieldSegmentationImagesVioletInterface(BaseDataInterface): """The custom interface to add the violet channel PCA mask to the NWBFile.""" - def __init__(self, folder_path: FolderPathType, verbose: bool = True): + def __init__(self, violet_pca_mask_file_path: FilePathType, verbose: bool = True): """ The interface to add the summary images to the NWBFile. Parameters ---------- - folder_path : FolderPathType + violet_pca_mask_file_path : FilePathType + The file path to the violet channel PCA mask file. verbose : bool, default: True """ - super().__init__(folder_path=folder_path) - self.folder_path = Path(folder_path) + super().__init__(violet_pca_mask_file_path=violet_pca_mask_file_path) + self.violet_pca_mask_file_path = Path(violet_pca_mask_file_path) + assert self.violet_pca_mask_file_path.exists(), f"The violet channel PCA mask file '{violet_pca_mask_file_path}' does not exist." self.verbose = verbose self._image_pca_violet = self._load_pca_mask() def _load_pca_mask(self) -> np.ndarray: - pca_mask_file_path = self.folder_path / "violet_pca_vasculature_mask_2.mat" - assert ( - pca_mask_file_path.exists() - ), f"The PCA mask file for the violet channel is missing from {self.folder_path}." - pca_mask_violet = read_mat(str(pca_mask_file_path)) - assert "vasc_mask" in pca_mask_violet, f"Could not find 'vasc_mask' in 'violet_pca_vasculature_mask_2.mat'." + pca_mask_violet = read_mat(str(self.violet_pca_mask_file_path)) + assert "vasc_mask" in pca_mask_violet, f"Could not find 'vasc_mask' in '{self.violet_pca_mask_file_path}'." pca_mask = pca_mask_violet["vasc_mask"] return pca_mask From 0b05a049853af765f4b98d2c91963d93dd435650 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Sun, 3 Dec 2023 14:58:26 +0100 Subject: [PATCH 2/4] adjust convert session script --- .../widefield/widefield_convert_session.py | 67 +++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py b/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py index 8e05f7f..20ba77b 100644 --- a/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py +++ b/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py @@ -21,6 +21,13 @@ def session_to_nwb( strobe_sequence_file_path: FilePathType, processed_imaging_file_path: FilePathType, info_file_path: FilePathType, + vasculature_mask_file_path: FilePathType, + manual_mask_file_path: FilePathType, + manual_mask_struct_name: str, + roi_from_ref_mat_file_path: FilePathType, + binned_vasculature_mask_file_path: FilePathType, + binned_blue_pca_mask_file_path: FilePathType, + binned_violet_pca_mask_file_path: FilePathType, subject_metadata_file_path: Optional[FilePathType] = None, stub_test: bool = False, ): @@ -37,6 +44,20 @@ def session_to_nwb( The file path to the strobe sequence file. This file should contain the 'strobe_session_key' key. info_file_path: FilePathType The file path to the Matlab file with information about the imaging session (e.g. 'frameRate'). + vasculature_mask_file_path: FilePathType + The file path that contains the contrast based vasculature mask on the full size session image (blue channel). + manual_mask_file_path: FilePathType + The file path that contains the manual mask on the full size session image (blue channel). + manual_mask_struct_name: str + The name of the struct in the manual mask file that contains the manual mask (e.g. "regMask" or "reg_manual_mask"). + roi_from_ref_mat_file_path: FilePathType + The file path that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. + binned_vasculature_mask_file_path: FilePathType + The file path that contains the contrast based vasculature mask on the downsampled (binned) session image (blue channel). + binned_blue_pca_mask_file_path: FilePathType + The file path that contains the PCA mask for the blue channel. + binned_violet_pca_mask_file_path: FilePathType + The file path that contains the PCA mask for the violet channel. subject_metadata_file_path: FilePathType, optional The file path to the subject metadata file. This file should contain the 'metadata' key. stub_test: bool, optional @@ -106,13 +127,18 @@ def session_to_nwb( source_data.update( dict( SegmentationProcessedBlue=dict( - folder_path=str(widefield_imaging_folder_path), + info_mat_file_path=str(info_file_path), + roi_from_ref_mat_file_path=str(roi_from_ref_mat_file_path), + vasculature_mask_file_path=str(binned_vasculature_mask_file_path), + blue_pca_mask_file_path=str(binned_blue_pca_mask_file_path), ), SummaryImagesBlue=dict( - folder_path=str(widefield_imaging_folder_path), + vasculature_mask_file_path=str(vasculature_mask_file_path), + manual_mask_file_path=str(manual_mask_file_path), + manual_mask_struct_name=manual_mask_struct_name, ), SummaryImagesViolet=dict( - folder_path=str(widefield_imaging_folder_path), + violet_pca_mask_file_path=str(binned_violet_pca_mask_file_path), ), ) ) @@ -156,13 +182,39 @@ def session_to_nwb( # Parameters for conversion # The folder path that contains the raw imaging data in Micro-Manager OME-TIF format (.ome.tif files). - imaging_folder_path = Path("/Users/weian/data/DrChicken_20230419_20hz") + #imaging_folder_path = Path("/Users/weian/data/Cherry/20230802/Cherry_20230802_20hz_1") + imaging_folder_path = Path("/Volumes/t7-ssd/Pinto/DrChicken_20230419_20hz") # The file path to the strobe sequence file. strobe_sequence_file_path = imaging_folder_path / "strobe_seq_1_2.mat" # The file path to the downsampled imaging data in Matlab format (.mat file). processed_imaging_path = imaging_folder_path / "rawf_full.mat" # The file path to the Matlab file with information about the imaging session (e.g. 'frameRate'). info_file_path = imaging_folder_path / "info.mat" + + # Parameters for custom segmentation and summary images + # The file path that contains the contrast based vasculature mask on the full size session image (blue channel). + vasculature_mask_file_path = imaging_folder_path / "vasculature_mask_2.mat" + + # The file path that contains the manual mask on the full size session image (blue channel). + #manual_mask_file_path = imaging_folder_path / "reg_manual_mask_jlt6316_Cherry_20230802_1_1_1.mat" + manual_mask_file_path = imaging_folder_path / "regManualMask.mat" + # The name of the struct in the manual mask file that contains the manual mask (e.g. "regMask" or "reg_manual_mask"). + #manual_mask_struct_name = "reg_manual_mask" + manual_mask_struct_name = "regMask" + + # The file path that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. + #roi_from_ref_mat_file_path = imaging_folder_path / "ROIfromRef_1.mat" + roi_from_ref_mat_file_path = imaging_folder_path / "ROIfromRef.mat" + + # The file path that contains the contrast based vasculature mask on the downsampled (binned) session image (blue channel). + binned_vasculature_mask_file_path = imaging_folder_path / "vasculature_mask_2.mat" + + # The file path that contains the PCA mask for the blue channel. + binned_blue_pca_mask_file_path = imaging_folder_path / "blue_pca_vasculature_mask_2.mat" + + # The file path that contains the PCA mask for the violet channel. + binned_violet_pca_mask_file_path = imaging_folder_path / "violet_pca_vasculature_mask_2.mat" + subject_metadata_file_path = "/Volumes/t7-ssd/Pinto/Behavior/subject_metadata.mat" # The file path to the NWB file that will be created. nwbfile_path = Path("/Volumes/t7-ssd/Pinto/nwbfiles/widefield/DrChicken_20230419_20hz.nwb") @@ -175,6 +227,13 @@ def session_to_nwb( strobe_sequence_file_path=strobe_sequence_file_path, processed_imaging_file_path=processed_imaging_path, info_file_path=info_file_path, + vasculature_mask_file_path=vasculature_mask_file_path, + manual_mask_file_path=manual_mask_file_path, + manual_mask_struct_name=manual_mask_struct_name, + roi_from_ref_mat_file_path=roi_from_ref_mat_file_path, + binned_vasculature_mask_file_path=binned_vasculature_mask_file_path, + binned_blue_pca_mask_file_path=binned_blue_pca_mask_file_path, + binned_violet_pca_mask_file_path=binned_violet_pca_mask_file_path, subject_metadata_file_path=subject_metadata_file_path, stub_test=stub_test, ) From 61ee9591ede4ed05e837459143646b9652060973 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Sun, 3 Dec 2023 15:29:10 +0100 Subject: [PATCH 3/4] add notes --- .../widefield/widefield_convert_session.py | 2 +- .../widefield/widefield_notes.md | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/pinto_lab_to_nwb/widefield/widefield_notes.md diff --git a/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py b/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py index 20ba77b..3e17acd 100644 --- a/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py +++ b/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py @@ -41,7 +41,7 @@ def session_to_nwb( widefield_imaging_folder_path: FolderPathType The folder path that contains the Micro-Manager OME-TIF imaging output (.ome.tif files). strobe_sequence_file_path: FilePathType - The file path to the strobe sequence file. This file should contain the 'strobe_session_key' key. + The file path to the strobe sequence file. This file should contain the 'strobe_session_key' key. info_file_path: FilePathType The file path to the Matlab file with information about the imaging session (e.g. 'frameRate'). vasculature_mask_file_path: FilePathType diff --git a/src/pinto_lab_to_nwb/widefield/widefield_notes.md b/src/pinto_lab_to_nwb/widefield/widefield_notes.md new file mode 100644 index 0000000..e1c9386 --- /dev/null +++ b/src/pinto_lab_to_nwb/widefield/widefield_notes.md @@ -0,0 +1,52 @@ +# Notes concerning the `widefield` conversion + +## Imaging folder structure + +See the example folder structure [here](https://gin.g-node.org/CatalystNeuro/ophys_testing_data/src/main/imaging_datasets/MicroManagerTif) for the MicroManager OME-TIF format. + +## Segmentation files structure + +Required files for custom segmentation and summary images: + +Summary images for the full size session image (blue channel): +- `"vasculature_mask_file_path"`: The file path that contains the contrast based vasculature mask on the full size session image (blue channel). +- `"manual_mask_file_path`: The file path that contains the manual mask on the full size session image (blue channel). +Summary images for the binned session image (blue channel, violet channel): +- `"binned_vasculature_mask_file_path"`: The file path that contains the contrast based vasculature mask on the downsampled (binned) session image (blue channel). +- `"binned_blue_pca_mask_file_path"`: The file path that contains the PCA mask for the blue channel. +- `"binned_violet_pca_mask_file_path"`: The file path that contains the PCA mask for the violet channel. +ROI masks and Allen area labels for the binned session image (blue channel): +- `"roi_from_ref_mat_file_path"`: The file path that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. +- `"info_file_path"`: The file path that contains the information about the imaging session (e.g. number of frames, frame rate, etc.). + +## Run conversion for a single session + +`widefield_convert_sesion.py`: this script defines the function to convert one full session of the conversion. +Parameters: +- "`widefield_imaging_folder_path`" : The folder path that contains the Micro-Manager OME-TIF imaging output (.ome.tif files). +- "`strobe_sequence_file_path`": The file path to the strobe sequence file. This file should contain the 'strobe_session_key' key. +- "`info_file_path`": The file path to the Matlab file with information about the imaging session (e.g. 'frameRate'). +- "`vasculature_mask_file_path`": The file path that contains the contrast based vasculature mask on the full size session image (blue channel). +- "`manual_mask_file_path`": The file path that contains the manual mask on the full size session image (blue channel). +- "`manual_mask_struct_name`": The name of the struct in the manual mask file that contains the manual mask (e.g. "regMask" or "reg_manual_mask"). +- "`roi_from_ref_mat_file_path`": The file path that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. +- "`binned_vasculature_mask_file_path`": The file path that contains the contrast based vasculature mask on the downsampled (binned) session image (blue channel). +- "`binned_blue_pca_mask_file_path`": The file path that contains the PCA mask for the blue channel. +- "`binned_violet_pca_mask_file_path`": The file path that contains the PCA mask for the violet channel. +- "`subject_metadata_file_path`": The file path that contains the subject metadata (e.g. subject_id, genotype, etc.). + +### Example usage + +To run a specific conversion, you might need to install first some conversion specific dependencies that are located in each conversion directory: +``` +cd src/pinto_lab_to_nwb/widefield +pip install -r widefield_requirements.txt +``` +Then you can run a specific conversion with the following command: +``` +python widefield_convert_session.py +``` + +### Tutorials + +See the [widefield tutorial](./tutorials/widefield_demo.ipynb) that demonstrates how to read and access the data in NWB. From 39f9084e15cdb53aca1f8e190f0a10b4b3b8a6af Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:33:03 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ...defield_processed_segmentationinterface.py | 13 ++++++----- ..._segmentation_images_blue_datainterface.py | 22 ++++++++++++------- ...egmentation_images_violet_datainterface.py | 4 +++- .../widefield/widefield_convert_session.py | 8 +++---- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py index e27da11..bda40b0 100644 --- a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py +++ b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_processed_segmentationinterface.py @@ -16,12 +16,13 @@ class WidefieldProcessedSegmentationinterface(BaseSegmentationExtractorInterface Extractor = WidefieldProcessedSegmentationExtractor def __init__( - self, - info_mat_file_path: FilePathType, - roi_from_ref_mat_file_path: FilePathType, - vasculature_mask_file_path: FilePathType, - blue_pca_mask_file_path: FilePathType, - verbose: bool = True): + self, + info_mat_file_path: FilePathType, + roi_from_ref_mat_file_path: FilePathType, + vasculature_mask_file_path: FilePathType, + blue_pca_mask_file_path: FilePathType, + verbose: bool = True, + ): """ Parameters diff --git a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py index 376eae9..1469f41 100644 --- a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py +++ b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_blue_datainterface.py @@ -14,11 +14,11 @@ class WidefieldSegmentationImagesBlueInterface(BaseDataInterface): """The custom interface to add the blue channel manual and vasculature mask to the NWBFile.""" def __init__( - self, - vasculature_mask_file_path: FilePathType, - manual_mask_file_path: FilePathType, - manual_mask_struct_name: str, - verbose: bool = True, + self, + vasculature_mask_file_path: FilePathType, + manual_mask_file_path: FilePathType, + manual_mask_struct_name: str, + verbose: bool = True, ): """ The interface to add the summary images to the NWBFile. @@ -35,7 +35,9 @@ def __init__( """ super().__init__(vasculature_mask_file_path=vasculature_mask_file_path) self.vasculature_mask_file_path = Path(vasculature_mask_file_path) - assert self.vasculature_mask_file_path.exists(), f"The vasculature mask file '{vasculature_mask_file_path}' does not exist." + assert ( + self.vasculature_mask_file_path.exists() + ), f"The vasculature mask file '{vasculature_mask_file_path}' does not exist." self.manual_mask_file_path = Path(manual_mask_file_path) assert self.manual_mask_file_path.exists(), f"The manual mask file '{manual_mask_file_path}' does not exist." @@ -49,14 +51,18 @@ def __init__( def _load_vasculature_mask(self) -> np.ndarray: vasculature_mask_mat = read_mat(str(self.vasculature_mask_file_path)) - assert "mask" in vasculature_mask_mat, f"The vasculature mask is missing from {self.vasculature_mask_file_path}." + assert ( + "mask" in vasculature_mask_mat + ), f"The vasculature mask is missing from {self.vasculature_mask_file_path}." vasculature_mask = vasculature_mask_mat["mask"] return vasculature_mask def _load_manual_mask(self): manual_mask_mat = read_mat(self.manual_mask_file_path) - assert self.manual_mask_struct_name in manual_mask_mat, f"The manual mask is missing from {self.manual_mask_file_path}." + assert ( + self.manual_mask_struct_name in manual_mask_mat + ), f"The manual mask is missing from {self.manual_mask_file_path}." manual_mask = manual_mask_mat[self.manual_mask_struct_name] return manual_mask diff --git a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py index dc48d37..7c2d0c8 100644 --- a/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py +++ b/src/pinto_lab_to_nwb/widefield/interfaces/widefield_segmentation_images_violet_datainterface.py @@ -25,7 +25,9 @@ def __init__(self, violet_pca_mask_file_path: FilePathType, verbose: bool = True """ super().__init__(violet_pca_mask_file_path=violet_pca_mask_file_path) self.violet_pca_mask_file_path = Path(violet_pca_mask_file_path) - assert self.violet_pca_mask_file_path.exists(), f"The violet channel PCA mask file '{violet_pca_mask_file_path}' does not exist." + assert ( + self.violet_pca_mask_file_path.exists() + ), f"The violet channel PCA mask file '{violet_pca_mask_file_path}' does not exist." self.verbose = verbose self._image_pca_violet = self._load_pca_mask() diff --git a/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py b/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py index 3e17acd..a261d2c 100644 --- a/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py +++ b/src/pinto_lab_to_nwb/widefield/widefield_convert_session.py @@ -182,7 +182,7 @@ def session_to_nwb( # Parameters for conversion # The folder path that contains the raw imaging data in Micro-Manager OME-TIF format (.ome.tif files). - #imaging_folder_path = Path("/Users/weian/data/Cherry/20230802/Cherry_20230802_20hz_1") + # imaging_folder_path = Path("/Users/weian/data/Cherry/20230802/Cherry_20230802_20hz_1") imaging_folder_path = Path("/Volumes/t7-ssd/Pinto/DrChicken_20230419_20hz") # The file path to the strobe sequence file. strobe_sequence_file_path = imaging_folder_path / "strobe_seq_1_2.mat" @@ -196,14 +196,14 @@ def session_to_nwb( vasculature_mask_file_path = imaging_folder_path / "vasculature_mask_2.mat" # The file path that contains the manual mask on the full size session image (blue channel). - #manual_mask_file_path = imaging_folder_path / "reg_manual_mask_jlt6316_Cherry_20230802_1_1_1.mat" + # manual_mask_file_path = imaging_folder_path / "reg_manual_mask_jlt6316_Cherry_20230802_1_1_1.mat" manual_mask_file_path = imaging_folder_path / "regManualMask.mat" # The name of the struct in the manual mask file that contains the manual mask (e.g. "regMask" or "reg_manual_mask"). - #manual_mask_struct_name = "reg_manual_mask" + # manual_mask_struct_name = "reg_manual_mask" manual_mask_struct_name = "regMask" # The file path that contains the Allen area label of each pixel mapped onto the reference image of the mouse and registered to the session. - #roi_from_ref_mat_file_path = imaging_folder_path / "ROIfromRef_1.mat" + # roi_from_ref_mat_file_path = imaging_folder_path / "ROIfromRef_1.mat" roi_from_ref_mat_file_path = imaging_folder_path / "ROIfromRef.mat" # The file path that contains the contrast based vasculature mask on the downsampled (binned) session image (blue channel).