Пример #1
0
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
Пример #2
0
def beta_psf_2d_lmfit_profile(pars, imsize, xsize_obj, ysize_obj,
                              distmatrix,
                              instrument, theta, energy, APPLY_PSF,
                              DO_ZERO_PAD, data_profile=None,
                              data_profile_err=None):
    """
    Fits the surface brightness profile by creating a 2D model of the
    image - beta model x psf
    No bg.
    Also allows to return directly residuals.
    """
    USE_ERROR=True             # debug option

    # model in 2d image beta x PSF = and extract profile
    model_image = make_2d_beta_psf(pars, imsize, xsize_obj, ysize_obj,
                                   instrument, theta, energy,
                                   APPLY_PSF, DO_ZERO_PAD)

    # this is the new version
    xcen_obj = xsize_obj / 2
    ycen_obj = ysize_obj / 2

    # 2013-05-22 not needed anymore
    # we want just the relevant part of the image
    # data = model_image[ycen-ysize_obj/2:ycen+ysize_obj/2, xcen-xsize_obj/2:xcen+xsize_obj/2]
    # data = model_image

    # setup data for the profile extraction - for speedup
    # was refactored - pass it for speed not
    # distmatrix = distance_matrix(model_image, xcen_obj, ycen_obj).astype(int) # need int for bincount

    r_length = model_image.shape[0]/2 + 1

    # r = arange(0, r_length, 1.0)   # original line: before 2013-03-13
    r = arange(1.0, r_length+1, 1.0)

    # FIXME: can be geoemtric area removed from here and instead
    # passes? or is there some edge effect
    (profile, geometric_area) = extract_profile_fast(model_image, distmatrix, xcen_obj, ycen_obj)
    model_profile = profile[0:r_length] / geometric_area[0:r_length]    # trim the corners

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

        return residuals
Пример #3
0
def beta_psf_2d_lmfit_profile_joint(pars, imsize, xsize_obj, ysize_obj,
                                    distmatrix,
                                    instruments, psf_dict,
                                    APPLY_PSF, DO_ZERO_PAD,
                                    data_r=None,
                                    data_profile=None,
                                    data_profile_err=None):
    """
    Fits the surface brightness profile by creating a 2D model of the
    image - beta model x psf for a combination of instruments
    No bg.
    Also allows to return directly residuals.
    """

    USE_ERROR=True             # debug option

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

    # this is the new version
    xcen_obj = xsize_obj / 2
    ycen_obj = ysize_obj / 2
    # we want just the relevant part of the image
    # data = model_image[ycen-ysize_obj/2:ycen+ysize_obj/2, xcen-xsize_obj/2:xcen+xsize_obj/2]

    for instrument in instruments:
        # model in 2d image beta x PSF = and extract profile

        model_image[instrument] = make_2d_beta_psf(pars, imsize, xsize_obj, ysize_obj,
                                       instrument, psf_dict[instrument],
                                       APPLY_PSF, DO_ZERO_PAD)

        r_length = model_image[instrument].shape[0]/2 + 1
        r = arange(1.0, r_length+1, 1.0)

        # FIXME: can be geometric areas removed from here and instead
        # pass it? or is there some edge effect
        (profile[instrument], geometric_area[instrument]) = \
            extract_profile_fast(model_image[instrument],
                                 distmatrix, xcen_obj, ycen_obj)

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


        ######################################################################
        # binning
        ######################################################################


    if data_profile == None:
        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 "full resid :: ", sum(residuals)
        print '='*35
        return residuals