Exemplo n.º 1
0
    def _predict_base(self,
                      context='2d',
                      extra='',
                      fluxthreshold=1.0,
                      facets=1,
                      vis_slices=1,
                      **kwargs):
        vis_list = zero_vislist_component(self.vis_list)
        vis_list = predict_component(vis_list,
                                     self.model_graph,
                                     context=context,
                                     vis_slices=vis_slices,
                                     facets=facets,
                                     **kwargs)
        vis_list = subtract_vislist_component(self.vis_list, vis_list)[0]

        vis_list = arlexecute.compute(vis_list, sync=True)

        dirty = invert_component([vis_list], [self.model_graph[0]],
                                 context='2d',
                                 dopsf=False,
                                 normalize=True)[0]
        dirty = arlexecute.compute(dirty, sync=True)

        assert numpy.max(numpy.abs(dirty[0].data)), "Residual image is empty"
        export_image_to_fits(
            dirty[0], '%s/test_imaging_predict_%s%s_%s_dirty.fits' %
            (self.dir, context, extra, arlexecute.type()))

        maxabs = numpy.max(numpy.abs(dirty[0].data))
        assert maxabs < fluxthreshold, "Error %.3f greater than fluxthreshold %.3f " % (
            maxabs, fluxthreshold)
Exemplo n.º 2
0
    def _invert_base(self,
                     context,
                     extra='',
                     fluxthreshold=1.0,
                     positionthreshold=1.0,
                     check_components=True,
                     facets=1,
                     vis_slices=1,
                     **kwargs):

        dirty = invert_component(self.vis_list,
                                 self.model_graph,
                                 context=context,
                                 dopsf=False,
                                 normalize=True,
                                 facets=facets,
                                 vis_slices=vis_slices,
                                 **kwargs)[0]
        dirty = arlexecute.compute(dirty, sync=True)

        export_image_to_fits(
            dirty[0], '%s/test_imaging_invert_%s%s_%s_dirty.fits' %
            (self.dir, context, extra, arlexecute.type()))

        assert numpy.max(numpy.abs(dirty[0].data)), "Image is empty"

        if check_components:
            self._checkcomponents(dirty[0], fluxthreshold, positionthreshold)
    def test_continuum_imaging_pipeline(self):
        self.actualSetUp(add_errors=False, block=True)
        continuum_imaging_list = \
            continuum_imaging_component(self.vis_list, model_imagelist=self.model_imagelist, context='2d',
                                        algorithm='mmclean', facets=1,
                                        scales=[0, 3, 10],
                                        niter=1000, fractional_threshold=0.1,
                                        nmoments=2, nchan=self.freqwin,
                                        threshold=2.0, nmajor=5, gain=0.1,
                                        deconvolve_facets=8, deconvolve_overlap=16,
                                        deconvolve_taper='tukey')
        clean, residual, restored = arlexecute.compute(continuum_imaging_list,
                                                       sync=True)
        export_image_to_fits(
            clean[0],
            '%s/test_pipelines_continuum_imaging_pipeline_clean.fits' %
            self.dir)
        export_image_to_fits(
            residual[0][0],
            '%s/test_pipelines_continuum_imaging_pipeline_residual.fits' %
            self.dir)
        export_image_to_fits(
            restored[0],
            '%s/test_pipelines_continuum_imaging_pipeline_restored.fits' %
            self.dir)

        qa = qa_image(restored[0])
        assert numpy.abs(qa.data['max'] - 116.9) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.118) < 1.0, str(qa)
Exemplo n.º 4
0
    def test_useFunction(self):
        def square(x):
            return x**2

        arlexecute.set_client(use_dask=False)
        graph = arlexecute.execute(square)(numpy.arange(10))
        assert (arlexecute.compute(graph) == numpy.array(
            [0, 1, 4, 9, 16, 25, 36, 49, 64, 81])).all()
        arlexecute.close()
Exemplo n.º 5
0
    def test_useDaskSync(self):
        def square(x):
            return x**2

        arlexecute.set_client(use_dask=True)
        graph = arlexecute.execute(square)(numpy.arange(10))
        result = arlexecute.compute(graph, sync=True)
        assert (result == numpy.array([0, 1, 4, 9, 16, 25, 36, 49, 64,
                                       81])).all()
        arlexecute.close()
