From a3c6a14215813f9dfbc97b1fec986e54029bcdd8 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 26 Jul 2021 15:10:22 +0100 Subject: [PATCH] Fix radius calculation. --- findingchart.py | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/findingchart.py b/findingchart.py index eccb6e5..289b2b5 100644 --- a/findingchart.py +++ b/findingchart.py @@ -43,35 +43,35 @@ def estimate_half_radius(image, fallback): thresh = 5 * bkg.globalrms raw_objects = sep.extract(subtracted, thresh) - radius = [] - for star in raw_objects: - # Discard spuriously small sources - if star['npix'] < 16: - continue - - x = star['x'] - y = star['y'] - a = star['a'] - b = star['b'] - theta = star['theta'] - kronrad, flag = sep.kron_radius(subtracted, x, y, a, b, theta, 6.0) - if flag != 0: - continue - - flux, _, flag = sep.sum_ellipse(subtracted, x, y, a, b, theta, 2.5 * kronrad, - subpix=0) - if flag != 0: - continue - - r, flag = sep.flux_radius(subtracted, x, y, 6.0 * a, 0.5, normflux=flux, subpix=5) - if flag != 0: - continue - - radius.append(r) + kronrad, kronrad_flag = sep.kron_radius( + subtracted, + raw_objects['x'], raw_objects['y'], + raw_objects['a'], raw_objects['b'], + raw_objects['theta'], 6.0) + + flux, _, flux_flag = sep.sum_ellipse( + subtracted, + raw_objects['x'], raw_objects['y'], + raw_objects['a'], raw_objects['b'], + raw_objects['theta'], 2.5 * kronrad, subpix=0) + + r, r_flag = sep.flux_radius( + subtracted, + raw_objects['x'], raw_objects['y'], + 6.0 * raw_objects['a'], + 0.5, normflux=flux, subpix=5) + + # Discard spuriously small sources or those with errors + valid = numpy.logical_and.reduce([ + raw_objects['npix'] >= 16, + kronrad_flag == 0, + flux_flag == 0, + r_flag == 0 + ]) # Require at least 10 objects for a more robust estimation - if len(radius) > 10: - return numpy.median(radius) + if numpy.sum(valid) > 10: + return numpy.median(r[valid]) return fallback