def test_fftim(self):
     self.m31image = create_test_image(cellsize=0.001,
                                       frequency=[1e8],
                                       canonical=True)
     m31_fft = fft_image(self.m31image)
     m31_fft_ifft = fft_image(m31_fft, self.m31image)
     numpy.testing.assert_array_almost_equal(self.m31image.data,
                                             m31_fft_ifft.data.real, 12)
     m31_fft.data = numpy.abs(m31_fft.data)
     export_image_to_fits(m31_fft,
                          fitsfile='%s/test_m31_fft.fits' % (self.dir))
Esempio n. 2
0
 def test_tapering_Gaussian(self):
     self.actualSetUp()
     size_required = 0.01
     self.componentvis, _, _ = weight_visibility(self.componentvis,
                                                 self.model,
                                                 algoritm='uniform')
     self.componentvis = taper_visibility_gaussian(self.componentvis,
                                                   beam=size_required)
     psf, sumwt = invert_2d(self.componentvis, self.model, dopsf=True)
     export_image_to_fits(
         psf, '%s/test_weighting_gaussian_taper_psf.fits' % self.dir)
     xfr = fft_image(psf)
     xfr.data = xfr.data.real.astype('float')
     export_image_to_fits(
         xfr, '%s/test_weighting_gaussian_taper_xfr.fits' % self.dir)
     npixel = psf.data.shape[3]
     sl = slice(npixel // 2 - 7, npixel // 2 + 8)
     fit = fit_2dgaussian(psf.data[0, 0, sl, sl])
     if fit.x_stddev <= 0.0 or fit.y_stddev <= 0.0:
         raise ValueError('Error in fitting to psf')
     # fit_2dgaussian returns sqrt of variance. We need to convert that to FWHM.
     # https://en.wikipedia.org/wiki/Full_width_at_half_maximum
     scale_factor = numpy.sqrt(8 * numpy.log(2.0))
     size = numpy.sqrt(fit.x_stddev * fit.y_stddev) * scale_factor
     # Now we need to convert to radians
     size *= numpy.pi * self.model.wcs.wcs.cdelt[1] / 180.0
     # Very impressive! Desired 0.01 Acheived 0.0100006250829
     assert numpy.abs(size - size_required) < 0.001 * size_required, \
         "Fit should be %f, actually is %f" % (size_required, size)
 def test_fftim_factors(self):
     for i in [3, 5, 7]:
         npixel = 256 * i
         m31image = create_test_image(cellsize=0.001,
                                      frequency=[1e8],
                                      canonical=True)
         padded = pad_image(m31image, [1, 1, npixel, npixel])
         assert padded.shape == (1, 1, npixel, npixel)
         padded_fft = fft_image(padded)
         padded_fft_ifft = fft_image(padded_fft, m31image)
         numpy.testing.assert_array_almost_equal(padded.data,
                                                 padded_fft_ifft.data.real,
                                                 12)
         padded_fft.data = numpy.abs(padded_fft.data)
         export_image_to_fits(padded_fft,
                              fitsfile='%s/test_m31_fft_%d.fits' %
                              (self.dir, npixel))
 def test_convert_image_to_kernel(self):
     m31image = create_test_image(cellsize=0.001,
                                  frequency=[1e8],
                                  canonical=True)
     screen = create_w_term_like(m31image, w=20000.0, remove_shift=True)
     screen_fft = fft_image(screen)
     converted = convert_image_to_kernel(screen_fft, 8, 8)
     assert converted.shape == (1, 1, 8, 8, 8, 8)
     with self.assertRaises(AssertionError):
         converted = convert_image_to_kernel(m31image, 15, 1)
     with self.assertRaises(AssertionError):
         converted = convert_image_to_kernel(m31image, 15, 1000)
Esempio n. 5
0
 def test_tapering_Tukey(self):
     self.actualSetUp()
     self.componentvis, _, _ = weight_visibility(self.componentvis,
                                                 self.model,
                                                 algoritm='uniform')
     self.componentvis = taper_visibility_tukey(self.componentvis,
                                                tukey=1.0)
     psf, sumwt = invert_2d(self.componentvis, self.model, dopsf=True)
     export_image_to_fits(
         psf, '%s/test_weighting_tukey_taper_psf.fits' % self.dir)
     xfr = fft_image(psf)
     xfr.data = xfr.data.real.astype('float')
     export_image_to_fits(
         xfr, '%s/test_weighting_tukey_taper_xfr.fits' % self.dir)