Skip to content

Commit c96445e

Browse files
authored
Merge pull request #1341 from ivenzor/issue_1340
PR to solve Issue 1340
2 parents 78c5bf4 + 9d84dd3 commit c96445e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

exotic/exotic.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -1245,16 +1245,28 @@ def fcn2min(pars):
12451245

12461246
# Method calculates the flux of the star (uses the skybg_phot method to do background sub)
12471247
def aperPhot(data, starIndex, xc, yc, r=5, dr=5):
1248-
if dr > 0 and not np.isnan(xc) and not np.isnan(yc):
1248+
# Check for invalid coordinates
1249+
if np.isnan(xc) or np.isnan(yc):
1250+
return 0, 0
1251+
1252+
# Calculate background if dr > 0
1253+
if dr > 0:
12491254
bgflux, sigmabg, Nbg = skybg_phot(data, starIndex, xc, yc, r + 2, dr)
12501255
else:
12511256
bgflux, sigmabg, Nbg = 0, 0, 0
1252-
1257+
1258+
# Create aperture and mask
12531259
aperture = CircularAperture(positions=[(xc, yc)], r=r)
12541260
mask = aperture.to_mask(method='exact')[0]
12551261
data_cutout = mask.cutout(data)
1262+
1263+
# Check if aperture is valid
1264+
if data_cutout is None:
1265+
# Aperture is partially or fully outside the image
1266+
return 0, bgflux # Return zero flux but valid background
1267+
1268+
# Calculate and return aperture sum
12561269
aperture_sum = (mask.data * (data_cutout - bgflux)).sum()
1257-
12581270
return aperture_sum, bgflux
12591271

12601272

0 commit comments

Comments
 (0)