File tree 3 files changed +26
-0
lines changed
3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ API Changes
9
9
10
10
Bug Fixes
11
11
^^^^^^^^^
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]
12
14
13
15
Other changes
14
16
^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -174,6 +174,23 @@ def test_fit_trace():
174
174
FitTrace (img , bins = ncols + 1 )
175
175
176
176
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
+
177
194
@pytest .mark .filterwarnings ("ignore:The fit may be unsuccessful" )
178
195
@pytest .mark .filterwarnings ("ignore:Model is linear in parameters" )
179
196
class TestMasksTracing :
Original file line number Diff line number Diff line change @@ -413,6 +413,13 @@ def _fit_trace(self, img):
413
413
414
414
if self .peak_method == "gaussian" :
415
415
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
+
416
423
peak_y_i = ilum2 [z_i .argmax ()]
417
424
418
425
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