Beispiel #1
0
 def test_weighting(self):
     self.actualSetUp()
     vis, density, densitygrid = weight_visibility(self.componentvis,
                                                   self.model,
                                                   weighting='uniform')
     assert vis.nvis == self.componentvis.nvis
     assert len(density) == vis.nvis
     assert numpy.std(vis.imaging_weight) > 0.0
     assert densitygrid.data.shape == self.model.data.shape
     vis, density, densitygrid = weight_visibility(self.componentvis,
                                                   self.model,
                                                   weighting='natural')
     assert density is None
     assert densitygrid is None
    def test_skymodel_solve_fixed(self):
        self.actualSetup(ntimes=1, doiso=True, fixed=True)
        calskymodel, residual_vis = calskymodel_solve(self.vis,
                                                      self.skymodels,
                                                      niter=30,
                                                      gain=0.25)

        # Check that the components are unchanged
        calskymodel_skycomponents = list()
        for sm in [csm[0] for csm in calskymodel]:
            for comp in sm.components:
                calskymodel_skycomponents.append(comp)

        recovered_components = find_skycomponent_matches(
            calskymodel_skycomponents, self.components, 1e-5)
        for p in recovered_components:
            assert numpy.abs(calskymodel_skycomponents[p[0]].flux[0, 0] -
                             self.components[p[1]].flux[0, 0]) < 1e-15
            assert calskymodel_skycomponents[p[0]].direction.separation(
                self.components[p[1]].direction).rad < 1e-15

        residual_vis = convert_blockvisibility_to_visibility(residual_vis)
        residual_vis, _, _ = weight_visibility(residual_vis, self.beam)
        dirty, sumwt = invert_function(residual_vis, self.beam, context='2d')
        export_image_to_fits(
            dirty, "%s/test_skymodel-final-iso-residual.fits" % self.dir)

        qa = qa_image(dirty)
        assert qa.data['rms'] < 3.4e-3, qa
Beispiel #3
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 #4
0
 def test_convert_weight(self):
     cvis = convert_blockvisibility_to_visibility(self.blockvis)
     model = create_image_from_visibility(vis=cvis, npixel=256, cellsize=0.001, phasecentre=self.phasecentre,
                                          polarisation_frame=PolarisationFrame('stokesI'))
     cvis = weight_visibility(cvis, model)
     assert numpy.mean(cvis.data['imaging_weight']) < 1.0
     assert numpy.std(cvis.data['imaging_weight']) > 0.0
     dvis = decoalesce_visibility(cvis)
     assert numpy.mean(dvis.data['imaging_weight']) < 1.0
     assert numpy.std(dvis.data['imaging_weight']) > 0.0
     assert dvis.nvis == self.blockvis.nvis
Beispiel #5
0
 def weight_vis(vis, model):
     if vis is not None:
         if model is not None:
             vis, _, _ = weight_visibility(vis,
                                           model,
                                           weighting=weighting,
                                           **kwargs)
             return vis
         else:
             return None
     else:
         return None
Beispiel #6
0
 def test_convert_weight(self):
     cvis = convert_blockvisibility_to_visibility(self.blockvis)
     cvis.data['imaging_weight'] = 10.0
     model = create_image_from_visibility(
         vis=cvis,
         npixel=256,
         cellsize=0.001,
         phasecentre=self.phasecentre,
         polarisation_frame=PolarisationFrame('stokesI'))
     cvis = weight_visibility(cvis, model)
     dvis = decoalesce_visibility(cvis, overwrite=True)
     assert numpy.max(dvis.data['imaging_weight'] - 10.0) < 1e-7
     assert dvis.nvis == self.blockvis.nvis
Beispiel #7
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)
    def test_skymodel_solve_noiso(self):
        self.actualSetup(ntimes=1, doiso=False)
        calskymodel, residual_vis = calskymodel_solve(self.vis,
                                                      self.skymodels,
                                                      niter=30,
                                                      gain=0.25)

        residual_vis = convert_blockvisibility_to_visibility(residual_vis)
        residual_vis, _, _ = weight_visibility(residual_vis, self.beam)
        dirty, sumwt = invert_function(residual_vis, self.beam, context='2d')
        export_image_to_fits(
            dirty, "%s/test_skymodel-final-noiso-residual.fits" % self.dir)

        qa = qa_image(dirty)
        assert qa.data['rms'] < 3.8e-3, qa
 def test_modelpartition_solve_arlexecute(self):
     
     self.actualSetup(doiso=True)
     
     self.skymodel_list = [arlexecute.execute(SkyModel, nout=1)(components=[cm])
                           for cm in self.components]
     
     modelpartition_list = solve_modelpartition_arlexecute(self.vis, skymodel_list=self.skymodel_list, niter=30,
                                                           gain=0.25)
     skymodel, residual_vis = arlexecute.compute(modelpartition_list, sync=True)
     
     residual_vis = convert_blockvisibility_to_visibility(residual_vis)
     residual_vis, _, _ = weight_visibility(residual_vis, self.beam)
     dirty, sumwt = invert_arlexecute(residual_vis, self.beam, context='2d')
     export_image_to_fits(dirty, "%s/test_modelpartition-%s-final-iso-residual.fits" % (self.dir, arlexecute.type()))
     
     qa = qa_image(dirty)
     assert qa.data['rms'] < 3.2e-3, qa
