From e74f7b464b4fd0564fe8387aba54d26bd0779f3e Mon Sep 17 00:00:00 2001 From: AlexKurek Date: Sat, 19 Sep 2026 09:22:32 +0200 Subject: [PATCH 1/2] Fix ZeroDivisionError in moment analysis --- bdsf/functions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bdsf/functions.py b/bdsf/functions.py index 880b7a9f..47eb7bf1 100644 --- a/bdsf/functions.py +++ b/bdsf/functions.py @@ -437,8 +437,7 @@ def momanalmask_gaus(subim, mask, isrc, bmar_p, allpara=True): mompara[3] = sqrt((m2[0]+m2[1]+sqrt((m2[0]-m2[1])*(m2[0]-m2[1])+4.0*m11*m11))/(2.0*tot))*fwsig mompara[4] = sqrt((m2[0]+m2[1]-sqrt((m2[0]-m2[1])*(m2[0]-m2[1])+4.0*m11*m11))/(2.0*tot))*fwsig - dumr = atan(abs(2.0*m11/(m2[0]-m2[1]))) - dumr = atanproper(dumr, m2[0]-m2[1], 2.0*m11) + dumr = N.arctan2(2.0*m11, m2[0]-m2[1]) % (2.0*pi) mompara[5] = 0.5*dumr*180.0/pi - 90.0 if mompara[5] < 0.0: mompara[5] += 180.0 return mompara From 957ae1381c6338ac1e35bcfb9578cc29b6c1ff12 Mon Sep 17 00:00:00 2001 From: AlexKurek Date: Mon, 9 Nov 2026 19:26:39 +0100 Subject: [PATCH 2/2] Remove `atanproper` --- bdsf/functions.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/bdsf/functions.py b/bdsf/functions.py index 39abca18..2ce3a627 100644 --- a/bdsf/functions.py +++ b/bdsf/functions.py @@ -45,28 +45,13 @@ def shapeletfit(cf, Bset, cfshape): return y -def atanproper(dumr, dx, dy): - from math import pi - - ysign = (dy >= 0.0) - xsign = (dx >= 0.0) - if ysign and (not xsign): dumr = pi - dumr - if (not ysign) and (not xsign): dumr = pi + dumr - if (not ysign) and xsign: dumr = 2.0*pi - dumr - - return dumr - def gdist_pa(pix1, pix2, gsize): """ Computes FWHM in degrees in the direction towards second source, of an elliptical gaussian. """ - from math import atan, pi, sqrt, cos, sin, tan + from math import atan, atan2, pi, sqrt, cos, sin, tan dx = pix2[0] - pix1[0] dy = pix2[1] - pix1[1] - if dx == 0.0: - val = pi/2.0 - else: - dumr = atan(abs(dy/dx)) - val = atanproper(dumr, dx, dy) + val = atan2(dy, dx) psi = val - (gsize[2]+90.0)/180.0*pi