potpyri.primitives.photometry

Aperture and PSF photometry for pipeline stacks.

Uses Source Extractor for initial catalogs, photutils for ePSF building and PSF fitting. Writes APPPHOT, PSFPHOT, PSFSTARS, PSF, and RESIDUAL extensions to the stack FITS. Authors: Kerry Paterson, Charlie Kilpatrick.

Functions

create_conv(outfile)

Write a 3x3 CONV NORM filter file for Source Extractor.

create_params(outfile)

Write Source Extractor parameter file (NUMBER, X_IMAGE, FWHM_IMAGE, etc.).

do_phot(img_file[, fwhm_scale_psf, ...])

Run full PSF and aperture photometry on a stack; write extensions to FITS.

extract_aperture_stats(img_data, img_mask, ...)

Compute aperture flux and error for a star table; return table with added columns.

extract_fwhm_from_epsf(epsf, fwhm_init)

Estimate FWHM from ePSF model (Moffat2D fit).

generate_epsf(img_file, x, y[, size, ...])

Build an ePSF from cutouts at (x, y) positions in the image.

get_star_catalog(img_data, img_mask, img_error)

Detect stars with DAOStarFinder and compute aperture stats; return star table.

photloop(stack[, phot_sn_min, phot_sn_max, ...])

Try PSF photometry with decreasing S/N threshold until do_phot succeeds.

run_photometry(img_file, epsf, fwhm, ...)

Run PSF photometry and aperture photometry; append result tables to FITS.

run_sextractor(img_file[, log, sextractor_path])

Run Source Extractor on SCI extension; return catalog table or None.

potpyri.primitives.photometry.create_conv(outfile)[source]

Write a 3x3 CONV NORM filter file for Source Extractor.

Parameters:

outfile (str) – Path to write the convolution kernel file.

Return type:

None

potpyri.primitives.photometry.create_params(outfile)[source]

Write Source Extractor parameter file (NUMBER, X_IMAGE, FWHM_IMAGE, etc.).

Parameters:

outfile (str) – Path to write the parameter file.

Return type:

None

potpyri.primitives.photometry.do_phot(img_file, fwhm_scale_psf=4.5, oversampling=1, star_param={'fwhm_init': 8.0, 'snthresh_final': 10.0, 'snthresh_psf': 20.0}, save_psf_img=False, save_residual_hdu=False, log=None)[source]

Run full PSF and aperture photometry on a stack; write extensions to FITS.

Builds ePSF, finds stars, runs PSF and aperture photometry, and appends APPPHOT, PSFPHOT, EPSF, and optional residual extensions to the FITS file.

Parameters:
  • img_file (str) – Path to stack FITS (SCI, MASK, ERROR).

  • fwhm_scale_psf (float, optional) – Scale factor for PSF fit shape. Default is 4.5.

  • oversampling (int, optional) – ePSF oversampling. Default is 1.

  • star_param (dict, optional) – Keys: snthresh_psf, fwhm_init, snthresh_final. Defaults as shown.

  • save_psf_img (bool, optional) – If True, save ePSF image extension. Default is False.

  • save_residual_hdu (bool, optional) – If True, save residual image extension. Default is False.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

img_file is updated in place with new extensions.

Return type:

None

potpyri.primitives.photometry.extract_aperture_stats(img_data, img_mask, img_error, stars, aperture_radius=10.0, log=None)[source]

Compute aperture flux and error for a star table; return table with added columns.

Parameters:
  • img_data (np.ndarray) – Science image data.

  • img_mask (np.ndarray) – Boolean or integer mask (True/masked excluded).

  • img_error (np.ndarray) – Per-pixel error array.

  • stars (astropy.table.Table) – Table with xcentroid, ycentroid (modified in place with refined centroids).

  • aperture_radius (float, optional) – Aperture radius in pixels. Default is 10.0.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

Table with fwhm, flux_best, flux_best_err, Xpos, Ypos, etc.

Return type:

