Skip to content

Commit

Permalink
Add data consistency checks to mmapping.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fdeguire03 authored Jan 10, 2025
1 parent 2a14837 commit 67787fe
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion caiman/mmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ def load_memmap(filename: str, mode: str = 'r') -> tuple[Any, tuple, int]:
#d1, d2, d3, T, order = int(fpart[-9]), int(fpart[-7]), int(fpart[-5]), int(fpart[-1]), fpart[-3]

filename = caiman.paths.fn_relocated(filename)
shape = prepare_shape((d1 * d2 * d3, T))
if extension == '.mmap':
Yr = np.memmap(filename, mode=mode, shape=prepare_shape((d1 * d2 * d3, T)), dtype=np.float32, order=order)
Yr = np.memmap(filename, mode=mode, shape=shape, dtype=np.float32, order=order)
elif extension == '.npy':
Yr = np.load(filename, mmap_mode=mode)
if Yr.shape != shape:
raise ValueError(f"Data in npy file was an unexpected shape: {Yr.shape}, expected: {shape}")
if Yr.dtype != np.float32:
raise ValueError(f"Data in npy file was an unexpected dtype: {Yr.dtype}, expected: np.float32")
if order == 'C' and not Yr.flags['C_CONTIGUOUS']:
raise ValueError("Data in npy file is not in C-contiguous order as expected.")
elif order == 'F' and not Yr.flags['F_CONTIGUOUS']:
raise ValueError("Data in npy file is not in Fortran-contiguous order as expected.")



if d3 == 1:
return (Yr, (d1, d2), T)
Expand Down

0 comments on commit 67787fe

Please sign in to comment.