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],
                                           fractional_threshold=0.1,
                                           algorithm='mmclean',
                                           nmoments=3)
     export_image_to_fits(
         model, '%s/test_solve_image_mmclean_solution.fits' % (self.dir))
     residual, sumwt = invert_2d(visres, model)
     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
Beispiel #2
0
    def setUp(self):
        from data_models.parameters import arl_path
        self.dir = arl_path('test_results')
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)
        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e6])
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'),
            zerow=True)
        self.vis.data['vis'] *= 0.0

        # Create model
        self.test_model = create_test_image(cellsize=0.001,
                                            phasecentre=self.vis.phasecentre,
                                            frequency=self.frequency)
        self.vis = predict_2d(self.vis, self.test_model)
        assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
        self.model = create_image_from_visibility(
            self.vis,
            npixel=512,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.dirty, sumwt = invert_2d(self.vis, self.model)
        self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True)
 def test_deconvolve_and_restore_cube_hogbom(self):
     self.bigmodel.data *= 0.0
     visres, model, _ = solve_image(self.vis,
                                    self.bigmodel,
                                    nmajor=5,
                                    niter=1000,
                                    threshold=0.01,
                                    gain=0.1,
                                    psf_support=200,
                                    window='quarter',
                                    fractional_threshold=0.1,
                                    algorithm='hogbom')
     assert numpy.max(numpy.abs(model.data)) > 0.0, "Model image is empty"
     export_image_to_fits(
         model,
         '%s/test_solve_skycomponent_hogbom_solution.fits' % (self.dir))
     residual, sumwt = invert_2d(visres, model)
     export_image_to_fits(
         residual,
         '%s/test_solve_skycomponent_msclean_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
Beispiel #4
0
    def setUp(self):
        from data_models.parameters import arl_path
        self.dir = arl_path('test_results')
        self.niter = 1000
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.nchan = 5
        self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7)
        self.frequency = numpy.linspace(0.9e8, 1.1e8, self.nchan)
        self.channel_bandwidth = numpy.array(
            self.nchan * [self.frequency[1] - self.frequency[0]])
        self.phasecentre = SkyCoord(ra=+0.0 * u.deg,
                                    dec=-45.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'),
            zerow=True)
        self.vis.data['vis'] *= 0.0

        # Create model
        self.test_model = create_low_test_image_from_gleam(
            npixel=512,
            cellsize=0.001,
            phasecentre=self.vis.phasecentre,
            frequency=self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            flux_limit=1.0)
        beam = create_low_test_beam(self.test_model)
        export_image_to_fits(beam,
                             "%s/test_deconvolve_mmclean_beam.fits" % self.dir)
        self.test_model.data *= beam.data
        export_image_to_fits(
            self.test_model,
            "%s/test_deconvolve_mmclean_model.fits" % self.dir)
        self.vis = predict_2d(self.vis, self.test_model)
        assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
        self.model = create_image_from_visibility(
            self.vis,
            npixel=512,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.dirty, sumwt = invert_2d(self.vis, self.model)
        self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True)
        export_image_to_fits(
            self.dirty, "%s/test_deconvolve_mmclean-dirty.fits" % self.dir)
        export_image_to_fits(self.psf,
                             "%s/test_deconvolve_mmclean-psf.fits" % self.dir)
        window = numpy.ones(shape=self.model.shape, dtype=numpy.bool)
        window[..., 129:384, 129:384] = True
        self.innerquarter = create_image_from_array(
            window,
            self.model.wcs,
            polarisation_frame=PolarisationFrame('stokesI'))
Beispiel #5
0
 def test_tapering_Gaussian(self):
     self.actualSetUp()
     size_required = 0.003542
     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)
