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

Protect import in sima #351

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* 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)
* Optimize parsing of xml with `lxml` library for Burker extractors: [#346](https://github.com/catalystneuro/roiextractors/pull/346)
* Protect sima and dill expoert [#346](https://github.com/catalystneuro/roiextractors/pull/346)
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved

### Testing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
from ...extraction_tools import PathType
from ...segmentationextractor import SegmentationExtractor

try:
import sima
import dill

HAVE_SIMA = True
except ImportError:
HAVE_SIMA = False


class SimaSegmentationExtractor(SegmentationExtractor):
"""A segmentation extractor for Sima.
Expand All @@ -34,7 +26,6 @@ class SimaSegmentationExtractor(SegmentationExtractor):
"""

extractor_name = "SimaSegmentation"
installed = HAVE_SIMA # check at class level if installed or not
is_writable = False
mode = "file"
# error message when not installed
Expand All @@ -51,6 +42,14 @@ def __init__(self, file_path: PathType, sima_segmentation_label: str = "auto_ROI
sima_segmentation_label: str
name of the ROIs in the dataset from which to extract all ROI info
"""
try:
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved
import sima
import dill

HAVE_SIMA = True
except ImportError:
HAVE_SIMA = False
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved

assert HAVE_SIMA, self.installation_mesg
SegmentationExtractor.__init__(self)
self.file_path = file_path
Expand Down Expand Up @@ -79,6 +78,8 @@ def _convert_sima(old_pkl_loc):
old_pkl_loc: str
Path of the pickle file to be converted
"""
import dill

# Make a name for the new pickle
old_pkl_loc = old_pkl_loc + "/"
for dirpath, dirnames, filenames in os.walk(old_pkl_loc):
Expand Down Expand Up @@ -108,6 +109,8 @@ def _convert_sima(old_pkl_loc):

def _file_extractor_read(self):
"""Read the sima file and return the sima.ImagingDataset object."""
import sima

_img_dataset = sima.ImagingDataset.load(self.file_path)
_img_dataset._savedir = self.file_path
return _img_dataset
Expand Down
Loading