def test_deconvolve_and_restore_cube_hogbom(self): self.bigmodel.data *= 0.0 visres, model, residual = solve_image(self.vis, self.bigmodel, niter=1000, nmajor=5, threshold=0.01, psf_support=200, window='quarter', fractional_threshold=0.1, gain=0.1, algorithm='hogbom') export_image_to_fits( model, '%s/test_solve_skycomponent_hogbom_solution.fits' % (self.dir)) export_image_to_fits( residual, '%s/test_solve_skycomponent_hogbom_residual.fits' % (self.dir)) psf, sumwt = invert_2d(self.vis, model, dopsf=True) export_image_to_fits( psf, '%s/test_solve_skycomponent_hogbom_psf.fits' % (self.dir)) restored = restore_cube(model=model, psf=psf, residual=residual) export_image_to_fits( restored, '%s/test_solve_skycomponent_hogbom_restored.fits' % (self.dir)) assert numpy.max(numpy.abs(residual.data)) < 0.5
def test_invert_2d(self): # Test if the 2D invert works with w set to zero # Set w=0 so that the two-dimensional transform should agree exactly with the model. # Good check on the grid correction in the vis->image direction self.actualSetUp() self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.componentvis.data['uvw'][:, 2] = 0.0 self.componentvis.data['vis'] *= 0.0 # Predict the visibility using direct evaluation for comp in self.components: predict_skycomponent_visibility(self.componentvis, comp) dirty2d = create_empty_image_like(self.model) dirty2d, sumwt = invert_2d(self.componentvis, dirty2d, **self.params) export_image_to_fits( dirty2d, '%s/test_imaging_functions_invert_2d_dirty.fits' % self.dir) self._checkcomponents(dirty2d)
def test_psf_location_2d(self): self.actualSetUp() self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.componentvis.data['uvw'][:, 2] = 0.0 self.componentvis.data['vis'] *= 0.0 psf2d = create_empty_image_like(self.model) psf2d, sumwt = invert_2d(self.componentvis, psf2d, dopsf=True, **self.params) export_image_to_fits( psf2d, '%s/test_imaging_functions_invert_psf_location.fits' % self.dir) nchan, npol, ny, nx = psf2d.shape assert numpy.abs(psf2d.data[0, 0, ny // 2, nx // 2] - 1.0) < 2e-3 imagecentre = pixel_to_skycoord(nx // 2 + 1.0, ny // 2 + 1.0, wcs=psf2d.wcs, origin=1) assert imagecentre.separation(self.phasecentre).value < 1e-15, \ "Image phase centre %s not as expected %s" % (imagecentre, self.phasecentre)
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) from arl.image.operations import fft_image 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_insert_skycomponent_dft(self): sc = create_skycomponent( direction=self.phasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) self.vis.data['vis'][...] = 0.0 self.vis = predict_skycomponent_visibility(self.vis, sc) im, sumwt = invert_2d(self.vis, self.model) export_image_to_fits(im, '%s/test_skycomponent_dft.fits' % self.dir) assert numpy.max(numpy.abs(self.vis.vis.imag)) < 1e-3
def _checkdirty(self, vis, name='test_invert_2d_dirty', fluxthreshold=1.0): # Make the dirty image self.params['imaginary'] = False dirty = create_empty_image_like(self.model) dirty, sumwt = invert_2d(vis=vis, im=dirty, dopsf=False, normalize=True, **self.params) export_image_to_fits(dirty, '%s/%s_dirty.fits' % (self.dir, name)) maxabs = numpy.max(numpy.abs(dirty.data)) assert maxabs < fluxthreshold, "%s, abs max %f exceeds flux threshold" % ( name, maxabs)
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) from arl.image.operations import fft_image 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)
def test_invert_2d(self): # Test if the 2D invert works with w set to zero # Set w=0 so that the two-dimensional transform should agree exactly with the model. # Good check on the grid correction in the vis->image direction self.actualSetUp() self.componentvis.data['uvw'][:, 2] = 0.0 self.componentvis.data['vis'] *= 0.0 # Predict the visibility using direct evaluation for comp in self.components: predict_skycomponent_visibility(self.componentvis, comp) dirty2d = create_empty_image_like(self.model) dirty2d, sumwt = invert_2d(self.componentvis, dirty2d, **self.params) export_image_to_fits( dirty2d, '%s/test_imaging_functions_invert_2d_dirty.fits' % self.dir) self._checkcomponents(dirty2d)
def test_psf_location_2d(self): self.actualSetUp() psf2d = create_empty_image_like(self.model) psf2d, sumwt = invert_2d(self.componentvis, psf2d, dopsf=True, **self.params) export_image_to_fits( psf2d, '%s/test_imaging_functions_invert_psf_location.fits' % self.dir) nchan, npol, ny, nx = psf2d.shape assert numpy.abs(psf2d.data[0, 0, ny // 2, nx // 2] - 1.0) < 2e-3 imagecentre = pixel_to_skycoord(nx // 2 + 1.0, ny // 2 + 1.0, wcs=psf2d.wcs, origin=1) assert imagecentre.separation(self.phasecentre).value < 1e-15, \ "Image phase centre %s not as expected %s" % (imagecentre, self.phasecentre)
def test_deconvolve_and_restore_cube_mmclean(self): self.bigmodel.data *= 0.0 visres, model, residual = solve_image(self.vis, self.bigmodel, nmajor=3, niter=1000, threshold=0.01, gain=0.7, window='quarter', scales=[0, 3, 10, 30], fractional_threshold=0.1, algorithm='mfsmsclean', nmoments=3) export_image_to_fits( model, '%s/test_solve_image_mmclean_solution.fits' % (self.dir)) export_image_to_fits( residual, '%s/test_solve_image_mmclean_residual.fits' % (self.dir)) psf, sumwt = invert_2d(self.vis, model, dopsf=True) export_image_to_fits( psf, '%s/test_solve_image_mmclean_psf.fits' % (self.dir)) restored = restore_cube(model=model, psf=psf, residual=residual) export_image_to_fits( restored, '%s/test_solve_image_mmclean_restored.fits' % (self.dir)) assert numpy.max(numpy.abs(residual.data)) < 1.2