Exemplo n.º 6
0
    def test_create_generic_image_graph(self):
        def imagerooter(im):
            im.data = numpy.sqrt(numpy.abs(im.data))
            return im

        root = generic_image_component(imagerooter, self.image, facets=4)
        root = arlexecute.compute(root, sync=True)
        arlexecute.close()

        numpy.testing.assert_array_almost_equal_nulp(
            root.data**2, numpy.abs(self.image.data), 7)
 def test_deconvolve_spectral(self):
     self.actualSetUp(add_errors=True)
     dirty_imagelist = invert_component(self.vis_list, self.model_imagelist,
                                        context='2d',
                                        dopsf=False, normalize=True)
     psf_imagelist = invert_component(self.vis_list, self.model_imagelist,
                                      context='2d',
                                      dopsf=True, normalize=True)
     deconvolved, _ = deconvolve_component(dirty_imagelist, psf_imagelist, self.model_imagelist, niter=1000,
                                           fractional_threshold=0.1, scales=[0, 3, 10],
                                           threshold=0.1, gain=0.7)
     deconvolved = arlexecute.compute(deconvolved, sync=True)
     
     export_image_to_fits(deconvolved[0], '%s/test_imaging_%s_deconvolve_spectral.fits' %
                          (self.dir, arlexecute.type()))
Exemplo n.º 8
0
    def test_weighting(self):

        self.actualSetUp()

        context = 'wstack'
        vis_slices = 41
        facets = 1

        dirty_graph = invert_component(self.vis_list,
                                       self.model_graph,
                                       context=context,
                                       dopsf=False,
                                       normalize=True,
                                       facets=facets,
                                       vis_slices=vis_slices)
        dirty = arlexecute.compute(dirty_graph[0], sync=True)
        export_image_to_fits(
            dirty[0], '%s/test_imaging_noweighting_%s_dirty.fits' %
            (self.dir, arlexecute.type()))
 def test_deconvolve_and_restore_cube_mmclean(self):
     self.actualSetUp(add_errors=True)
     dirty_imagelist = invert_component(self.vis_list, self.model_imagelist, context='2d',
                                        dopsf=False, normalize=True)
     psf_imagelist = invert_component(self.vis_list, self.model_imagelist, context='2d',
                                      dopsf=True, normalize=True)
     dec_imagelist, _ = deconvolve_component(dirty_imagelist, psf_imagelist, self.model_imagelist, niter=1000,
                                             fractional_threshold=0.01, scales=[0, 3, 10],
                                             algorithm='mmclean', nmoments=3, nchan=self.freqwin,
                                             threshold=0.1, gain=0.7)
     residual_imagelist = residual_component(self.vis_list, model_imagelist=dec_imagelist,
                                             context='wstack', vis_slices=51)
     restored = restore_component(model_imagelist=dec_imagelist, psf_imagelist=psf_imagelist,
                                  residual_imagelist=residual_imagelist,
                                  empty=self.model_imagelist)[0]
     
     restored = arlexecute.compute(restored, sync=True)
     
     export_image_to_fits(restored, '%s/test_imaging_%s_mmclean_restored.fits' % (self.dir, arlexecute.type()))
    def test_ical_pipeline(self):
        amp_errors = {'T': 0.0, 'G': 0.00, 'B': 0.0}
        phase_errors = {'T': 0.1, 'G': 0.0, 'B': 0.0}
        self.actualSetUp(add_errors=True,
                         block=True,
                         amp_errors=amp_errors,
                         phase_errors=phase_errors)

        controls = create_calibration_controls()

        controls['T']['first_selfcal'] = 1
        controls['G']['first_selfcal'] = 3
        controls['B']['first_selfcal'] = 4

        controls['T']['timescale'] = 'auto'
        controls['G']['timescale'] = 'auto'
        controls['B']['timescale'] = 1e5

        ical_list = \
            ical_component(self.vis_list, model_imagelist=self.model_imagelist, context='2d',
                           calibration_context='T', controls=controls, do_selfcal=True,
                           global_solution=False,
                           algorithm='mmclean',
                           facets=1,
                           scales=[0, 3, 10],
                           niter=1000, fractional_threshold=0.1,
                           nmoments=2, nchan=self.freqwin,
                           threshold=2.0, nmajor=5, gain=0.1,
                           deconvolve_facets=8, deconvolve_overlap=16, deconvolve_taper='tukey')
        clean, residual, restored = arlexecute.compute(ical_list, sync=True)
        export_image_to_fits(
            clean[0], '%s/test_pipelines_ical_pipeline_clean.fits' % self.dir)
        export_image_to_fits(
            residual[0][0],
            '%s/test_pipelines_ical_pipeline_residual.fits' % self.dir)
        export_image_to_fits(
            restored[0],
            '%s/test_pipelines_ical_pipeline_restored.fits' % self.dir)

        qa = qa_image(restored[0])
        assert numpy.abs(qa.data['max'] - 116.9) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.118) < 1.0, str(qa)
