From daac46f334de9962e8c160fc4e2a1d7af3b2d2d2 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Tue, 21 Nov 2023 12:07:44 +0100 Subject: [PATCH 1/3] fix override of channel_name --- .../extractors/suite2p/suite2psegmentationextractor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/roiextractors/extractors/suite2p/suite2psegmentationextractor.py b/src/roiextractors/extractors/suite2p/suite2psegmentationextractor.py index 4ae952c0..5756a32f 100644 --- a/src/roiextractors/extractors/suite2p/suite2psegmentationextractor.py +++ b/src/roiextractors/extractors/suite2p/suite2psegmentationextractor.py @@ -168,8 +168,9 @@ def __init__( self.iscell = self._load_npy("iscell.npy", mmap_mode="r") - channel_name = "OpticalChannel" if len(channel_names) == 1 else channel_name.capitalize() - self._channel_names = [channel_name] + # The name of the OpticalChannel object is "OpticalChannel" if there is only one channel, otherwise it is + # "Chan1" or "Chan2". + self._channel_names = ["OpticalChannel" if len(channel_names) == 1 else channel_name.capitalize()] self._image_correlation = self._correlation_image_read() image_mean_name = "meanImg" if channel_name == "chan1" else f"meanImg_chan2" From af596a581b3b0396c5a36a161e84809d97f7c985 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Tue, 21 Nov 2023 12:43:12 +0100 Subject: [PATCH 2/3] update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1e5bfd..eb075773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes * Fixed `MicroManagerTiffImagingExtractor` private extractor's dtype to not override the parent's dtype. [PR #257](https://github.com/catalystneuro/roiextractors/pull/257) - +* Fixed override of `channel_name` in `Suite2pSegmentationExtractor`. [PR #263](https://github.com/catalystneuro/roiextractors/pull/263) # v0.5.4 From 3ca299f603e471b11d1f36a344c706a3a20a5876 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Wed, 22 Nov 2023 14:41:42 +0100 Subject: [PATCH 3/3] add test for mean image --- tests/test_suite2psegmentationextractor.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test_suite2psegmentationextractor.py b/tests/test_suite2psegmentationextractor.py index 59dae738..b38265a2 100644 --- a/tests/test_suite2psegmentationextractor.py +++ b/tests/test_suite2psegmentationextractor.py @@ -28,6 +28,10 @@ def setUpClass(cls): cls.first_channel_raw_traces = np.load(cls.folder_path / "plane0" / "F.npy").T cls.second_channel_raw_traces = np.load(cls.folder_path / "plane0" / "F_chan2.npy").T + options = np.load(cls.folder_path / "plane0" / "ops.npy", allow_pickle=True).item() + cls.first_channel_mean_image = options["meanImg"] + cls.second_channel_mean_image = options["meanImg_chan2"] + cls.image_size = (128, 128) cls.num_rois = 15 @@ -43,7 +47,7 @@ def tearDownClass(cls): # remove the temporary directory and its contents shutil.rmtree(cls.test_dir) - def test_channel_names(self): + def test_available_channel_names(self): self.assertEqual( Suite2pSegmentationExtractor.get_available_channels(folder_path=self.folder_path), self.channel_names ) @@ -98,7 +102,7 @@ def test_num_frames(self): def test_sampling_frequency(self): self.assertEqual(self.extractor.get_sampling_frequency(), 10.0) - def test_channel_names(self): + def test_optical_channel_names(self): self.assertEqual(self.extractor.get_channel_names(), ["Chan1"]) def test_num_channels(self): @@ -125,3 +129,14 @@ def test_extractor_image_masks_selected_rois(self): """Test that the image masks are correctly extracted for a subset of ROIs.""" roi_indices = list(range(5)) assert_array_equal(self.extractor.get_roi_image_masks(roi_ids=roi_indices), self.image_masks[..., roi_indices]) + + def test_first_channel_mean_image(self): + """Test that the mean image is correctly loaded from the extractor.""" + images_dict = self.extractor.get_images_dict() + assert_array_equal(images_dict["mean"], self.first_channel_mean_image) + + def test_second_channel_mean_image(self): + """Test that the mean image for the second channel is correctly loaded from the extractor.""" + extractor = Suite2pSegmentationExtractor(folder_path=self.folder_path, channel_name="chan2") + images_dict = extractor.get_images_dict() + assert_array_equal(images_dict["mean"], self.second_channel_mean_image)