photutils
An Astropy coordinated package for detecting and performing photometry of astronomical sources. Provides tools for background estimation, source detection (DAOFIND, IRAF), aperture photometry, and PSF (Point Spread Function) fitting. Use when working with astronomical image analysis, star/galaxy detection, measuring brightness (photometry), background subtraction, PSF fitting, aperture photometry, centroiding, or isophotal analysis.
What this skill does
# Photutils - Astronomical Photometry
Photutils is the modern standard for extracting quantitative data from astronomical images. It replaces legacy tools like SExtractor or DAOPHOT with a modular, Pythonic interface integrated with the Astropy ecosystem.
## When to Use
- Detecting stars or galaxies in an astronomical image (DAOStarFinder, IRAFStarFinder).
- Measuring the brightness of objects using circular, elliptical, or rectangular apertures.
- Performing PSF-fitting photometry (essential for crowded stellar fields).
- Estimating and subtracting complex 2D backgrounds (sky background).
- Calculating the centroids (precise centers) of astronomical sources.
- Performing "isophotal analysis" (measuring shapes of galaxies).
- Segmentation of images based on thresholding.
## Reference Documentation
**Official docs**: https://photutils.readthedocs.io/
**GitHub**: https://github.com/astropy/photutils
**Search patterns**: `photutils.aperture`, `photutils.detection`, `photutils.background`, `photutils.psf`
## Core Principles
### Background First
Accurate photometry is impossible without correct background subtraction. Photutils provides tools to estimate global and local sky levels.
### Aperture vs. PSF
- **Aperture Photometry**: Summing pixels within a fixed shape. Best for isolated sources or galaxies.
- **PSF Photometry**: Fitting a mathematical model of a star to the data. Best for overlapping stars or high-precision work.
### Units and WCS
Photutils is fully units-aware. If your image has WCS metadata, apertures can be defined in sky coordinates (degrees) rather than just pixels.
## Quick Reference
### Installation
```bash
pip install photutils
```
### Standard Imports
```python
import numpy as np
import matplotlib.pyplot as plt
from astropy import units as u
from photutils.detection import DAOStarFinder
from photutils.aperture import CircularAperture, aperture_photometry
from photutils.background import Background2D, MedianBackground
```
### Basic Pattern - Detection and Aperture Photometry
```python
import numpy as np
from photutils.detection import DAOStarFinder
from photutils.aperture import CircularAperture, aperture_photometry
# 1. Detect sources
# fwhm: Full Width at Half Maximum of the stars
finder = DAOStarFinder(fwhm=3.0, threshold=5.*std)
sources = finder(image - background)
# 2. Define apertures at detected positions
positions = np.transpose((sources['xcentroid'], sources['ycentroid']))
apertures = CircularAperture(positions, r=4.0)
# 3. Perform photometry
phot_table = aperture_photometry(image - background, apertures)
print(phot_table)
```
## Critical Rules
### ✅ DO
- **Subtract background first** - Detection and photometry always work better on a background-subtracted image.
- **Use Background2D** - For images with varying sky levels, a 2D mesh estimation is more accurate than a single median value.
- **Specify the Gain** - For accurate error (uncertainty) estimation, provide the detector gain to `aperture_photometry`.
- **Match FWHM** - Ensure the `fwhm` parameter in finders matches the actual PSF of your images.
- **Vectorize apertures** - One `CircularAperture` object can hold thousands of positions; don't create them in a loop.
- **Use SkyAperture** - If you have a WCS, define apertures in RA/Dec to ensure they stay on target if the image is rotated or reprojected.
### ❌ DON'T
- **Ignore mask pixels** - If your image has bad pixels (cosmic rays, saturated stars), pass a mask to the photometry functions.
- **Use small apertures** - If an aperture is too small, you lose light (aperture correction required). If too large, you add noise.
- **Blindly trust defaults** - Always visualize your apertures on top of the image to verify they align with the stars.
- **Mix pixel and sky units** - Be careful whether you are passing (x, y) or (RA, Dec).
## Anti-Patterns (NEVER)
```python
# ❌ BAD: Manual pixel summation
# light_sum = np.sum(image[y-r:y+r, x-r:x+r]) # No circular masking!
# ✅ GOOD: Proper aperture photometry
from photutils.aperture import CircularAperture
ap = CircularAperture((x, y), r=r)
phot = aperture_photometry(image, ap)
# ❌ BAD: Detecting sources on raw data with high background
# finder = DAOStarFinder(threshold=100)(raw_image)
# ✅ GOOD: Detection on noise-subtracted data
from photutils.background import Background2D, MedianBackground
bkg = Background2D(image, (50, 50), filter_size=(3, 3), bkg_estimator=MedianBackground())
sources = finder(image - bkg.background)
```
## Background Estimation (photutils.background)
### Robust 2D Background Mapping
```python
from photutils.background import Background2D, MedianBackground
from astropy.stats import SigmaClip
sigma_clip = SigmaClip(sigma=3.0)
bkg_estimator = MedianBackground()
# box_size: size of the mesh grid
bkg = Background2D(image, box_size=(50, 50),
filter_size=(3, 3),
sigma_clip=sigma_clip,
bkg_estimator=bkg_estimator)
print(f"Global median background: {bkg.background_median}")
clean_image = image - bkg.background
```
## Source Detection (photutils.detection)
### Star Finding Algorithms
```python
from photutils.detection import DAOStarFinder, IRAFStarFinder
# DAOStarFinder: Optimized for stars
daofind = DAOStarFinder(fwhm=3.0, threshold=5.0*std)
sources = daofind(data)
# IRAFStarFinder: Alternative implementation
iraffind = IRAFStarFinder(threshold=5.0*std, fwhm=3.0)
sources_iraf = iraffind(data)
# Extract coordinates for photometry
positions = np.transpose((sources['xcentroid'], sources['ycentroid']))
```
## Aperture Photometry (photutils.aperture)
### Handling Multiple Shapes
```python
from photutils.aperture import CircularAperture, CircularAnnulus, aperture_photometry
# 1. Main aperture and Annulus (for local background)
positions = [(100.5, 120.3), (250.1, 88.4)]
aperture = CircularAperture(positions, r=5.0)
annulus = CircularAnnulus(positions, r_in=10.0, r_out=15.0)
# 2. Local background subtraction
# Calculate median in the annulus
annulus_masks = annulus.to_mask(method='center')
bkg_median = []
for mask in annulus_masks:
annulus_data = mask.multiply(image)
annulus_data_1d = annulus_data[mask.data > 0]
bkg_median.append(np.median(annulus_data_1d))
# 3. Perform photometry and subtract local background
phot = aperture_photometry(image, aperture)
phot['local_bkg'] = bkg_median
phot['aper_sum_corrected'] = phot['aperture_sum'] - (bkg_median * aperture.area)
```
## PSF Photometry (photutils.psf)
### Fitting Overlapping Sources
```python
from photutils.psf import BasicPSFFitter, IntegratedGaussianPRF
from photutils.background import MMMBackground
# 1. Define the PSF model (Gaussian or custom)
psf_model = IntegratedGaussianPRF(sigma=1.5)
# 2. Initialize the fitter
fitter = BasicPSFFitter(psf_model, fitshape=(11, 11),
finder=daofind,
bkg_estimator=MMMBackground())
# 3. Perform fitting
# result_table contains fitted x, y, and flux
result_table = fitter(image)
# 4. Get the residual image (original - fitted stars)
residual_image = fitter.get_residual_image()
```
## Centroiding (photutils.centroids)
### Precise Star Centering
```python
from photutils.centroids import centroid_com, centroid_2dg
# Center of mass (simple)
x1, y1 = centroid_com(image[y-5:y+6, x-5:x+6])
# 2D Gaussian fit (most precise for stars)
x2, y2 = centroid_2dg(image[y-5:y+6, x-5:x+6])
```
## Practical Workflows
### 1. Full Image Pipeline (Detection to Magnitude)
```python
def extract_magnitudes(image, zero_point=25.0):
# 1. Subtract 2D Background
bkg = Background2D(image, box_size=(64, 64))
data_sub = image - bkg.background
# 2. Detect sources
finder = DAOStarFinder(fwhm=2.5, threshold=5*bkg.background_rms_median)
sources = finder(data_sub)
# 3. Aperture Photometry
pos = np.transpose((sources['xcentroid'], sources['ycentroid']))
ap = CircularAperture(pos, r=4.0)
phot = apertRelated in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.