Skip to content

Commit 05f7ffe

Browse files
authored
Merge pull request #1501 from flatironinstitute/unpack_oasis_call_and_typecast_to_scalar
Fix docs for part of components_evaluation, cast types to deal with upstream, unroll one-liner
2 parents 80d986b + 05d7699 commit 05f7ffe

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

caiman/components_evaluation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ def compute_event_exceptionality(traces: np.ndarray,
6767
erfc: ndarray
6868
probability at each time step of observing the N consecutive actual trace values given the distribution of noise
6969
70-
noise_est: ndarray
71-
the components ordered according to the fitness
70+
std_r:
71+
Standard deviation of r
72+
73+
mode:
74+
Mode of the traces
7275
"""
7376
if N == 0:
7477
# Without this, numpy ranged syntax does not work correctly, and also N=0 is conceptually incoherent
@@ -85,7 +88,6 @@ def compute_event_exceptionality(traces: np.ndarray,
8588
# only consider values under the mode to determine the noise standard deviation
8689
ff1 = -ff1 * (ff1 < 0)
8790
if robust_std:
88-
8991
# compute 25 percentile
9092
ff1 = np.sort(ff1, axis=1)
9193
ff1[ff1 == 0] = np.nan

caiman/source_extraction/cnmf/online_cnmf.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ def update_num_components(t, sv, Ab, Cf, Yres_buf, Y_buf, rho_buf,
21922192
for ij in ijSig]), dims, order='F').ravel()
21932193

21942194
cin_circ = cin.get_ordered()
2195-
useOASIS = False # whether to use faster OASIS for cell detection
2195+
useOASIS = False # whether to use faster OASIS for cell detection FIXME don't hardcode things internally like this
21962196
accepted = True # flag indicating new component has not been rejected yet
21972197

21982198
if Ab_dense is None:
@@ -2248,18 +2248,32 @@ def update_num_components(t, sv, Ab, Cf, Yres_buf, Y_buf, rho_buf,
22482248
ind_new.append(ijSig)
22492249

22502250
if oases is not None:
2251-
if not useOASIS:
2251+
if not useOASIS: # FIXME bad variable name, also hardcoded?
22522252
# lambda from Selesnick's 3*sigma*|K| rule
22532253
# use noise estimate from init batch or use std_rr?
22542254
# sn_ = sqrt((ain**2).dot(sn[indices]**2)) / sqrt(1 - g**2)
2255+
# The one-liner below was too hard to read -- breaking it apart for legibility
2256+
# (and also to make it easier to temporarily add assertions with np.isscalar and
2257+
# unpack size-1 arrays that are no longer ok in newer versions of numpy/scipy)
22552258
sn_ = std_rr
2256-
oas = OASIS(np.ravel(g)[0], 3 * sn_ /
2257-
(sqrt(1 - g**2) if np.size(g) == 1 else
2258-
sqrt((1 + g[1]) * ((1 - g[1])**2 - g[0]**2) / (1 - g[1])))
2259-
if s_min == 0 else 0,
2260-
s_min, num_empty_samples=t +
2261-
1 - len(cin_res),
2262-
g2=0 if np.size(g) == 1 else g[1])
2259+
if np.size(sn_) == 1:
2260+
sn_ = np.ravel(std_rr)[0]
2261+
else:
2262+
logger.warning("std_rr has more dimensionality than expected and this may lead to problems")
2263+
sn_ = std_rr
2264+
2265+
oasis_g = np.ravel(g)[0]
2266+
if s_min != 0:
2267+
oasis_lambda = 0
2268+
elif np.size(g) == 1:
2269+
oasis_lambda = 3 * sn_ / (sqrt(1 - np.ravel(g)[0]**2))
2270+
else:
2271+
oasis_lambda = 3 * sn_ / sqrt((1 + np.ravel(g)[1]) * ((1 - np.ravel(g)[1])**2 - np.ravel(g)[0]**2) / (1 - np.ravel(g)[1]))
2272+
2273+
oasis_ne = t + 1 - len(cin_res)
2274+
oasis_g2 = 0 if np.size(g) == 1 else np.ravel(g)[1]
2275+
2276+
oas = OASIS(oasis_g, oasis_lambda, s_min, num_empty_samples=oasis_ne, g2=oasis_g2)
22632277
for yt in cin_res:
22642278
oas.fit_next(yt)
22652279

0 commit comments

Comments
 (0)