Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include interval ends for sharpless, roundness, and peakmax #1978

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading