I'm using BasicPSFPhotometry from photutils.psf to obtain the photometry of a source.
Here an example of my code (sadly is not a working example but can help understanding what I'm doing and what I need). Most of this was copied from https://photutils.readthedocs.io/en/stable/psf.html and adapted to my needs.
fitter=LevMarLSQFitter()
psf_model = photutils.psf.FittableImageModel(psfdata,normalize=True)
pos = Table(names=['id','x_0', 'y_0','flux_0'], data=[[1],[xycen[0]],[xycen[1]],[flux]])
photometrypsf = BasicPSFPhotometry(group_maker=daogroup,
bkg_estimator=None,
psf_model=psf_model,
fitter=fitter,
fitshape=target.shape,
aperture_radius=fwhm)
psf_photometry = photometrypsf(image=target.copy(),init_guesses=pos)
I need to estimate the chi square for the PSF fitting of my source but I don't understand how to do it.
I was following this post (In Scipy how and why does curve_fit calculate the covariance of the parameter estimates) where they explain how to get a reduced chi squared as:
s_sq = (infodict['fvec']**2).sum()/ (N-n)
that I was able to translate i my code in:
s_sq = (fitter.fit_info['fvec']**2).sum()/(len(fitter.fit_info['fvec'])-n)
The problem is that I don't know how to evaluate "n". In the example they say n (number of free parameter) is the length of the output x of scipy.optimize.leastsq (the first output) but LevMarLSQFitter clearly state that:
Note that the x return value is not included (as it is instead the parameter values of the returned model).
So the question is, using LevMarLSQFitter in conjunction with BasicPSFPhotometry what is the most practical way to estimate the chi square for the fit (or any other parameter can let me understand the goodness of the fit)? Moreover, how do I acces to the parameter of the fit performed from LevMarLSQFitter?