Exemplo n.º 1
0
    def corrupt_vis(vis, gt, **kwargs):
        if isinstance(vis, Visibility):
            bv = convert_visibility_to_blockvisibility(vis)
        else:
            bv = vis
        if gt is None:
            gt = create_gaintable_from_blockvisibility(bv, **kwargs)
            gt = simulate_gaintable(gt, seed=seed, **kwargs)
            bv = apply_gaintable(bv, gt)

        if isinstance(vis, Visibility):
            return convert_blockvisibility_to_visibility(bv)
        else:
            return bv
Exemplo n.º 2
0
    def actualSetUp(self,
                    add_errors=False,
                    nfreqwin=7,
                    dospectral=True,
                    dopol=False,
                    zerow=True):

        self.npixel = 512
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = nfreqwin
        self.vis_list = list()
        self.ntimes = 5
        self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0
        self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)

        if self.freqwin > 1:
            self.channelwidth = numpy.array(
                self.freqwin * [self.frequency[1] - self.frequency[0]])
        else:
            self.channelwidth = numpy.array([1e6])

        if dopol:
            self.vis_pol = PolarisationFrame('linear')
            self.image_pol = PolarisationFrame('stokesIQUV')
            f = numpy.array([100.0, 20.0, -10.0, 1.0])
        else:
            self.vis_pol = PolarisationFrame('stokesI')
            self.image_pol = PolarisationFrame('stokesI')
            f = numpy.array([100.0])

        if dospectral:
            flux = numpy.array(
                [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
        else:
            flux = numpy.array([f])

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.blockvis_list = [
            arlexecute.execute(ingest_unittest_visibility,
                               nout=1)(self.low, [self.frequency[i]],
                                       [self.channelwidth[i]],
                                       self.times,
                                       self.vis_pol,
                                       self.phasecentre,
                                       block=True,
                                       zerow=zerow) for i in range(nfreqwin)
        ]
        self.blockvis_list = arlexecute.compute(self.blockvis_list, sync=True)
        self.blockvis_list = arlexecute.scatter(self.blockvis_list)

        self.vis_list = [
            arlexecute.execute(convert_blockvisibility_to_visibility,
                               nout=1)(bv) for bv in self.blockvis_list
        ]
        self.vis_list = arlexecute.compute(self.vis_list, sync=True)
        self.vis_list = arlexecute.scatter(self.vis_list)

        self.model_imagelist = [
            arlexecute.execute(create_unittest_model,
                               nout=1)(self.vis_list[i],
                                       self.image_pol,
                                       npixel=self.npixel,
                                       cellsize=0.0005)
            for i in range(nfreqwin)
        ]
        self.model_imagelist = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        self.model_imagelist = arlexecute.scatter(self.model_imagelist)

        self.components_list = [
            arlexecute.execute(create_unittest_components)(
                self.model_imagelist[freqwin],
                flux[freqwin, :][numpy.newaxis, :])
            for freqwin, m in enumerate(self.model_imagelist)
        ]
        self.components_list = arlexecute.compute(self.components_list,
                                                  sync=True)
        self.components_list = arlexecute.scatter(self.components_list)

        self.blockvis_list = [
            arlexecute.execute(predict_skycomponent_visibility)(
                self.blockvis_list[freqwin], self.components_list[freqwin])
            for freqwin, _ in enumerate(self.blockvis_list)
        ]
        self.blockvis_list = arlexecute.compute(self.blockvis_list, sync=True)
        self.vis = self.blockvis_list[0]
        self.blockvis_list = arlexecute.scatter(self.blockvis_list)

        self.model_imagelist = [
            arlexecute.execute(insert_skycomponent,
                               nout=1)(self.model_imagelist[freqwin],
                                       self.components_list[freqwin])
            for freqwin in range(nfreqwin)
        ]
        self.model_imagelist = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        model = self.model_imagelist[0]
        self.cmodel = smooth_image(model)
        if self.persist:
            export_image_to_fits(
                model, '%s/test_pipelines_arlexecute_model.fits' % self.dir)
            export_image_to_fits(
                self.cmodel,
                '%s/test_pipelines_arlexecute_cmodel.fits' % self.dir)

        if add_errors:
            gt = create_gaintable_from_blockvisibility(self.vis)
            gt = simulate_gaintable(gt,
                                    phase_error=0.1,
                                    amplitude_error=0.0,
                                    smooth_channels=1,
                                    leakage=0.0,
                                    seed=180555)
            self.blockvis_list = [
                arlexecute.execute(apply_gaintable,
                                   nout=1)(self.blockvis_list[i], gt)
                for i in range(self.freqwin)
            ]
            self.blockvis_list = arlexecute.compute(self.blockvis_list,
                                                    sync=True)
            self.blockvis_list = arlexecute.scatter(self.blockvis_list)

        self.vis_list = [
            arlexecute.execute(convert_blockvisibility_to_visibility)(bv)
            for bv in self.blockvis_list
        ]
        self.vis_list = arlexecute.compute(self.vis_list, sync=True)
        self.vis_list = arlexecute.scatter(self.vis_list)

        self.model_imagelist = [
            arlexecute.execute(create_unittest_model,
                               nout=1)(self.vis_list[i],
                                       self.image_pol,
                                       npixel=self.npixel,
                                       cellsize=0.0005)
            for i in range(nfreqwin)
        ]
        self.model_imagelist = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        self.model_imagelist = arlexecute.scatter(self.model_imagelist)
    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_list_arlexecute_workflow(
            self.model_vis, self.beam, context='2d')
        export_image_to_fits(
            self.dirty_model,
            "%s/test_modelpartition-model_dirty.fits" % self.dir)

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

        self.skymodels = [
            SkyModel(components=[cm], fixed=fixed) for cm in self.components
        ]
Exemplo n.º 4
0
 def corrupt_vis(vis, gt, **kwargs):
     if gt is None:
         gt = create_gaintable_from_blockvisibility(vis, **kwargs)
         gt = simulate_gaintable(gt, **kwargs)
     return apply_gaintable(vis, gt)
Exemplo n.º 5
0
                                                      0]).flatten(),
                numpy.angle(gt_list[i]['T'].gain[:, :, 0, 0, 0]).flatten(),
                '.')
        plt.xlabel('Current phase')
        plt.ylabel('Update to phase')
        plt.title("%s iteration%d: Change in phase" % (context, it))
        plt.savefig(
            arl_path(
                "test_results/low-sims-mpc-%s-skymodel-phase-change_iteration%d.jpg"
                % (context, it)))
        plt.show(block=block_plots)
        return tl_list

    all_fluxes = [sm.components[0].flux[0, 0] for sm in all_skymodel]

    null_gaintable = create_gaintable_from_blockvisibility(block_vis)

    #######################################################################################################
    # Set up and run MPCCAL in ICAL mode i.e. there is only one skymodel
    model = create_image_from_visibility(block_vis,
                                         npixel=npixel,
                                         frequency=frequency,
                                         nchan=nfreqwin,
                                         cellsize=cellsize,
                                         phasecentre=phasecentre)

    ical_skymodel = [
        SkyModel(components=all_components[:args.ninitial],
                 gaintable=null_gaintable,
                 image=model)
    ]