Skip to content

Commit

Permalink
"import caiman as cm" -> "import caiman"
Browse files Browse the repository at this point in the history
  • Loading branch information
pgunn committed Feb 15, 2024
1 parent 542ffeb commit e1c3f92
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 96 deletions.
8 changes: 4 additions & 4 deletions bin/caiman_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyqtgraph.parametertree import Parameter, ParameterTree
from scipy.sparse import csc_matrix

import caiman as cm
import caiman
from caiman.source_extraction.cnmf.cnmf import load_CNMF
from caiman.source_extraction.cnmf.params import CNMFParams

Expand Down Expand Up @@ -67,10 +67,10 @@ def make_color_img(img, gain=255, min_max=None, out_type=np.uint8):
directory=d, filter=f + ';;*.mmap')[0]

if fpath[-3:] == 'nwb':
mov = cm.load(cnm_obj.mmap_file,
mov = caiman.load(cnm_obj.mmap_file,
var_name_hdf5='acquisition/TwoPhotonSeries')
else:
mov = cm.load(cnm_obj.mmap_file)
mov = caiman.load(cnm_obj.mmap_file)

estimates = cnm_obj.estimates
params_obj = cnm_obj.params
Expand Down Expand Up @@ -106,7 +106,7 @@ def selectionchange(self,i):
cb.show()

if not hasattr(estimates, 'Cn'):
estimates.Cn = cm.local_correlations(mov, swap_dim=False)
estimates.Cn = caiman.local_correlations(mov, swap_dim=False)
#Cn = estimates.Cn

# We rotate our components 90 degrees right because of incompatibility of pyqtgraph and pyplot
Expand Down
15 changes: 7 additions & 8 deletions caiman/behavior/behavior.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Functions related to optical flow
Expand All @@ -14,7 +13,7 @@
from sklearn.decomposition import NMF
import time

import caiman as cm
import caiman

try:
cv2.setNumThreads(0)
Expand Down Expand Up @@ -75,14 +74,14 @@ def extract_motor_components_OF(m,
mask = coo_matrix(np.array(mask).squeeze())
ms = [get_nonzero_subarray(mask.multiply(fr), mask) for fr in m]
ms = np.dstack(ms)
ms = cm.movie(ms.transpose([2, 0, 1]))
ms = caiman.movie(ms.transpose([2, 0, 1]))

else:
ms = m
of_or = compute_optical_flow(ms, do_show=False, polar_coord=False)
of_or = np.concatenate([
cm.movie(of_or[0]).resize(resize_fact, resize_fact, 1)[np.newaxis, :, :, :],
cm.movie(of_or[1]).resize(resize_fact, resize_fact, 1)[np.newaxis, :, :, :]
caiman.movie(of_or[0]).resize(resize_fact, resize_fact, 1)[np.newaxis, :, :, :],
caiman.movie(of_or[1]).resize(resize_fact, resize_fact, 1)[np.newaxis, :, :, :]
],
axis=0)

Expand Down Expand Up @@ -130,8 +129,8 @@ def extract_magnitude_and_angle_from_OF(spatial_filter_,
x, y = scipy.signal.medfilt(time_trace, kernel_size=[1, 1]).T
x = scipy.signal.savgol_filter(x.squeeze(), sav_filter_size, 1)
y = scipy.signal.savgol_filter(y.squeeze(), sav_filter_size, 1)
mag, dirct = to_polar(x - cm.components_evaluation.mode_robust(x),
y - cm.components_evaluation.mode_robust(y))
mag, dirct = to_polar(x - caiman.components_evaluation.mode_robust(x),
y - caiman.components_evaluation.mode_robust(y))
dirct = scipy.signal.medfilt(dirct.squeeze(), kernel_size=1).T

# normalize to pixel units
Expand Down Expand Up @@ -271,8 +270,8 @@ def compute_optical_flow(m,

return mov_tot

# NMF

#%% NMF
def extract_components(mov_tot,
n_components: int = 6,
normalize_std: bool = True,
Expand Down
16 changes: 8 additions & 8 deletions caiman/mmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Any, Optional, Union
import pathlib

import caiman as cm
import caiman
import caiman.paths

def prepare_shape(mytuple:tuple) -> tuple:
Expand Down Expand Up @@ -412,7 +412,7 @@ def save_memmap(filenames:list[str],

logging.debug('Distributing memory map over many files')
# Here we make a bunch of memmap files in the right order. Same parameters
fname_parts = cm.save_memmap_each(filenames,
fname_parts = caiman.save_memmap_each(filenames,
base_name=base_name,
order=order,
border_to_0=border_to_0,
Expand All @@ -432,7 +432,7 @@ def save_memmap(filenames:list[str],
if order == 'F':
raise Exception('You cannot merge files in F order, they must be in C order')

fname_new = cm.save_memmap_join(fname_parts, base_name=base_name,
fname_new = caiman.save_memmap_join(fname_parts, base_name=base_name,
dview=dview, n_chunks=n_chunks)

else:
Expand All @@ -458,9 +458,9 @@ def save_memmap(filenames:list[str],

else:
if isinstance(f, (str, list)):
Yr = cm.load(caiman.paths.fn_relocated(f), fr=1, in_memory=True, var_name_hdf5=var_name_hdf5)
Yr = caiman.load(caiman.paths.fn_relocated(f), fr=1, in_memory=True, var_name_hdf5=var_name_hdf5)
else:
Yr = cm.movie(f)
Yr = caiman.movie(f)
if xy_shifts is not None:
Yr = Yr.apply_shifts(xy_shifts, interpolation='cubic', remove_blanks=False)

Expand Down Expand Up @@ -492,7 +492,7 @@ def save_memmap(filenames:list[str],
fx, fy, fz = resize_fact
if fx != 1 or fy != 1 or fz != 1:
if 'movie' not in str(type(Yr)):
Yr = cm.movie(Yr, fr=1)
Yr = caiman.movie(Yr, fr=1)
Yr = Yr.resize(fx=fx, fy=fy, fz=fz)

T, dims = Yr.shape[0], Yr.shape[1:]
Expand All @@ -501,7 +501,7 @@ def save_memmap(filenames:list[str],
Yr = np.ascontiguousarray(Yr, dtype=np.float32) + np.float32(0.0001) + np.float32(add_to_movie)

if idx == 0:
fname_tot = cm.paths.generate_fname_tot(base_name, dims, order)
fname_tot = caiman.paths.generate_fname_tot(base_name, dims, order)
if isinstance(f, str):
fname_tot = caiman.paths.fn_relocated(os.path.join(os.path.split(f)[0], fname_tot))
if len(filenames) > 1:
Expand Down Expand Up @@ -643,7 +643,7 @@ def save_tif_to_mmap_online(movie_iterable, save_base_name='YrOL_', order='C', a

if isinstance(movie_iterable, str): # Allow specifying a filename rather than its data rep
with tifffile.TiffFile(movie_iterable) as tf: # And load it if that happens
movie_iterable = cm.movie(tf)
movie_iterable = caiman.movie(tf)

count = 0
new_mov = []
Expand Down
Loading

0 comments on commit e1c3f92

Please sign in to comment.