@@ -47,7 +47,7 @@ def detect(ops, classfile=None):
4747
4848 if ops .get ('anatomical_only' , 0 ) > 0 and CELLPOSE_INSTALLED :
4949 print ('>>>> CELLPOSE finding masks in ' + ['max_proj / mean_img' , 'mean_img' , 'enhanced_mean_img' ][int (ops ['anatomical_only' ])- 1 ])
50- stats = anatomical .select_rois (
50+ stat = anatomical .select_rois (
5151 ops = ops ,
5252 mov = mov ,
5353 dy = dy ,
@@ -57,7 +57,7 @@ def detect(ops, classfile=None):
5757 diameter = ops ['diameter' ])
5858
5959 else :
60- stats = select_rois (
60+ stat = select_rois (
6161 ops = ops ,
6262 mov = mov ,
6363 dy = dy ,
@@ -74,10 +74,10 @@ def detect(ops, classfile=None):
7474 if 'meanImg_chan2' in ops :
7575 if 'chan2_thres' not in ops :
7676 ops ['chan2_thres' ] = 0.65
77- ops , redcell = chan2detect .detect (ops , stats )
77+ ops , redcell = chan2detect .detect (ops , stat )
7878 np .save (Path (ops ['save_path' ]).joinpath ('redcell.npy' ), redcell )
7979
80- return ops , stats
80+ return ops , stat
8181
8282def select_rois (ops : Dict [str , Any ], mov : np .ndarray , dy : int , dx : int , Ly : int , Lx : int ,
8383 max_overlap : float = True , sparse_mode : bool = True , do_crop : bool = True ,
@@ -86,7 +86,7 @@ def select_rois(ops: Dict[str, Any], mov: np.ndarray, dy: int, dx: int, Ly: int,
8686 t0 = time .time ()
8787 if sparse_mode :
8888 ops .update ({'Lyc' : mov .shape [1 ], 'Lxc' : mov .shape [2 ]})
89- new_ops , stats = sparsedetect .sparsery (
89+ new_ops , stat = sparsedetect .sparsery (
9090 mov = mov ,
9191 high_pass = ops ['high_pass' ],
9292 neuropil_high_pass = ops ['spatial_hp_detect' ],
@@ -100,29 +100,32 @@ def select_rois(ops: Dict[str, Any], mov: np.ndarray, dy: int, dx: int, Ly: int,
100100 )
101101 ops .update (new_ops )
102102 else :
103- ops , stats = sourcery .sourcery (mov = mov , ops = ops )
103+ ops , stat = sourcery .sourcery (mov = mov , ops = ops )
104104
105- print ('Detected %d ROIs, %0.2f sec' % (len (stats ), time .time () - t0 ))
106- stats = np .array (stats )
105+ print ('Detected %d ROIs, %0.2f sec' % (len (stat ), time .time () - t0 ))
106+ stat = np .array (stat )
107+
108+ if len (stat )== 0 :
109+ raise ValueError ("no ROIs were found -- check registered binary and maybe change spatial scale" )
107110
108111 if ops ['preclassify' ] > 0 :
109112 if classfile is None :
110113 print (f'NOTE: Applying user classifier at { str (user_classfile )} ' )
111114 classfile = user_classfile
112115
113- stats = roi_stats (stats , dy , dx , Ly , Lx , do_crop = do_crop )
114- if len (stats ) == 0 :
116+ stat = roi_stats (stat , dy , dx , Ly , Lx , do_crop = do_crop )
117+ if len (stat ) == 0 :
115118 iscell = np .zeros ((0 , 2 ))
116119 else :
117- iscell = classify (stat = stats , classfile = classfile )
120+ iscell = classify (stat = stat , classfile = classfile )
118121 np .save (Path (ops ['save_path' ]).joinpath ('iscell.npy' ), iscell )
119122 ic = (iscell [:,0 ]> ops ['preclassify' ]).flatten ().astype (np .bool )
120- stats = stats [ic ]
123+ stat = stat [ic ]
121124 print ('Preclassify threshold %0.2f, %d ROIs removed' % (ops ['preclassify' ], (~ ic ).sum ()))
122-
123- # add ROI stats to stats
124- stats = roi_stats (stats , dy , dx , Ly , Lx , max_overlap = max_overlap , do_crop = do_crop )
125+
126+ # add ROI stat to stat
127+ stat = roi_stats (stat , dy , dx , Ly , Lx , max_overlap = max_overlap , do_crop = do_crop )
125128
126- print ('After removing overlaps, %d ROIs remain' % (len (stats )))
127- return stats
129+ print ('After removing overlaps, %d ROIs remain' % (len (stat )))
130+ return stat
128131
0 commit comments