Beispiel #10
0
def image_2d(vis, npixel_advice, cell_advice, channel, results_dir):
    """Do 2D imaging of visibility data.
        
    Args:
    vis (obj): ARL visibility data.
    npixel_advice (float): number of pixels in output image.
    cell_advice (float): cellsize in output image.
    channel (int): channel number to be imaged (affects output filename).
    results_dir (str): directory to save results.
    
    Returns:
    dirty: dirty image.
    psf: image of psf.
    """
    try:
        vis_slices = len(np.unique(vis.time))
        print("There are %d timeslices" % vis_slices)
        # Obtain advice on w-proj parameters:
        advice = advise_wide_field(vis)
        # Create a model image:
        model = create_image_from_visibility(vis, cellsize=cell_advice, npixel=npixel_advice, phasecentre=vis.phasecentre, polarisation_frame=PolarisationFrame('stokesIQUV'))
        # Weight the visibilities:
        vis, _, _ = weight_visibility(vis, model)
        
        # Create a dirty image:
        dirty, sumwt = invert_serial(vis, model, context='2d', vis_slices=1, padding=2)
        # Create the psf:
        psf, sumwt = invert_serial(vis, model, dopsf=True, context='2d', vis_slices=1, padding=2)
        
        # Save to disk:
        export_image_to_fits(dirty, '%s/imaging_dirty_WStack-%s.fits'
                             % (results_dir, channel))
        export_image_to_fits(psf, '%s/imaging_psf_WStack-%s.fits'
                             % (results_dir, channel))
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
    return dirty, psf
    def actualSetup(self,
                    vnchan=1,
                    doiso=True,
                    ntimes=5,
                    flux_limit=2.0,
                    zerow=True,
                    fixed=False):

        nfreqwin = vnchan
        rmax = 300.0
        npixel = 512
        cellsize = 0.001
        frequency = numpy.linspace(0.8e8, 1.2e8, nfreqwin)
        if nfreqwin > 1:
            channel_bandwidth = numpy.array(nfreqwin *
                                            [frequency[1] - frequency[0]])
        else:
            channel_bandwidth = [0.4e8]
        times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)

        phasecentre = SkyCoord(ra=-60.0 * u.deg,
                               dec=-60.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')

        lowcore = create_named_configuration('LOWBD2', rmax=rmax)

        block_vis = create_blockvisibility(
            lowcore,
            times,
            frequency=frequency,
            channel_bandwidth=channel_bandwidth,
            weight=1.0,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            zerow=zerow)

        block_vis.data['uvw'][..., 2] = 0.0
        self.beam = create_image_from_visibility(
            block_vis,
            npixel=npixel,
            frequency=[numpy.average(frequency)],
            nchan=nfreqwin,
            channel_bandwidth=[numpy.sum(channel_bandwidth)],
            cellsize=cellsize,
            phasecentre=phasecentre)

        self.components = create_low_test_skycomponents_from_gleam(
            flux_limit=flux_limit,
            phasecentre=phasecentre,
            frequency=frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=npixel * cellsize)
        self.beam = create_low_test_beam(self.beam)
        self.components = apply_beam_to_skycomponent(self.components,
                                                     self.beam,
                                                     flux_limit=flux_limit)

        self.vis = copy_visibility(block_vis, zero=True)
        gt = create_gaintable_from_blockvisibility(block_vis, timeslice='auto')
        for i, sc in enumerate(self.components):
            if sc.flux[0, 0] > 10:
                sc.flux[...] /= 10.0
            component_vis = copy_visibility(block_vis, zero=True)
            gt = simulate_gaintable(gt,
                                    amplitude_error=0.0,
                                    phase_error=0.1,
                                    seed=None)
            component_vis = predict_skycomponent_visibility(component_vis, sc)
            component_vis = apply_gaintable(component_vis, gt)
            self.vis.data['vis'][...] += component_vis.data['vis'][...]

        # Do an isoplanatic selfcal
        self.model_vis = copy_visibility(self.vis, zero=True)
        self.model_vis = predict_skycomponent_visibility(
            self.model_vis, self.components)
        if doiso:
            gt = solve_gaintable(self.vis,
                                 self.model_vis,
                                 phase_only=True,
                                 timeslice='auto')
            self.vis = apply_gaintable(self.vis, gt, inverse=True)

        self.model_vis = convert_blockvisibility_to_visibility(self.model_vis)
        self.model_vis, _, _ = weight_visibility(self.model_vis, self.beam)
        self.dirty_model, sumwt = invert_function(self.model_vis,
                                                  self.beam,
                                                  context='2d')
        export_image_to_fits(self.dirty_model,
                             "%s/test_skymodel-model_dirty.fits" % self.dir)

        lvis = convert_blockvisibility_to_visibility(self.vis)
        lvis, _, _ = weight_visibility(lvis, self.beam)
        dirty, sumwt = invert_function(lvis, self.beam, context='2d')
        if doiso:
            export_image_to_fits(
                dirty, "%s/test_skymodel-initial-iso-residual.fits" % self.dir)
        else:
            export_image_to_fits(
                dirty,
                "%s/test_skymodel-initial-noiso-residual.fits" % self.dir)

        self.skymodels = [
            SkyModel(components=[cm], fixed=fixed) for cm in self.components
        ]