From b8bc0db9b50b771de31a6fdfe2818f4cf89c5b0a Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 21 May 2024 13:27:59 -0400 Subject: [PATCH] BaseSegmentation class improvements (#327) * prepopulate private attribute for image mask; rearrange abstract method * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Paul Adkisson --- CHANGELOG.md | 3 ++- src/roiextractors/segmentationextractor.py | 25 +++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ece49f53..c7ee71ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,12 +11,13 @@ ### Fixes -* Remove unecessary scipy import error handling: [#315](https://github.com/catalystneuro/roiextractors/pull/315) +* Remove unnecessary `scipy` import error handling: [#315](https://github.com/catalystneuro/roiextractors/pull/315) * Fixed the typing returned by the `InscopixImagingExtractor.get_dtype` method: [#326](https://github.com/catalystneuro/roiextractors/pull/326) ### Improvements * The `Suite2PSegmentationExtractor` now produces an error when a required sub-file is missin: [#330](https://github.com/catalystneuro/roiextractors/pull/330) +* Added `_image_mask` initialization in `BaseSegmentationExtractor`; combined `abstractmethod`s into top of file: [#327](https://github.com/catalystneuro/roiextractors/pull/327) ### Testing diff --git a/src/roiextractors/segmentationextractor.py b/src/roiextractors/segmentationextractor.py index 856c62f9..40502c08 100644 --- a/src/roiextractors/segmentationextractor.py +++ b/src/roiextractors/segmentationextractor.py @@ -32,7 +32,7 @@ class SegmentationExtractor(ABC): """ def __init__(self): - """Create a new SegmentationExtractor from specified data type (unique to each child SegmentationExtractor).""" + """Create a new SegmentationExtractor for a specific data format (unique to each child SegmentationExtractor).""" self._sampling_frequency = None self._times = None self._channel_names = ["OpticalChannel"] @@ -44,6 +44,7 @@ def __init__(self): self._roi_response_deconvolved = None self._image_correlation = None self._image_mean = None + self._image_mask = None @abstractmethod def get_accepted_list(self) -> list: @@ -67,6 +68,17 @@ def get_rejected_list(self) -> list: """ pass + @abstractmethod + def get_image_size(self) -> ArrayType: + """Get frame size of movie (height, width). + + Returns + ------- + no_rois: array_like + 2-D array: image height x image width + """ + pass + def get_num_frames(self) -> int: """Get the number of frames in the recording (duration of recording). @@ -204,17 +216,6 @@ def get_background_pixel_masks(self, background_ids=None) -> np.array: return _pixel_mask_extractor(self.get_background_image_masks(background_ids=background_ids), background_ids) - @abstractmethod - def get_image_size(self) -> ArrayType: - """Get frame size of movie (height, width). - - Returns - ------- - no_rois: array_like - 2-D array: image height x image width - """ - pass - def frame_slice(self, start_frame: Optional[int] = None, end_frame: Optional[int] = None): """Return a new SegmentationExtractor ranging from the start_frame to the end_frame.