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

Improve error message for tiff imaging extractor #353

Merged
merged 5 commits into from
Aug 13, 2024
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
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)
* 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
Loading