imcascade.psf_fitter

Module Contents

Classes

PSFFitter

A Class used to fit Gaussian models to a PSF image

class imcascade.psf_fitter.PSFFitter(psf_img, oversamp=1.0)

A Class used to fit Gaussian models to a PSF image

Parameters
  • psf_img (str or 2D array) – PSF data to be fit. If a string is given will assume it is a fits file and load the Data in the first HDU. If it is an array then will use as the PSF image. Either way it is assumed the PSF is centered and image is square.

  • oversamp (Float, optional) – Factor by which the PSF image is oversampled. Default is 1.

psf_data

pixelized PSF data to be fit

Type

2D array

intens

1D sbp of PSF

Type

1D array

radii

Radii corresponding to intens

Type

1D array

calc_profile()

Calculates the 1-D PSF profile in 1 pixel steps assuming it is circular

Returns

  • intens (1D array) – Intensity profile.

  • radius (1D array) – radii at which the intensity measuremnts are made.

multi_gauss_1d(r, *params, mu=0)

Function used to evaluate a 1-D multi Gaussian model with any number of components

Parameters
  • params (1D array) – List of parameters to define model. The length should be twice the number of components in the following pattern:[ a_1, sig_1, a_2,sig_2, ….] where a_i is the weight of the i’th component and sig_i is the width of the i’th component.

  • r (float, array) – Radii at which the profile is to be evaluated

  • mu (float, optional) – The centre of the gaussian distribution, default is 0

Returns

The multi-gaussian profile evaluated at ‘r’

Return type

1D array

multi_gauss_1d_ls(*params, x_data=np.zeros(10), y_data=np.zeros(10), mu=0)

Wrapper for multi_gauss_1d function, to be used in fitting the profile

Parameters
  • params (1D Array) – List of parameters to define model. The length should be twice the number of components in the following pattern: [ a_1, sig_1, a_2,sig_2, ….]. Here a_i is the weight of the i’th component and sig_i is the width of the i’th component.

  • x_data (1-D array) – x_data to be fit, generally self.radius.

  • y_data (1-D array) – y_data to be fit, genrally self.intens

  • mu (float, optional) – The centre of the gaussian distribution, default is 0.

Returns

resid – log scale residuals between the models specified by ‘params’ and the given y_data

Return type

1D array

fit_N(N, frac_cutoff=0.0001, plot=False)

‘Fully’ Fit a Multi Gaussian Model with a given number of gaussians to the psf profile. Start with 1D to find the best fit widths and then us evaluate chi2 in 2D

Parameters
  • N (Int) – Number of gaussian to us in fit

  • frac_cutoff (float, optional) – Fraction of max, below which to not fit. This is done to focus on the center of the PSF and not the edges. Important because we using the log-residuals

  • plot (bool) – Whether or not to show summary plot

Returns

  • a_fit (1-D array) – Best fit Weights, corrected for oversamping

  • sig_fit (1-D array) – Best fit widths, corrected for oversamping

  • Chi2 (Float) – The overall chi squared of the fit, computed using the best fit 2D model

fit_1D(N, init_guess=None, frac_cutoff=0.0001)

Fit a 1-D Multi Gaussian Model to the psf profile

Parameters
  • N (Int) – Number of gaussian to us in fit

  • guess (Init) – Initial guess at parameters, if None will set Default based on N

  • frac_cutoff (float) – Fraction of max, below which to not fit. This is done to focus on the center of the PSF and not the edges. Important because we using the log-residuals

Returns

  • a_fit (1-D array) – Best fit Weights, Not corrected for oversampling

  • sig_fit (1-D array) – Best fit widths, Not corrected for oversampling

  • Chi2 (Float) – The overall chi squared of the fit

auto_fit(N_max=5, frac_cutoff=0.0001, norm_a=True)

Function used for automatic fitting of PSF. First using a 1-D fit to find the smallest acceptable number of Gaussians and the corresponding widths, then using these widths to fit in 2D and find the weights.

Parameters
  • N (Int) – Number of gaussian to us in fit

  • frac_cutoff (float) – Fraction of max, below which to not fit. This is done to focus on the center of the PSF and not the edges. Important because we using the log-residuals

  • norm_a (Bool) – Wheter or not to normize the resulting weight so that the sum is unity

Returns

  • a_fit (1-D array) – Best fit Weights

  • sig_fit (1-D array) – Best fit widths

calc_fwhm()

Function to estimate the FHWM of the PSF, by interpolating the measured profile

Returns

FWHM – Estimate of the FWHM in pixels

Return type

float