Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix override of channel_name in Suite2pSegmentationExtractor #263

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 17 additions & 2 deletions tests/test_suite2psegmentationextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
)
Expand Down Expand Up @@ -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):
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(self.extractor.get_channel_names(), ["Chan1"])

def test_num_channels(self):
Expand All @@ -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)
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
Loading