Skip to content

Commit 4fd2f1b

Browse files
committed
Fix index swap, component off-by-one, and QE infinity in pipeline
helpers.py: - _clip_region: fix image[rx,ry] → image[ry,rx] in the threshold check so it is consistent with the stats computation; previously stats were computed on image[ry,rx] (y,x) but the mask was applied to image[rx,ry] (x,y), clipping the wrong pixels - grad_clip_fill_bkg: fix component size filter to cover all labeled regions 1..n_objects; previous [:n_objects] slice excluded the last real component and included the background (label 0), allowing the final artifact to bypass size filtering tessreduce.py: - _calc_qe: replace zero-only guard with np.isfinite check so infinities produced by division by zero background are also converted to NaN before sigma-clipping; suppress the runtime warning with np.errstate
1 parent 0587f29 commit 4fd2f1b

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎tessreduce/helpers.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ def Extract_fits(pixelfile):
11161116

11171117
def _clip_region(image, rx, ry, sigma, iters):
11181118
m, me, s = sigma_clipped_stats(image[ry, rx], maxiters=iters)
1119-
cut = (image[rx, ry] >= me + sigma * s) | (image[rx, ry] <= me - sigma * s)
1119+
cut = (image[ry, rx] >= me + sigma * s) | (image[ry, rx] <= me - sigma * s)
11201120
return rx[cut], ry[cut]
11211121

11221122
def regional_stats_mask(image, size=90, sigma=3, iters=10, n_jobs=1):
@@ -1221,16 +1221,16 @@ def grad_clip_fill_bkg(bkg,sigma=3,max_size=1000):
12211221
b_labeled, b_objects = label(bp)
12221222
a_labeled, a_objects = label(ap)
12231223

1224-
# Component sizes via bincount (preserves original loop range 0..n_objects-1)
1225-
b_obj_size = np.bincount(b_labeled.ravel(), minlength=b_objects + 1)[:b_objects]
1226-
a_obj_size = np.bincount(a_labeled.ravel(), minlength=a_objects + 1)[:a_objects]
1224+
# Component sizes via bincount — labels 1..n_objects, index 0 is background
1225+
b_obj_size = np.bincount(b_labeled.ravel(), minlength=b_objects + 1)
1226+
a_obj_size = np.bincount(a_labeled.ravel(), minlength=a_objects + 1)
12271227

1228-
# Zero out components outside the valid size range
1229-
bad_a = np.where((a_obj_size >= max_size) | (a_obj_size <= 9))[0]
1228+
# Zero out components outside the valid size range (skip label 0 = background)
1229+
bad_a = np.where((a_obj_size[1:] >= max_size) | (a_obj_size[1:] <= 9))[0] + 1
12301230
if len(bad_a) > 0:
12311231
a_labeled[np.isin(a_labeled, bad_a)] = 0
12321232

1233-
bad_b = np.where((b_obj_size >= max_size) | (b_obj_size <= 9))[0]
1233+
bad_b = np.where((b_obj_size[1:] >= max_size) | (b_obj_size[1:] <= 9))[0] + 1
12341234
if len(bad_b) > 0:
12351235
b_labeled[np.isin(b_labeled, bad_b)] = 0
12361236

‎tessreduce/tessreduce.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,9 @@ def _calc_qe(self):#,flux_e):
671671
'''
672672
time = deepcopy(self.mjd)
673673
strap_data = (self.flux) * ((self.mask&4) > 0)*(~self.mask&1)
674-
qe = strap_data/self.bkg
675-
qe[qe == 0] = np.nan
674+
with np.errstate(divide='ignore', invalid='ignore'):
675+
qe = strap_data / self.bkg
676+
qe[~np.isfinite(qe)] = np.nan
676677
m,med,std = sigma_clipped_stats(qe,axis=1,sigma_upper=2)
677678
qes = np.ones_like(qe)
678679
qes[:,:,:] = med[:,np.newaxis,:]

0 commit comments

Comments
 (0)