Exemplo n.º 11
0
    def test_create_generic_blockvisibility_graph(self):
        self.blockvis = [
            create_blockvisibility(
                self.lowcore,
                self.times,
                self.frequency,
                phasecentre=self.phasecentre,
                channel_bandwidth=self.channel_bandwidth,
                weight=1.0,
                polarisation_frame=PolarisationFrame('stokesI'))
        ]

        self.blockvis = generic_blockvisibility_component(
            predict_skycomponent_visibility,
            vis_list=self.blockvis,
            sc=self.comp)[0]

        self.blockvis = arlexecute.compute(self.blockvis, sync=True)
        arlexecute.close()

        assert numpy.max(numpy.abs(self.blockvis[0].vis)) > 0.0
Exemplo n.º 12
0
    def test_calskymodel_solve_component(self):

        self.actualSetup(doiso=True)

        self.skymodel_list = [
            arlexecute.execute(SkyModel, nout=1)(components=[cm])
            for cm in self.components
        ]

        calskymodel_list = calskymodel_solve_component(
            self.vis, skymodel_list=self.skymodel_list, niter=30, gain=0.25)
        skymodel, residual_vis = arlexecute.compute(calskymodel_list,
                                                    sync=True)

        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_calskymodel-%s-final-iso-residual.fits" %
            (self.dir, arlexecute.type()))

        qa = qa_image(dirty)
        assert qa.data['rms'] < 3.2e-3, qa
                               threshold=0.1,
                               nmajor=5,
                               gain=0.25,
                               deconvolve_facets=8,
                               deconvolve_overlap=32,
                               deconvolve_taper='tukey',
                               vis_slices=ntimes,
                               timeslice='auto',
                               global_solution=False,
                               psf_support=64,
                               do_selfcal=True)

    # In[ ]:

    log.info('About to run ical')
    result = arlexecute.compute(ical_list, sync=True)
    deconvolved = result[0][0]
    residual = result[1][0]
    restored = result[2][0]
    arlexecute.close()

    show_image(deconvolved,
               title='Clean image',
               cm='Greys',
               vmax=0.1,
               vmin=-0.01)
    print(qa_image(deconvolved, context='Clean image'))
    plt.show()
    export_image_to_fits(deconvolved,
                         '%s/gleam_ical_deconvolved.fits' % (results_dir))
