def rebin_data(self, grid, use_psf=True):
        """Calculates the center of mass of the grid and then
        rebins so that the center pixel really is the center of the array
        For this we do a 2-d interpolation on the grid
        """
        a = psf_fitter.psffit(abs(grid), circle=False, rotate=1)
        xcen = a[2]
        ycen = a[2]
        xlen, ylen = grid.shape
        xval = arange(xlen)
        yval = arange(ylen)

        xint = interp1d(xval, self.xpos_abs)
        yint = interp1d(yval, self.ypos_abs)

        xintcen = self.xmax_pos-xint(xcen)
        yintcen = self.ymax_pos-yint(ycen)

        print self.xmax_pos, xintcen, self.ymax_pos, yintcen
        f_real = interp2d(self.xpos_rel, self.ypos_rel, real(grid))
        f_imag = interp2d(self.xpos_rel, self.ypos_rel, imag(grid))

        xnew = self.xpos_rel - xintcen
        ynew = self.ypos_rel - yintcen

        recen_grid = f_real(xnew, ynew) + 1j*f_imag(xnew, ynew)

        print nd.center_of_mass(abs(recen_grid))

        return recen_grid
 def calculate_grid_center(self, grid, fit_type="psf"):
     if fit_type is "psf":
         a = psf_fitter.psffit(abs(grid), circle=False, rotate=1)
         print a
     elif fit_type is "cm":
         print "cm"
     else:
         print "nope"
Beispiel #3
0
    figure(1)
    clf()
    x = linspace(0,5,1000)
    plot(x,agpy.psf_fitter._airy_func(x),label='Airy')
    plot(x,agpy.psf_fitter._gaussian_func(x),label='Gaussian')
    plot(x,agpy.psf_fitter._gaussian_func(x,sigma=airy_fwhm/gaussian_fwhm),label='Gaussian (sigma=%5.3f)' % (airy_fwhm/gaussian_fwhm))


    figure(2)
    clf()
    test_airy = psf_fitter.airy([1,50,50,5],vheight=False,shape=[100,100])
    imshow((test_airy),norm=asinh_norm.AsinhNorm())
    colorbar()

    airyfitp,airyfitimg = psf_fitter.psffit(test_airy,returnfitimage=True,vheight=False)
    gaussfitp,gaussfitimg = psf_fitter.psffit(test_airy,psffunction=psf_fitter.twodgaussian,returnfitimage=True,vheight=False)
    print "When fitting, the Gaussian FWHM will be smaller than the Airy FWHM by %f  (inverted, this is %f)" % (gaussfitp[4]*gaussian_fwhm/(airyfitp[4]*airy_fwhm),airyfitp[4]*airy_fwhm/(gaussfitp[4]*gaussian_fwhm))
    print ""

    print "Fitted Airy parameters:     amp %10f xcen %10f ycen %10f width %10f fwhm %10f.  Residual: %10g  Res^2: %10g" % (tuple(airyfitp[1:].tolist())+
            (airyfitp[4]*airy_fwhm,(test_airy-airyfitimg).sum(),((test_airy-airyfitimg)**2).sum()))
    print "Fitted Gaussian parameters: amp %10f xcen %10f ycen %10f width %10f fwhm %10f.  Residual: %10g  Res^2: %10g" % (tuple(gaussfitp[1:].tolist())+
            (gaussfitp[4]*gaussian_fwhm,(test_airy-gaussfitimg).sum(),((test_airy-gaussfitimg)**2).sum()))


    figure(3)
    clf()
    subplot(121)
    imshow((test_airy-airyfitimg), norm=asinh_norm.AsinhNorm())
    colorbar()
Beispiel #4
0
    plot(x, agpy.psf_fitter._airy_func(x), label='Airy')
    plot(x, agpy.psf_fitter._gaussian_func(x), label='Gaussian')
    plot(x,
         agpy.psf_fitter._gaussian_func(x, sigma=airy_fwhm / gaussian_fwhm),
         label='Gaussian (sigma=%5.3f)' % (airy_fwhm / gaussian_fwhm))

    figure(2)
    clf()
    test_airy = psf_fitter.airy([1, 50, 50, 5],
                                vheight=False,
                                shape=[100, 100])
    imshow((test_airy), norm=asinh_norm.AsinhNorm())
    colorbar()

    airyfitp, airyfitimg = psf_fitter.psffit(test_airy,
                                             returnfitimage=True,
                                             vheight=False)
    gaussfitp, gaussfitimg = psf_fitter.psffit(
        test_airy,
        psffunction=psf_fitter.twodgaussian,
        returnfitimage=True,
        vheight=False)
    print "When fitting, the Gaussian FWHM will be smaller than the Airy FWHM by %f  (inverted, this is %f)" % (
        gaussfitp[4] * gaussian_fwhm /
        (airyfitp[4] * airy_fwhm), airyfitp[4] * airy_fwhm /
        (gaussfitp[4] * gaussian_fwhm))
    print ""

    print "Fitted Airy parameters:     amp %10f xcen %10f ycen %10f width %10f fwhm %10f.  Residual: %10g  Res^2: %10g" % (
        tuple(airyfitp[1:].tolist()) + (airyfitp[4] * airy_fwhm,
                                        (test_airy - airyfitimg).sum(),