@@ -496,7 +496,8 @@ def moments_enhanced(
496496 # position of the Gaussian peak.
497497 rounded_barycenter = int (round (xbar )), int (round (ybar ))
498498 mask = (posx == rounded_barycenter [0 ]) & (posy == rounded_barycenter [1 ])
499- if mask .any ():
499+ in_source_island = mask .any ()
500+ if in_source_island :
500501 # In this case the rounded barycenter position is in source_island.
501502 # Note that mask, from the way that posx and posy have been constructed,
502503 # can have no more than one True value.
@@ -517,16 +518,19 @@ def moments_enhanced(
517518 smaj = beam [0 ]
518519 smin = beam [1 ]
519520 theta = beam [2 ]
520- # Implementation of "tweaked moments", equation 2.66 from
521- # Spreeuw's thesis. In that formula the "base position" was the
522- # maximum pixel position, though. Here that is the rounded
523- # barycenter position, unless it's masked. If it's masked, it
524- # will be the maximum pixel position.
525- exponent = np .log (2.0 ) * (
526- ((np .cos (theta ) * deltax + np .sin (theta ) * deltay ) / smin ) ** 2
527- + ((np .cos (theta ) * deltay - np .sin (theta ) * deltax ) / smaj ) ** 2
528- )
529- peak = np .exp (exponent ) * basevalue
521+
522+ if in_source_island :
523+ # Implementation of "tweaked moments", equation 2.66 from
524+ # Spreeuw's thesis. In that formula the "base position" was the
525+ # maximum pixel position, though. Here that is the rounded
526+ # barycenter position, unless it's masked. If it's masked, it
527+ # will be the maximum pixel position.
528+ exponent = np .log (2.0 ) * (
529+ ((np .cos (theta ) * deltax + np .sin (theta ) * deltay ) / smin ) ** 2
530+ + ((np .cos (theta ) * deltay - np .sin (theta ) * deltax ) / smaj )
531+ ** 2
532+ )
533+ peak = np .exp (exponent ) * basevalue
530534
531535 else :
532536 xxbar , yybar , xybar = 0 , 0 , 0
0 commit comments