<jupyter_start><jupyter_text>Source detection full reduction comparison<jupyter_code>import sys
sys.path.append('.')
import numpy as np
from matplotlib import pyplot as plt
%matplotlib notebook
from scipy.ndimage.filters import convolve

from library.gen_image import gen_image

from photutils.detection import DAOStarFinder
from photutils.datasets import load_star_image

from astropop.photometry.detection import daofind, starfind, sepfind

from astropy.stats import gaussian_fwhm_to_sigma<jupyter_output><empty_output><jupyter_text>General performance- Photutils seems to find a bit more weak sources, but gives more doubled results in saturated stars.- The missing stars in `starfind`, in general, are excluded due to bad `roundness`. Values of roundness computed from photutils seems to be smaller than computed by astropop. So, less exclusion.- Weak stars near strong ones seems to suffer an interference in `roundness`.- Segmentation is the only one to handle well saturated stars.<jupyter_code>hdu = load_star_image()
im = hdu.data[:400, :400].astype('f8')
fwhm = 5
bkg = np.median(im)
rms = np.std(im)
thresh = 4
fig, ax = plt.subplots(1, 1, figsize=(8, 8))

dao = DAOStarFinder(fwhm=fwhm, threshold=thresh*rms)
sources_photutils = dao.find_stars(im-bkg)
sources_sep = sepfind(im, thresh, bkg, rms)
sources_starfind_norej = starfind(im, thresh, bkg, rms, sharp_limit=None, round_limit=None, skip_invalid_centroid=True)
sources_starfind_crej = starfind(im, thresh, bkg, rms, sharp_limit=None, round_limit=None)
sources_starfind = starfind(im, thresh, bkg, rms)

ax.imshow(im, origin='lower', vmax=12000, cmap='gray_r')
ax.plot(sources_starfind['x'], sources_starfind['y'], 'co', ms=10, alpha=0.5, label='StarFind (reject)')
ax.plot(sources_photutils['xcentroid'], sources_photutils['ycentroid'], 'xb', ms=10, alpha=0.5, label='Photutils')
ax.plot(sources_sep['x'], sources_sep['y'], '.g', ms=10, alpha=0.5, label='SEP')
ax.plot(sources_starfind_crej['x'], sources_starfind_crej['y'], 'vm', ms=5, alpha=0.5, label='StarFind (centr.-rej)')
ax.plot(sources_starfind_norej['x'], sources_starfind_norej['y'], '+y', ms=10, alpha=0.5, label='StarFind (no-rej)')

print(f'Photutils: {len(sources_photutils)}')
print(f'Starfind: {len(sources_starfind)}')
print(f'Starfind (no-rejection): {len(sources_starfind_norej)}')
print(f'Starfind (centroid-rejection): {len(sources_starfind_crej)}')

plt.tight_layout()
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13525588952071488, 'fraction_numerical': 0.015028432168968318, 'mean_word_length': 7.73404255319149, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '301073', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 915, 'n_tokens_neox': 873, 'n_words': 213, 'path': 'source_detection_full.ipynb', 'repo_name': 'sparc4-dev/astropop-studies', 'size': '2462'}