Skip to content

Commit

Permalink
Merge pull request #936 from flatironinstitute/dev
Browse files Browse the repository at this point in the history
Merge dev to master to prepare for release
  • Loading branch information
pgunn authored Nov 19, 2021
2 parents a814402 + c34d2ab commit 8d9ff55
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion caiman/base/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ def load(file_name: Union[str, List[str]],
np.arange(shape[1]))
).reshape((len(ts),) + shape[1:])
else:
input_arr = tffl.asarray()
input_arr = tffl.asarray(out='memmap')
input_arr = input_arr[subindices]

else:
Expand Down
4 changes: 3 additions & 1 deletion caiman/source_extraction/cnmf/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ def onclick(event):
[ai, ci_raw, ind_success] = extract_ac(data_filtered_box,
data_raw_box, ind_ctr, patch_dims)

if (np.sum(ai > 0) < min_pixel) or (not ind_success):
if (not ind_success) or (np.sum(ai > 0) < min_pixel):
# bad initialization. discard and continue
continue
else:
Expand Down Expand Up @@ -1903,6 +1903,8 @@ def extract_ac(data_filtered, data_raw, ind_ctr, patch_dims):
y_diff = np.concatenate([[-1], np.diff(ci)])
b = np.median(ci[(y_diff >= 0) * (y_diff < sn)])
ci -= b
if np.isnan(ci.sum()):
return None, None, False

# return results
return ai, ci, True
Expand Down
29 changes: 13 additions & 16 deletions caiman/source_extraction/cnmf/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,24 @@ def update_spatial_components(Y, C=None, f=None, A_in=None, sn=None, dims=None,
# we compute the indicator from distance indicator
ind2_, nr, C, f, b_, A_in = computing_indicator(
Y, A_in, b_in, C, f, nb, method_exp, dims, min_size, max_size, dist, expandCore, dview)

# remove components that have a nan
ff = np.where(np.isnan(np.sum(C, axis=1)))
if np.size(ff) > 0:
logging.info("Eliminating nan components: {}".format(ff))
ff = ff[0]
A_in = csc_column_remove(A_in, list(ff))
C = np.delete(C, list(ff), 0)

# remove empty components
ff = np.where(np.sum(C, axis=1)==0)

# remove components that are empty or have a nan
ff = np.where((np.sum(C, axis=1)==0) + np.isnan(np.sum(C, axis=1)))[0]
if np.size(ff) > 0:
logging.info("Eliminating empty components: {}".format(ff))
ff = ff[0]
logging.info("Eliminating empty and nan components: {}".format(ff))
A_in = csc_column_remove(A_in, list(ff))
C = np.delete(C, list(ff), 0)

# update indices
ind_list = list(range(nr-np.size(ff)))
for i in ff:
ind_list.insert(i, 0)
ind_list = np.array(ind_list, dtype=int)
ind2_ = [ind_list[np.setdiff1d(a,ff)] if len(a) else a for a in ind2_]

nr = np.shape(C)[0]
if normalize_yyt_one and C is not None:
C = np.array(C)
nr_C = np.shape(C)[0]
d_ = scipy.sparse.lil_matrix((nr_C, nr_C))
d_ = scipy.sparse.lil_matrix((nr, nr))
d_.setdiag(np.sqrt(np.sum(C ** 2, 1)))
A_in = A_in * d_
C = C/(np.sqrt((C**2).sum(1))[:, np.newaxis] + np.finfo(np.float32).eps)
Expand Down

0 comments on commit 8d9ff55

Please sign in to comment.