Skip to content

Commit

Permalink
Alphebatize imports and use splitext
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbb committed Mar 29, 2024
1 parent 300fd3d commit ec9ca6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions caiman/base/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import caiman.base.traces
import caiman.mmapping
import caiman.summary_images
import caiman.utils.visualization
import caiman.utils.sbx_utils
import caiman.utils.visualization

try:
cv2.setNumThreads(0)
Expand Down Expand Up @@ -1311,7 +1311,7 @@ def load(file_name: Union[str, list[str]],
logging.error('movies.py:load(): channel parameter is not supported for single movie input')

if os.path.exists(file_name):
_, extension = os.path.splitext(file_name)[:2]
basename, extension = os.path.splitext(file_name)

extension = extension.lower()
if extension == '.mat':
Expand Down Expand Up @@ -1576,8 +1576,8 @@ def load(file_name: Union[str, list[str]],

elif extension == '.sbx':
logging.debug('sbx')
meta_data = caiman.utils.sbx_utils.sbx_meta_data(file_name[:-4])
input_arr = caiman.utils.sbx_utils.sbxread(file_name[:-4], subindices)
meta_data = caiman.utils.sbx_utils.sbx_meta_data(basename)
input_arr = caiman.utils.sbx_utils.sbxread(basename, subindices)
return movie(input_arr, fr=fr,
file_name=os.path.split(file_name)[-1],
meta_data=meta_data).astype(outtype)
Expand Down
6 changes: 3 additions & 3 deletions caiman/tests/test_sbx.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python

import os

import numpy as np
import numpy.testing as npt
import os

import caiman as cm
from caiman.utils import sbx_utils
from caiman.paths import caiman_datadir
from caiman.utils import sbx_utils

testdata_path = os.path.join(caiman_datadir(), 'testdata')

Expand Down
28 changes: 14 additions & 14 deletions caiman/utils/sbx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
Utility functions for Neurolabware Scanbox files (.sbx)
"""

import os
import logging
from typing import Iterable

import numpy as np
import os
import scipy
import tifffile
from typing import Iterable

DimSubindices = Iterable[int] | slice
FileSubindices = DimSubindices | Iterable[DimSubindices] # can have inds for just frames or also for y, x, z
Expand Down Expand Up @@ -98,8 +97,9 @@ def sbx_to_tif(filename: str, fileout: str | None = None, subindices: FileSubind
how many frames to load into memory at once (None = load the whole thing)
"""
# Check filenames
if '.sbx' in filename:
filename = filename[:-4]
basename, ext = os.path.splitext(filename)
if ext == '.sbx':
filename = basename

if fileout is None:
fileout = filename + '.tif'
Expand Down Expand Up @@ -207,9 +207,9 @@ def sbx_shape(filename: str, info: dict | None = None) -> tuple[int, int, int, i
Output: tuple (chans, X, Y, Z, frames) representing shape of scanbox data
"""
# Check if contains .sbx and if so just truncate
if '.sbx' in filename:
filename = filename[:-4]
basename, ext = os.path.splitext(filename)
if ext == '.sbx':
filename = basename

# Load info
if info is None:
Expand Down Expand Up @@ -288,8 +288,9 @@ def sbx_meta_data(filename: str):
filename: str
filename should be full path excluding .sbx
"""
if '.sbx' in filename:
filename = filename[:-4]
basename, ext = os.path.splitext(filename)
if ext == '.sbx':
filename = basename

info = loadmat_sbx(filename + '.mat')['info']

Expand Down Expand Up @@ -380,10 +381,9 @@ def _sbxread_helper(filename: str, subindices: FileSubindices = slice(None), cha
chunk_size: int | None
how many frames to load into memory at once (None = load the whole thing)
"""

# Check if contains .sbx and if so just truncate
if '.sbx' in filename:
filename = filename[:-4]
basename, ext = os.path.splitext(filename)
if ext == '.sbx':
filename = basename

# Normalize so subindices is a list over dimensions
if isinstance(subindices, slice) or np.isscalar(subindices[0]):
Expand Down

0 comments on commit ec9ca6e

Please sign in to comment.