Exemplo n.º 14
0
    def actualSetUp(self,
                    add_errors=False,
                    freqwin=1,
                    block=False,
                    dospectral=True,
                    dopol=False,
                    zerow=False):

        arlexecute.set_client(use_dask=True)

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

        if freqwin > 1:
            self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
            self.channelwidth = numpy.array(
                freqwin * [self.frequency[1] - self.frequency[0]])
        else:
            self.frequency = numpy.array([0.8e8])
            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.vis_list = [
            arlexecute.execute(ingest_unittest_visibility)(
                self.low, [self.frequency[freqwin]],
                [self.channelwidth[freqwin]],
                self.times,
                self.vis_pol,
                self.phasecentre,
                block=block,
                zerow=zerow) for freqwin, _ in enumerate(self.frequency)
        ]

        self.model_graph = [
            arlexecute.execute(create_unittest_model,
                               nout=freqwin)(self.vis_list[freqwin],
                                             self.image_pol,
                                             npixel=self.npixel)
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.components_graph = [
            arlexecute.execute(create_unittest_components)(
                self.model_graph[freqwin], flux[freqwin, :][numpy.newaxis, :])
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.model_graph = [
            arlexecute.execute(insert_skycomponent,
                               nout=1)(self.model_graph[freqwin],
                                       self.components_graph[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.vis_list = [
            arlexecute.execute(predict_skycomponent_visibility)(
                self.vis_list[freqwin], self.components_graph[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        # Calculate the model convolved with a Gaussian.
        self.model = arlexecute.compute(self.model_graph[0], sync=True)

        self.cmodel = smooth_image(self.model)
        export_image_to_fits(self.model,
                             '%s/test_imaging_model.fits' % self.dir)
        export_image_to_fits(self.cmodel,
                             '%s/test_imaging_cmodel.fits' % self.dir)

        if add_errors and block:
            self.vis_list = [
                arlexecute.execute(insert_unittest_errors)(self.vis_list[i])
                for i, _ in enumerate(self.frequency)
            ]

        self.vis = arlexecute.compute(self.vis_list[0], sync=True)

        self.components = arlexecute.compute(self.components_graph[0],
                                             sync=True)
    def actualSetUp(self,
                    add_errors=False,
                    freqwin=5,
                    block=False,
                    dospectral=True,
                    dopol=False,
                    amp_errors=None,
                    phase_errors=None,
                    zerow=True):

        if amp_errors is None:
            amp_errors = {'T': 0.0, 'G': 0.01, 'B': 0.01}
        if phase_errors is None:
            phase_errors = {'T': 1.0, 'G': 0.1, 'B': 0.01}

        self.npixel = 512
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        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 freqwin > 1:
            self.channelwidth = numpy.array(
                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.vis_list = [
            arlexecute.execute(ingest_unittest_visibility)(
                self.low, [self.frequency[i]], [self.channelwidth[i]],
                self.times,
                self.vis_pol,
                self.phasecentre,
                block=block,
                zerow=zerow) for i, _ in enumerate(self.frequency)
        ]

        self.model_imagelist = [
            arlexecute.execute(create_unittest_model,
                               nout=freqwin)(self.vis_list[0],
                                             self.image_pol,
                                             npixel=self.npixel)
            for i, _ in enumerate(self.frequency)
        ]

        self.components_list = [
            arlexecute.execute(create_unittest_components)(
                self.model_imagelist[i], flux[i, :][numpy.newaxis, :])
            for i, _ in enumerate(self.frequency)
        ]

        # Apply the LOW primary beam and insert into model
        self.model_imagelist = [
            arlexecute.execute(insert_skycomponent,
                               nout=1)(self.model_imagelist[freqwin],
                                       self.components_list[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.vis_list = [
            arlexecute.execute(predict_skycomponent_visibility)(
                self.vis_list[freqwin], self.components_list[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        # Calculate the model convolved with a Gaussian.
        self.model_imagelist = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        model = self.model_imagelist[0]
        self.cmodel = smooth_image(model)
        export_image_to_fits(model,
                             '%s/test_imaging_delayed_model.fits' % self.dir)
        export_image_to_fits(self.cmodel,
                             '%s/test_imaging_delayed_cmodel.fits' % self.dir)

        if add_errors and block:
            self.vis_list = [
                arlexecute.execute(insert_unittest_errors)(
                    self.vis_list[i],
                    amp_errors=amp_errors,
                    phase_errors=phase_errors)
                for i, _ in enumerate(self.frequency)
            ]

        self.vis_list = arlexecute.compute(self.vis_list, sync=True)

        self.vis_list = arlexecute.scatter(self.vis_list)
        self.model_imagelist = arlexecute.scatter(self.model_imagelist)
Exemplo n.º 16
0
    rmax = 300.0
    frequency = numpy.linspace(0.9e8, 1.1e8, nfreqwin)
    channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]])
    times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)
    phasecentre = SkyCoord(ra=+30.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
    
    vis_list = simulate_component('LOWBD2',
                                  rmax=rmax,
                                  frequency=frequency,
                                  channel_bandwidth=channel_bandwidth,
                                  times=times,
                                  phasecentre=phasecentre,
                                  order='frequency')
    print('%d elements in vis_list' % len(vis_list))
    log.info('About to make visibility')
    vis_list = arlexecute.compute(vis_list, sync=True)
    
    print(vis_list[0])

    
    # In[ ]:
    
    wprojection_planes = 1
    advice_low = advise_wide_field(vis_list[0], guard_band_image=8.0, delA=0.02, wprojection_planes=wprojection_planes)
    
    advice_high = advise_wide_field(vis_list[-1], guard_band_image=8.0, delA=0.02,
                                    wprojection_planes=wprojection_planes)
    
    vis_slices = advice_low['vis_slices']
    npixel = advice_high['npixels2']
    cellsize = min(advice_low['cellsize'], advice_high['cellsize'])