OnePassPhot

class one_pass_fitting.OnePassPhot(psf_model: GriddedPSFModel, hmin: int = 5, fmin: float = 1000.0, pmax: float = 70000.0, bkg_stat: str = 'mode', sky_in: float = 8.5, sky_out: float = 13.5)

Bases: object

Perform one-pass photometry on an image using a PSF model.

This class is designed for performing photometry on an astronomical image using a provided PSF model. It includes methods for detecting stars, fitting the PSF model to the stars, and calculating photometric parameters. It can operate in parallel for improved performance.

Parameters:

psf_modelGriddedPSFModel

The PSF model to use for photometry.

hminint, optional

Minimum separation between stars for detection (default is 5 pixels).

fminfloat, optional

Minimum flux value for a star to be considered (default is 1000.0).

pmaxfloat, optional

Maximum pixel value for a star to be considered (default is 70000.0).

bkg_statstr, optional

Background estimation method (default is “mode”). Supported values: “mean,” “median,” or “mode.”

sky_infloat, optional

Inner radius for sky background estimation (default is 8.5 pixels).

sky_outfloat, optional

Outer radius for sky background estimation (default is 13.5 pixels).

Methods:

__call__(data, data_wcs=None, output_name=None, do_sat=False, dq=None):

Perform one-pass photometry on the input image.

fit_stars(data, xs=None, ys=None, mod=None):

Fit the PSF model to detected stars.

sat_phot(data, dq, mod=None, data_wcs=None, output_name=None):

Detect and fit the saturated sources

Attributes:

xdetsarray-like

X positions of detected stars.

ydetsarray-like

Y positions of detected stars.

Attributes Summary

bkg_stat

fmin

hmin

pmax

sky_in

sky_out

Methods Summary

__call__(data[, data_wcs, output_name, ...])

Perform one-pass photometry on the input image.

compile_results(result, skies[, data_wcs, ...])

Compile photometry results into a table and potentially save it to a file.

fit_stars(data[, xs, ys, mod, data_wcs, ...])

Fits PSF model to objects in data located at (xs,``ys``).

sat_phot(data, dq[, xs, ys, mod, data_wcs, ...])

Perform photometry on saturated stars detected in the data.

write_tbl(tbl, output_name)

Writes table to file, handles the different formats

Attributes Documentation

bkg_stat: str = 'mode'
fmin: float = 1000.0
hmin: int = 5
pmax: float = 70000.0
sky_in: float = 8.5
sky_out: float = 13.5

Methods Documentation

__call__(data, data_wcs=None, output_name=None, do_sat=False, dq=None)

Perform one-pass photometry on the input image.

Parameters:

datanumpy.ndarray

The image data on which to perform photometry.

data_wcsWCS, optional

World Coordinate System information for the input data (default is None).

output_namestr, optional

Output name for writing catalog to file. For JWST data, .ecsv is recommended, for HST, .cat is recommended (saved as ascii.commented_header). If None no file is written out.

do_satbool, optional

Find and measure the saturated stars as well (default is False). Currently only well implemented for JWST

dqnumpy.ndarray

The data quality array corresponding to data. Must be passed in if do_sat is True

Returns:

astropy.table.Table

A table containing the photometric measurements of the detected stars. See fit_stars for details.

Notes:

This method performs one-pass photometry on the input image using the provided PSF model. It detects stars in the image, fits the PSF model to the stars, and returns a table with photometric measurements. If do_sat is True then it also finds and detects the saturated sources (currently a beta version that works for just JWST). The data quality array must be passed in the dq argument if do_sat is True.

If data_wcs is provided, the method will also calculate the celestial coordinates (RA and Dec) of the detected stars and include them in the output table.

If output_name is not None, it is strongly recommeneded to name the catalog to have the same name as the image filename, with the .fits file extension replaced with _sci<X>_xyrd.cat for HST or _sci<X>_xyrd.ecsv for JWST, where <X> is the EXTVER of the relevant SCI extension, e.g. the output_name for extension SCI, 2 of iaab01hxq_flc.fits (an HST image) should be iaab01hxq_flc_sci2_xyrd.cat.

compile_results(result, skies, data_wcs=None, output_name=None)

