Skip to content

Commit

Permalink
Merge branch 'main' into protect_import_in_sima
Browse files Browse the repository at this point in the history
  • Loading branch information
h-mayorquin authored Aug 13, 2024
2 parents fea18ec + 28b843f commit be0fa79
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* 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 export [#351](https://github.com/catalystneuro/roiextractors/pull/351)
* Improve error message when `TiffImagingExtractor` is not able to form memmap [#353](https://github.com/catalystneuro/roiextractors/pull/353)

### Testing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ def __init__(self, file_path: PathType, sampling_frequency: FloatType):

try:
self._video = tifffile.memmap(self.file_path, mode="r")
except ValueError:
warn(
"memmap of TIFF file could not be established. Reading entire matrix into memory. "
"Consider using the ScanImageTiffExtractor for lazy data access."
)
with tifffile.TiffFile(self.file_path) as tif:
self._video = tif.asarray()
except Exception as e:

try:
with tifffile.TiffFile(self.file_path) as tif:
self._video = tif.asarray()
warn(
f"memmap of TIFF file could not be established due to the following error: {e}. "
"Reading entire matrix into memory. Consider using the ScanImageTiffSinglePlaneImagingExtractor or ScanImageTiffMultiPlaneImagingExtractor for lazy data access.",
stacklevel=2,
)
except Exception as e2:
raise RuntimeError(
f"Memory mapping failed: {e}. \n"
f"Attempt to read the TIFF file directly also failed: {e2}. \n"
f"Consider using ScanImageTiffSinglePlaneImagingExtractor or ScanImageTiffMultiPlaneImagingExtractor for lazy data access, check the file integrity. \n"
f"If problems persist, please report an issue at roiextractors/issues."
)

shape = self._video.shape
if len(shape) == 3:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_scan_image_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_tiff_non_memmap_warning(self):
with self.assertWarnsWith(
warn_type=UserWarning,
exc_msg=(
"memmap of TIFF file could not be established. Reading entire matrix into memory. "
"Consider using the ScanImageTiffExtractor for lazy data access."
"memmap of TIFF file could not be established due to the following error: image data are not memory-mappable. "
"Reading entire matrix into memory. Consider using the ScanImageTiffSinglePlaneImagingExtractor or ScanImageTiffMultiPlaneImagingExtractor for lazy data access."
),
):
TiffImagingExtractor(file_path=self.file_path, sampling_frequency=30.0)
Expand Down

0 comments on commit be0fa79

Please sign in to comment.