Ejemplo n.º 1
0
def test_dtype():
    """Image class: testing dtype."""
    wcs = WCS(cdelt=(0.2, 0.3), crval=(8.5, 12), shape=(40, 30), deg=True)
    data = np.zeros((40, 30))
    data[19, 14] = 1
    ima = Image(wcs=wcs, data=data, dtype=int)
    ima2 = ima.fftconvolve_gauss(center=None,
                                 flux=1.,
                                 fwhm=(20000., 10000.),
                                 peak=False,
                                 rot=60.,
                                 factor=1,
                                 unit_center=u.deg,
                                 unit_fwhm=u.arcsec)

    g = ima2.gauss_fit(verbose=False)
    assert_almost_equal(g.fwhm[0], 20000, 2)
    assert_almost_equal(g.fwhm[1], 10000, 2)
    assert_almost_equal(g.center[0], 8.5)
    assert_almost_equal(g.center[1], 12)
    assert_equal(ima2.dtype, np.float64)

    ima3 = ima2.resample(newdim=(32, 24),
                         newstart=None,
                         newstep=ima2.get_step(unit=u.arcsec) * 0.8)
    assert_equal(ima3.dtype, np.float64)
Ejemplo n.º 2
0
def test_fftconvolve():
    """Image class: testing FFT convolution method."""
    wcs = WCS(cdelt=(0.2, 0.3), crval=(8.5, 12), shape=(40, 30), deg=True)
    data = np.zeros((40, 30))
    data[19, 14] = 1
    ima = Image(wcs=wcs, data=data)
    ima2 = ima.fftconvolve_gauss(center=None,
                                 flux=1.,
                                 fwhm=(20000., 10000.),
                                 peak=False,
                                 rot=60.,
                                 factor=1,
                                 unit_center=u.deg,
                                 unit_fwhm=u.arcsec)

    g = ima2.gauss_fit(verbose=False)
    assert_almost_equal(g.fwhm[0], 20000, 2)
    assert_almost_equal(g.fwhm[1], 10000, 2)
    assert_almost_equal(g.center[0], 8.5)
    assert_almost_equal(g.center[1], 12)
    ima2 = ima.fftconvolve_moffat(center=None,
                                  flux=1.,
                                  a=10000,
                                  q=1,
                                  n=2,
                                  peak=False,
                                  rot=60.,
                                  factor=1,
                                  unit_center=u.deg,
                                  unit_a=u.arcsec)
    m = ima2.moffat_fit(verbose=False)
    assert_almost_equal(m.center[0], 8.5)
    assert_almost_equal(m.center[1], 12)
Ejemplo n.º 3
0
    def convolve(self, basename, main_beam):

        outName = string.split(basename, '.fits')[0]
        outName = outName + '_cv.fits'
        dat, baseheader = fint.openFile(basename)
        basefile = fits.open(basename)
        #baseheader = basefile[0].header
        basedata = Image(basename)

        if 'NAXIS3' in baseheader:
            del baseheader['NAXIS3']
        if 'NAXIS4' in baseheader:
            del baseheader['NAXIS4']

        aaa = basedata.data

        beam = np.array([float(baseheader['BMAJ']), float(baseheader['BMIN'])])
        print main_beam, beam
        if main_beam[0] > beam[0] and main_beam[1] > beam[1]:
            bx = np.sqrt(main_beam[0] * main_beam[0] - beam[0] * beam[0])
            by = np.sqrt(main_beam[1] * main_beam[1] - beam[1] * beam[1])
            #bx= main_beam[0]
            #by = main_beam[1]
            if 'CDELT1' in baseheader:
                pix_size = -baseheader['CDELT1']
            elif 'CD1_1' in baseheader:
                pix_size = -baseheader['CD1_1']

            beam_area = 2 * np.pi * beam[0] / 2.35482 * beam[1] / 2.35482
            main_beam_area = 2 * np.pi * main_beam[0] / 2.35482 * main_beam[
                1] / 2.35482

            number_pix_beam = beam_area / (pix_size * pix_size)

            #aaa = np.divide(aaa,number_pix_beam)
            #aaa = np.squeeze(aaa)
            #basedata.data = np.squeeze(basedata.data)
            #basedata.data=aaa
            #print basedata.shape

            newdata = Image.fftconvolve_gauss(basedata,
                                              center=None,
                                              flux=1,
                                              peak=True,
                                              factor=1,
                                              fwhm=(by, bx),
                                              unit_center=u.degree,
                                              unit_fwhm=u.degree,
                                              inplace=False)

            aaa = np.array(newdata.data)

            result = np.divide(aaa, np.power(main_beam_area / beam_area, 2))

            #result = np.multiply(aaa,main_beam_area/(pix_size*pix_size))

            baseheader['BMAJ'] = main_beam[0]
            baseheader['BMIN'] = main_beam[1]

            fits.writeto(outName, result, baseheader, overwrite=True)

        else:
            outName = basename

        return outName