Skip to content

Commit

Permalink
Include interval ends for sharpless, roundness, and peakmax (#1978)
Browse files Browse the repository at this point in the history
* Include interval ends for sharpless, roundness, and peakmax

* Fix style

* Add changelog entry

* Add test for DAO and fix mask for DAO

* fix DAO test failure on ubuntu
  • Loading branch information
mcara authored Jan 3, 2025
1 parent 3d06161 commit 715eae0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ API Changes
different along the x and y edges if the kernel shape is rectangular.
[#1957]

- Detected sources that match interval ends for sharpness, roundness, and
maximum peak values (``sharplo``, ``sharphi``, ``roundlo``, ``roundhi``,
and ``peakmax``) are now included in the returned table of detected
sources by ``DAOStarFinder`` and ``IRAFStarFinder``. [#1978]

- ``photutils.morphology``

- The ``gini`` function now returns zero instead of NaN if the
Expand Down
14 changes: 7 additions & 7 deletions photutils/detection/daofinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,14 @@ def apply_filters(self):
return None

# filter based on sharpness, roundness, and peakmax
mask = ((newcat.sharpness > newcat.sharplo)
& (newcat.sharpness < newcat.sharphi)
& (newcat.roundness1 > newcat.roundlo)
& (newcat.roundness1 < newcat.roundhi)
& (newcat.roundness2 > newcat.roundlo)
& (newcat.roundness2 < newcat.roundhi))
mask = ((newcat.sharpness >= newcat.sharplo)
& (newcat.sharpness <= newcat.sharphi)
& (newcat.roundness1 >= newcat.roundlo)
& (newcat.roundness1 <= newcat.roundhi)
& (newcat.roundness2 >= newcat.roundlo)
& (newcat.roundness2 <= newcat.roundhi))
if newcat.peakmax is not None:
mask &= (newcat.peak < newcat.peakmax)
mask &= (newcat.peak <= newcat.peakmax)
newcat = newcat[mask]

if len(newcat) == 0:
Expand Down
10 changes: 5 additions & 5 deletions photutils/detection/irafstarfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,12 @@ def apply_filters(self):
return None

# filter based on sharpness, roundness, and peakmax
mask = ((newcat.sharpness > newcat.sharplo)
& (newcat.sharpness < newcat.sharphi)
& (newcat.roundness > newcat.roundlo)
& (newcat.roundness < newcat.roundhi))
mask = ((newcat.sharpness >= newcat.sharplo)
& (newcat.sharpness <= newcat.sharphi)
& (newcat.roundness >= newcat.roundlo)
& (newcat.roundness <= newcat.roundhi))
if newcat.peakmax is not None:
mask &= (newcat.peak < newcat.peakmax)
mask &= (newcat.peak <= newcat.peakmax)
newcat = newcat[mask]

if len(newcat) == 0:
Expand Down
27 changes: 27 additions & 0 deletions photutils/detection/tests/test_daofinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,30 @@ def test_single_detected_source(self, data):
assert cat.isscalar
flux = cat.flux[0] # evaluate the flux so it can be sliced
assert cat[0].flux == flux

def test_interval_ends_included(self):
# https://github.com/astropy/photutils/issues/1977
data = np.zeros((46, 64))

x = 33
y = 21

data[y - 1: y + 2, x - 1: x + 2] = [
[1.0, 2.0, 1.0],
[2.0, 1.0e20, 2.0],
[1.0, 2.0, 1.0],
]

finder = DAOStarFinder(
threshold=0,
fwhm=2.5,
roundlo=0,
sharphi=1.407913491884342,
peakmax=1.0e20
)
tbl = finder.find_stars(data)

assert len(tbl) == 1
assert abs(tbl[0]['roundness1']) < 1.e-15
assert abs(tbl[0]['roundness2']) == 0.0
assert abs(tbl[0]['peak']) == 1.0e20
25 changes: 25 additions & 0 deletions photutils/detection/tests/test_irafstarfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,28 @@ def test_all_border_sources(self):
data += model3(xx, yy)
tbl = finder(data)
assert len(tbl) == 1

def test_interval_ends_included(self):
# https://github.com/astropy/photutils/issues/1977
data = np.zeros((46, 64))

x = 33
y = 21
data[y - 1: y + 2, x - 1: x + 2] = [
[0.1, 0.6, 0.1],
[0.6, 0.8, 0.6],
[0.1, 0.6, 0.1],
]

finder = IRAFStarFinder(
threshold=0,
fwhm=2.5,
roundlo=0,
peakmax=0.8
)
tbl = finder.find_stars(data)

assert len(tbl) == 1
assert abs(tbl[0]['roundness']) == 0.0
assert abs(tbl[0]['pa']) == 0.0
assert abs(tbl[0]['peak']) == 0.8

0 comments on commit 715eae0

Please sign in to comment.