File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ API Changes
99
1010Bug Fixes
1111^^^^^^^^^
12+ - When all-zero bin encountered in fit_trace with peak_method=gaussian, the bin peak
13+ will be set to NaN in this caseto work better with DogBoxLSQFitter. [#257]
1214
1315Other changes
1416^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -174,6 +174,23 @@ def test_fit_trace():
174174 FitTrace (img , bins = ncols + 1 )
175175
176176
177+ def test_fit_trace_gaussian_all_zero ():
178+ """
179+ Test fit_trace when peak_method is 'gaussian', which uses DogBoxLSQFitter
180+ for the fit for each bin peak and does not work well with all-zero columns.
181+ In this case, an all zero bin should fall back to NaN to for its'
182+ peak to be filtered out in the final fit for the trace.
183+ """
184+ img = mk_img (ncols = 100 )
185+ # add some all-zero columns so there is an all-zero bin
186+ img [:, 10 :20 ] = 0
187+
188+ t = FitTrace (img , bins = 10 , peak_method = 'gaussian' )
189+
190+ # this is a pretty flat trace, so make sure the fit reflects that
191+ assert np .all ((t .trace >= 99 ) & (t .trace <= 101 ))
192+
193+
177194@pytest .mark .filterwarnings ("ignore:The fit may be unsuccessful" )
178195@pytest .mark .filterwarnings ("ignore:Model is linear in parameters" )
179196class TestMasksTracing :
Original file line number Diff line number Diff line change @@ -413,6 +413,13 @@ def _fit_trace(self, img):
413413
414414 if self .peak_method == "gaussian" :
415415
416+ # if bin is fully 0, set bin peak to nan so it doesn't bias the
417+ # all-bin fit. DogBoxLSQFitter, which is always used for the bin
418+ # center fits when peak_method is gaussian, does not like all zeros.
419+ if np .all (z_i == 0.0 ):
420+ y_bins [i ] = np .nan
421+ continue
422+
416423 peak_y_i = ilum2 [z_i .argmax ()]
417424
418425 yy_i_above_half_max = np .sum (z_i > (z_i .max () / 2 ))
You can’t perform that action at this time.
0 commit comments