Compile photometry results into a table and potentially save it to a file.

Parameters

resultlist or numpy.ndarray

List or array containing photometry results.

skieslist or numpy.ndarray

List or array containing sky values.

data_wcsastropy.wcs.WCS, optional

WCS information for the data.

output_namestr, optional

Name of the output file to save the results.

Returns

tblastropy.table.Table

Compiled table containing selected columns of photometry results.

Notes

This method compiles the input ‘result’ into an astropy table, adding sky values (‘skies’), converting flux (‘f’) to magnitude (‘m’). The order for the values for each sublist in result must be: flux, x positon, y postion, q fit, cx, pix flux, and finally npix_fit (see fit_stars for more info) Additionally, it creates a column ‘sat’ to mark stars with NaNs at the peak but not as a failed fit. If ‘data_wcs’ is provided, RA and Dec columns are added to the table based on pixel values. If ‘output_name’ is provided, the resulting table can be saved to a file using the ‘write_tbl’ method.

fit_stars(data, xs=None, ys=None, mod=None, data_wcs=None, output_name=None)

Fits PSF model to objects in data located at (xs,``ys``).

Parameters:

datanumpy.ndarray

Data array from which to measure stars

xsarray-like, optional

The x positions of the stars. Only needs to fall within central (brightest) pixel of star. If None, sources are detected first.

ysarray-like, optional

The y positions of the stars. Only needs to fall within central (brightest) pixel of star

modGriddedPSFModel, EPSFModel, FittableImageModel, optional

The PSF model to fit to the stars. Should usually be GriddedPSFModel. If None (default), then sets value to self.psf_model.

data_wcsWCS, optional

World Coordinate System information for the input data (default is None).

output_namestr, optional

Output name for writing catalog to file. For JWST data, .ecsv is recommended, for HST, .cat``is recommended (saved as ascii.commented_header).  If ``None no file is written out.

Returns:

astropy.table.Table
A table of the fitted parameters for each star, include columns:
  • x : x positions of fitted stars (0 indexed)

  • y : y positions of fitted stars (0 indexed)

  • m : instrumental magnitude of fitted stars

  • q : quality of fit value (qfit)

  • s : sky values measured around the stars

  • cx : central excess values

  • f : flux of fitted stars

  • pix_flux : Sum of the model on the pixels on which it was fit

  • npix_fit : Number of pixels fit by the model

  • sat : Whether the core of the star was saturated (nan) or not

  • r : RA of fit position (only if data_wcs is not None)

  • d : Dec of fit position (only if data_wcs is not None)

sat_phot(data, dq, xs=None, ys=None, mod=None, data_wcs=None, output_name=None)

Perform photometry on saturated stars detected in the data.

Parameters

datanumpy.ndarray

Data array from which to measure stars

dqnumpy.ndarray

Data quality array indicating pixel flags, needed for finding saturated stars.

xsarray-like, optional

The x positions of the stars. Only needs to fall within central block of nans of star. If None, sources are detected first.

ysarray-like, optional

The y positions of the stars. Only needs to fall within central block of nans of star. If None, sources are detected first.

areas: array-like, optional

How many nans in block. Used to compute fitting cutout size. Only used if xs and ys are also passed in. If None will attempt to compute size.

modGriddedPSFModel, EPSFModel, FittableImageModel, optional

The PSF model to fit to the stars. Should usually be GriddedPSFModel. If None (default), then sets value to self.psf_model.

data_wcsWCS, optional

World Coordinate System information for the input data (default is None).

output_namestr, optional

Output name for writing catalog to file. For JWST data, .ecsv is recommended, for HST, .cat``is recommended (saved as ascii.commented_header).  If ``None no file is written out.

Notes:

This function uses the data quality array to detect blocks of pixels that have flags indicating there is a saturated object present. It then determines an approximate center of the object, calculates an appropriate size of cutout to fit, calculates backgrounds and then fits the unsaturated wings of the PSF. For more information, see fit_stars().

WARNING: This is a very early version of this function, and has only been tested on a couple of cases. In addition, it is only meant to work for JWST imaging data at the moment

write_tbl(tbl, output_name)

Writes table to file, handles the different formats