astropy.table.Table

potpyri.primitives.photometry.extract_fwhm_from_epsf(epsf, fwhm_init)[source]

Estimate FWHM from ePSF model (Moffat2D fit).

Parameters:
  • epsf (photutils.psf.EPSFModel) – ePSF model with .data array.

  • fwhm_init (float) – Initial FWHM guess for fit (pixels).

Returns:

FWHM in pixels from fitted Moffat2D.

Return type:

float

potpyri.primitives.photometry.generate_epsf(img_file, x, y, size=11, oversampling=2, maxiters=11, log=None)[source]

Build an ePSF from cutouts at (x, y) positions in the image.

Parameters:
  • img_file (str) – Path to FITS with SCI extension.

  • x (array-like) – Star x,y positions (pixels).

  • y (array-like) – Star x,y positions (pixels).

  • size (int, optional) – Cutout size in pixels. Default is 11.

  • oversampling (int, optional) – EPSFBuilder oversampling. Default is 2.

  • maxiters (int, optional) – EPSFBuilder max iterations. Default is 11.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

Fitted ePSF model.

Return type:

photutils.psf.EPSFModel

potpyri.primitives.photometry.get_star_catalog(img_data, img_mask, img_error, fwhm_init=5.0, threshold=50.0, log=None)[source]

Detect stars with DAOStarFinder and compute aperture stats; return star table.

Parameters:
  • img_data (np.ndarray) – Science image data.

  • img_mask (np.ndarray) – Boolean mask (True = masked).

  • img_error (np.ndarray) – Per-pixel error array.

  • fwhm_init (float, optional) – DAOStarFinder FWHM and aperture scale. Default is 5.0.

  • threshold (float, optional) – DAOStarFinder detection threshold. Default is 50.0.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

Star table with centroid, flux, fwhm, flux_best, etc.

Return type:

astropy.table.Table

potpyri.primitives.photometry.photloop(stack, phot_sn_min=3.0, phot_sn_max=40.0, fwhm_init=5.0, log=None)[source]

Try PSF photometry with decreasing S/N threshold until do_phot succeeds.

Parameters:
  • stack (str) – Path to stack FITS (SCI, MASK, ERROR).

  • phot_sn_min (float, optional) – Minimum S/N threshold to try. Default is 3.0.

  • phot_sn_max (float, optional) – Initial S/N threshold. Default is 40.0.

  • fwhm_init (float, optional) – Initial FWHM for star finding. Default is 5.0.

  • log (ColoredLogger, optional) – Logger for progress.

Returns:

Stack FITS is updated in place when do_phot succeeds.

Return type:

None

potpyri.primitives.photometry.run_photometry(img_file, epsf, fwhm, threshold, shape, stars)[source]

Run PSF photometry and aperture photometry; append result tables to FITS.

Parameters:
  • img_file (str) – Path to FITS with SCI, MASK, ERROR extensions.

  • epsf (photutils.psf.EPSFModel) – ePSF model for PSF fit.

  • fwhm (float) – FWHM in pixels (for aperture radius).

  • threshold (float) – Detection threshold (unused in this wrapper; for compatibility).

  • shape (int) – Fit shape (pixels) for PSFPhotometry.

  • stars (astropy.table.Table) – Star table with xcentroid, ycentroid, flux_best for initial guesses.

Returns:

(result_table, residual_image). result_table has flux_fit, x_fit, y_fit, etc.

Return type:

tuple

potpyri.primitives.photometry.run_sextractor(img_file, log=None, sextractor_path=None)[source]

Run Source Extractor on SCI extension; return catalog table or None.

Parameters:
  • img_file (str) – Path to FITS with SCI extension (and SATURATE in header).

  • log (ColoredLogger, optional) – Logger for progress.

  • sextractor_path (str, optional) – Path to Source Extractor binary. If None, uses ‘sex’ from PATH.

Returns:

Source Extractor catalog, or None if run failed.

Return type:

astropy.table.Table or None