def residual_multigauss(param, dataimage, nonfinite = 0.0, ravelresidual=True, showimages=False, verbose=False):
"""
Calculating the residual bestween the multigaussian model with the paramters 'param' and the data.
--- INPUT ---
param Parameters of multi-gaussian model to generate. See modelimage_multigauss() header for details
dataimage Data image to take residual
nonfinite Value to replace non-finite entries in residual with
ravelresidual To np.ravel() the residual image set this to True. Needed by scipy.optimize.leastsq()
optimizer function
showimages To show model and residiual images set to True
verbose Toggle verbosity
--- EXAMPLE OF USE ---
import tdose_model_FoV as tmf
param = [18,31,1*0.3,2.1*0.3,1.2*0.3,30*0.3, 110,90,200*0.5,20.1*0.5,15.2*0.5,0*0.5]
dataimg = pyfits.open('/Users/kschmidt/work/TDOSE/mock_cube_sourcecat161213_tdose_mock_cube.fits')[0].data[0,:,:]
residual = tmf.residual_multigauss(param, dataimg, showimages=True)
"""
if verbose: ' - Estimating residual (= model - data) between model and data image'
imgsize = dataimage.shape
xgrid, ygrid = tu.gen_gridcomponents(imgsize)
modelimg = tmf.modelimage_multigauss((xgrid, ygrid),param,imgsize,showmodelimg=showimages, verbose=verbose)
residualimg = modelimg - dataimage
if showimages:
plt.imshow(residualimg,interpolation='none', vmin=1e-5, vmax=np.max(residualimg), norm=mpl.colors.LogNorm())
plt.title('Resdiaul (= model - data) image')
plt.show()
if nonfinite is not None:
residualimg[~np.isfinite(residualimg)] = 0.0
if ravelresidual:
residualimg = np.ravel(residualimg)
return residualimg
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
评论列表
文章目录