Skip to content

Commit

Permalink
Merge pull request #148 from catalystneuro/swap_to_suffix_warnings
Browse files Browse the repository at this point in the history
Swap suffix assertions to warnings (ImagingExtractors)
  • Loading branch information
CodyCBakerPhD authored Jun 20, 2022
2 parents 4667c27 + d054919 commit e8927dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from warnings import warn

import numpy as np

Expand Down Expand Up @@ -39,10 +40,8 @@ def __init__(
self.filepath = Path(file_path)
self._sampling_frequency = sampling_frequency
self._mov_field = mov_field
assert self.filepath.suffix in [
".h5",
".hdf5",
], "'file_path' file is not an .hdf5 or .h5 file"
if self.filepath.suffix not in [".h5", ".hdf5"]:
warn("'file_path' file is not an .hdf5 or .h5 file")
self._channel_names = channel_names

self._file = h5py.File(file_path, "r")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
from warnings import warn

import numpy as np

Expand Down Expand Up @@ -47,7 +48,10 @@ def _check_file_path(file_path):
file_path = Path(file_path)
assertion_msg = "for file_path arg, provide a path to one .sbx / .mat file"
file_type = file_path.suffix
assert file_type in [".mat", ".sbx"], assertion_msg
if file_type not in [".mat", ".sbx"]:
warn(
"File suffix ({file_type}) is not one of .mat or .sbx - the SbxImagingExtractor may not be appropriate!"
)
if file_type == ".mat":
mat_file_path = file_path
sbx_file_path = file_path.with_suffix(".sbx")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
import warnings
from warnings import warn

import numpy as np
from tqdm import tqdm
Expand Down Expand Up @@ -36,15 +36,19 @@ def __init__(self, file_path: PathType, sampling_frequency: FloatType):
ImagingExtractor.__init__(self)
self.file_path = Path(file_path)
self._sampling_frequency = sampling_frequency
assert self.file_path.suffix in [".tiff", ".tif", ".TIFF", ".TIF"]
if self.file_path.suffix not in [".tiff", ".tif", ".TIFF", ".TIF"]:
warn(
"File suffix ({self.file_path.suffix}) is not one of .tiff, .tif, .TIFF, or .TIF! "
"The TiffImagingExtracto may not be appropriate."
)

with tifffile.TiffFile(self.file_path) as tif:
self._num_channels = len(tif.series)

try:
self._video = tifffile.memmap(self.file_path, mode="r")
except ValueError:
warnings.warn(
warn(
"memmap of TIFF file could not be established. Reading entire matrix into memory. "
"Consider using the ScanImageTiffExtractor for lazy data access."
)
Expand Down

0 comments on commit e8927dc

Please sign in to comment.