Example #1
0
def v06_psf_2d_lmfit_profile(pars,distmatrix,bgrid,r500,instrument, theta, energy,
                             xcen_obj,ycen_obj,data_profile=None,
                             data_profile_err=None):
    """
    Fits the surface brightness profile by creating a 2D model of the
    image - v06 model (without the central beta model) x psf
    No bg.
    Also allows to return directly residuals.
    """
    USE_ERROR=True             # debug option

    # make first a 2D image
    model_image = make_2d_v06_psf(pars, distmatrix, bgrid, r500,
                                  instrument, theta, energy)

    # FIXME: is this necessary for each step?
    # trim distmatrix size to image post convolution
    distmatrix = roll(roll(distmatrix,2,axis=0),2,axis=1)
    distmatrix = trim_fftconvolve(distmatrix)

    # profile extraction
    r_length = r500             # factor out r500
    r = arange(1.0, r_length+1, 1.0)

    (profile, geometric_area) = extract_profile_fast2(model_image, distmatrix, bgrid)
    model_profile = profile[0:r_length] / geometric_area[0:r_length]    # trim the corners

    # print '*'*30
    # print len(r), len(model_profile)
    # print len(profile[0:r_length]), r_length
    # # print len(data_profile[0:r_length]), len(model_profile), r500, r_length
    # print '*'*30

    if data_profile == None:
        # return (r, model_profile, geometric_area)
        return (r, model_profile)
    else:
        residuals = data_profile - model_profile
        # is this biasing?
        if USE_ERROR: residuals = residuals / data_profile_err

        print "full resid :: ", sum(residuals)

        # return residuals
        return residuals
Example #2
0
def v06_psf_2d_lmfit_profile_joint(pars,distmatrix,bgrid, rfit,
                                   instruments, psf_dict,
                                   xcen_obj,ycen_obj,
                                   data_r=None,
                                   data_profile=None,
                                   data_profile_err=None):
    """
    Fits the surface brightness profile by creating a 2D model of the
    image - v06 model (without the central beta model) x psf for a
    combinaiton of instruments
    No bg.  Also allows to return directly
    residuals.
    """
    USE_ERROR=True             # debug option

    # setup dictionaries
    model_image = {}
    profile = {}
    geometric_area = {}
    model_profile = {}

    # profile extraction
    r = arange(1.0, rfit+1, 1.0)

    # make first a 2D image
    for instrument in instruments:
        model_image[instrument] = make_2d_v06_psf(pars, distmatrix, bgrid, rfit,
                                                  instrument, psf_dict[instrument])

        # FIXME: is this necessary for each step? - would require to
        # have 2 distance matrices!  trim distmatrix size to image
        # post convolution
        distmatrix = roll(roll(distmatrix,2,axis=0),2,axis=1)
        distmatrix = trim_fftconvolve(distmatrix)

        (profile[instrument], geometric_area[instrument]) = \
             extract_profile_fast2(model_image[instrument], distmatrix, bgrid)

        # trim the corners
        model_profile[instrument] = profile[instrument][0:rfit] / geometric_area[instrument][0:rfit]

        # FIXME: bin here

    if data_profile == None:
        # return (r, model_profile, geometric_area)
        return (r, model_profile)
    else:
        # combine the likelihoods
        residuals = 0.0
        for instrument in instruments:
            residuals_inst = abs(data_profile[instrument] - model_profile[instrument])
            # is this biasing?
            if USE_ERROR: residuals_inst = residuals_inst / data_profile_err[instrument]

            print instrument, "resid :: ", sum(residuals_inst)
            residuals = residuals + residuals_inst

        print pars['n0_'+instruments[0]].value, pars['alpha'].value, pars['beta'].value, pars['epsilon'].value, pars['rc'].value, pars['rs'].value

        print "full resid :: ", sum(residuals), "Chisqr :: ", sum(residuals**2)
        print '='*35
        return residuals