Photutils

2.3.0 · active · verified Thu Apr 16

Photutils is an Astropy package for detecting and performing photometry on astronomical sources in image data. It provides tools for source detection, background estimation, aperture and PSF photometry, and image segmentation. Photutils is actively maintained, with new minor versions typically released every 1-3 months, following Astropy's release cycle. The current stable version is 2.3.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic `photutils` workflow: generating synthetic image data, estimating and subtracting the background, detecting point sources using DAOStarFinder, and performing aperture photometry on the detected sources. This covers fundamental steps in analyzing astronomical images.

import numpy as np
from astropy.stats import sigma_clipped_stats
from photutils.detection import DAOStarFinder
from photutils.background import Background2D, MedianBackground
from photutils.aperture import CircularAperture, aperture_photometry

# Create dummy data (replace with your actual FITS data)
data = np.random.rand(100, 100) * 100
y, x = np.mgrid[0:100, 0:100]
data += 500 * np.exp(-((x - 20)**2 + (y - 20)**2) / (2 * 5**2)) # Add a star
data += 700 * np.exp(-((x - 70)**2 + (y - 80)**2) / (2 * 7**2)) # Add another star

# 1. Estimate background
mean_bkg, median_bkg, std_bkg = sigma_clipped_stats(data, sigma=3.0)
bkg = Background2D(data, (50, 50), filter_size=(3, 3),
                   bkg_estimator=MedianBackground())
data_subtracted = data - bkg.background

# 2. Detect sources
finder = DAOStarFinder(fwhm=5.0, threshold=3.0 * std_bkg)
sources = finder(data_subtracted)

if sources is None:
    print("No sources found. Adjust DAOStarFinder parameters.")
else:
    print(f"Detected {len(sources)} sources:")
    for col in sources.colnames:
        sources[col].info.format = '%.8g'  # for consistent output
    print(sources)

    # 3. Perform aperture photometry
    positions = (sources['xcentroid'], sources['ycentroid'])
    aperture = CircularAperture(positions, r=8.0)
    phot_table = aperture_photometry(data_subtracted, aperture)

    print("\nAperture Photometry:")
    for col in phot_table.colnames:
        phot_table[col].info.format = '%.8g'  # for consistent output
    print(phot_table)

view raw JSON →