Beispiel #6
0
    def test_invert(self):

        uvfitsfile = arl_path("data/vis/ASKAP_example.fits")

        nchan_ave = 32
        nchan = 192
        for schan in range(0, nchan, nchan_ave):
            max_chan = min(nchan, schan + nchan_ave)
            bv = create_blockvisibility_from_uvfits(uvfitsfile,
                                                    range(schan, max_chan))[0]
            vis = convert_blockvisibility_to_visibility(bv)
            from processing_components.visibility.operations import convert_visibility_to_stokesI
            vis = convert_visibility_to_stokesI(vis)
            model = create_image_from_visibility(
                vis,
                npixel=256,
                polarisation_frame=PolarisationFrame('stokesI'))
            dirty, sumwt = invert_2d(vis, model, context='2d')
            assert (numpy.max(numpy.abs(dirty.data))) > 0.0
            assert dirty.shape == (nchan_ave, 1, 256, 256)
            import matplotlib.pyplot as plt
            from processing_components.image.operations import show_image
            show_image(dirty)
            plt.show()
            if self.persist:
                export_image_to_fits(
                    dirty, '%s/test_visibility_uvfits_dirty.fits' % self.dir)
    def _predict_base(self,
                      fluxthreshold=1.0,
                      gcf=None,
                      cf=None,
                      name='predict_2d',
                      gcfcf=None,
                      **kwargs):

        vis = predict_2d(self.vis, self.model, gcfcf=gcfcf, **kwargs)
        vis.data['vis'] = self.vis.data['vis'] - vis.data['vis']
        dirty = invert_2d(vis,
                          self.model,
                          dopsf=False,
                          normalize=True,
                          gcfcf=gcfcf)

        if self.persist:
            export_image_to_fits(
                dirty[0],
                '%s/test_imaging_%s_residual.fits' % (self.dir, name))
        assert numpy.max(numpy.abs(dirty[0].data)), "Residual image is empty"

        maxabs = numpy.max(numpy.abs(dirty[0].data))
        assert maxabs < fluxthreshold, "Error %.3f greater than fluxthreshold %.3f " % (
            maxabs, fluxthreshold)
    def test_insert_skycomponent_dft(self):
        self.sc = create_skycomponent(direction=self.phasecentre, flux=self.sc.flux,
                                    frequency=self.component_frequency,
                                    polarisation_frame=PolarisationFrame('stokesI'))

        self.vis.data['vis'][...] = 0.0
        self.vis = predict_skycomponent_visibility(self.vis, self.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
Beispiel #9
0
 def _invert_base(self, fluxthreshold=1.0, positionthreshold=1.0, check_components=True,
                  name='predict_2d', gcfcf=None, **kwargs):
     
     dirty = invert_2d(self.vis, self.model, dopsf=False, normalize=True, gcfcf = gcfcf, **kwargs)
     
     export_image_to_fits(dirty[0], '%s/test_imaging_%s_dirty.fits' %
                          (self.dir, name))
     
     assert numpy.max(numpy.abs(dirty[0].data)), "Image is empty"
     
     if check_components:
         self._checkcomponents(dirty[0], fluxthreshold, positionthreshold)
Beispiel #10
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)
Beispiel #11
0
def invert_timeslice_single(vis: Visibility,
                            im: Image,
                            dopsf,
                            normalize=True,
                            remove=True,
                            gcfcf=None,
                            **kwargs) -> (Image, numpy.ndarray):
    """Process single time slice

    Extracted for re-use in parallel version
    :param vis: Visibility to be inverted
    :param im: image template (not changed)
    :param dopsf: Make the psf instead of the dirty image
    :param gcfcf: (Grid correction function, convolution function)
    :param normalize: Normalize by the sum of weights (True)
    """
    assert isinstance(vis, Visibility), vis

    uvw = vis.uvw
    vis, p, q = fit_uvwplane(vis, remove=remove)

    workimage, sumwt = invert_2d(vis,
                                 im,
                                 dopsf,
                                 normalize=normalize,
                                 gcfcf=gcfcf,
                                 **kwargs)
    # Work image is distorted. We describe the distortion by putting the olbiquity parameters in
    # the wcs. The output image should be described as having zero olbiquity parameters.

    if numpy.abs(p) > 1e-7 or numpy.abs(q) > 1e-7:
        # Note that this has to be zero relative in first element, one relative in second!!!!
        workimage.wcs.wcs.set_pv([(0, 1, -p), (0, 2, -q)])

        finalimage, footprint = reproject_image(workimage, im.wcs, im.shape)
        finalimage.data[footprint.data <= 0.0] = 0.0
        finalimage.wcs.wcs.set_pv([(0, 1, 0.0), (0, 2, 0.0)])

        if remove:
            vis.data['uvw'][...] = uvw

        return finalimage, sumwt
    else:
        if remove:
            vis.data['uvw'][...] = uvw

        return workimage, sumwt
    def setUp(self):
        from data_models.parameters import arl_path
        self.dir = arl_path('test_results')
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)
        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e6])
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.vis.data['vis'] *= 0.0
        self.vis.data['uvw'][:, 2] = 0.0

        # Create model
        self.model = create_test_image(cellsize=0.0015,
                                       phasecentre=self.vis.phasecentre,
                                       frequency=self.frequency)
        self.model.data[self.model.data > 1.0] = 1.0
        self.vis = predict_2d(self.vis, self.model)
        assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
        export_image_to_fits(
            self.model, '%s/test_solve_skycomponent_model.fits' % (self.dir))
        self.bigmodel = create_image_from_visibility(self.vis,
                                                     cellsize=0.0015,
                                                     npixel=512)
        residual, sumwt = invert_2d(self.vis, self.bigmodel)
        export_image_to_fits(
            residual,
            '%s/test_solve_skycomponent_msclean_dirty.fits' % (self.dir))