def beta_2d_lmfit_profile(pars, imsize=None, data_profile=None, data_profile_err=None): """ Fits the surface brightness profile by creating a 2D model of the image. No psf, or bg. Also allows to return directly residuals. Arguments: """ # unpack parameters norm = pars['norm'].value rcore = pars['rcore'].value beta = pars['beta'].value xcen = pars['xcen'].value ycen = pars['ycen'].value # model in 2d and extract profile t1 = time.clock() model_image = make_2d_beta(imsize, xcen, ycen, norm, rcore, beta) t2 = time.clock() print "beta inside minimize took: ", t2-t1, " s" ###################################################################### # original extraction # t1 = time.clock() # (r, profile, geometric_area) = extract_profile_generic(model_image, xcen, ycen) # model_profile = profile / geometric_area # t2 = time.clock() # print "extract inside minimize took: ", t2-t1, " s" ###################################################################### #ADDED SPEED##################################################################### # setup data for the profile extraction - for speedup t1 = time.clock() distmatrix = distance_matrix(data, xcen_obj, ycen_obj).astype(int) # need int for bincount r_length = data.shape[0]/2 + 1 r = arange(0, r_length, 1.0) (profile, geometric_area) = extract_profile_fast(data, distmatrix, xcen_obj, ycen_obj) model_profile = profile[0:r_length] / geometric_area[0:r_length] # trim the corners t2 = time.clock() print "extract inside minimize took: ", t2-t1, " s" #ADDED SPEED##################################################################### if data_profile == None: return (r, model_profile) else: residuals = data_profile - model_profile # is this biasing? residuals = residuals / data_profile_err # print xcen, ycen, rcore return residuals
def make_2d_beta_psf(pars, imsize, xsize_obj, ysize_obj, instrument, im_psf, APPLY_PSF, DO_ZERO_PAD): """ Creates a 2D image of a beta model convolved with psf Arguments: """ # FIXME: the _object coordinates are not needed anymore # hdr = pyfits.getheader('pn-test.fits') # FIXME: would be better to create a fits header from scratch xcen = pars['xcen'].value ycen = pars['ycen'].value norm = pars['norm_'+instrument].value rcore = pars['rcore'].value beta = pars['beta'].value im_beta = make_2d_beta(imsize, xcen, ycen, norm, rcore, beta) # hdu = pyfits.PrimaryHDU(im_beta, hdr) # extension - array, header # hdulist = pyfits.HDUList([hdu]) # list all extensions here # hdulist.writeto('tmpa.fits', clobber=True) # if DO_ZERO_PAD: im_beta = zero_pad_image(im_beta, xsize_obj) # hdu = pyfits.PrimaryHDU(im_beta, hdr) # extension - array, header # hdulist = pyfits.HDUList([hdu]) # list all extensions here # hdulist.writeto('tmp0.fits', clobber=True) im_output = im_beta if APPLY_PSF: # create PSF # im_psf = make_2d_king_old(imsize, xcen, ycen, instrument, theta, energy) # im_psf = psf[instrument] # convolve im_output = fftconvolve(im_beta.astype(float), im_psf.astype(float), mode = 'same') im_output = trim_fftconvolve(im_output) return im_output