def test_create_visibility_polarisation(self):
     self.vis = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame("linear"))
     assert self.vis.nvis == len(self.vis.time)
     assert self.vis.nvis == len(self.vis.frequency)
Example #2
0
    def actualSetUp(self, times=None):
        if times is not None:
            self.times = times

        self.vis = create_visibility(self.lowcore,
                                     self.times,
                                     self.frequency,
                                     channel_bandwidth=self.channel_bandwidth,
                                     phasecentre=self.phasecentre,
                                     weight=1.0)
        self.vis.data['vis'][:, 0] = self.vis.time
Example #3
0
 def test_sum_visibility(self):
     self.vis = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         polarisation_frame=PolarisationFrame("linear"),
         weight=1.0)
     self.vis = predict_skycomponent_visibility(self.vis, self.comp)
     flux, weight = sum_visibility(self.vis, self.comp.direction)
     assert numpy.max(numpy.abs(flux - self.flux)) < 1e-7
Example #4
0
 def test_addnoise_visibility(self):
     self.vis = create_visibility(
         self.config,
         self.times,
         self.frequency,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame('stokesIQUV'),
         channel_bandwidth=self.channel_bandwidth)
     original = copy_visibility(self.vis)
     self.vis = addnoise_visibility(self.vis)
     actual = numpy.std(numpy.abs(self.vis.vis - original.vis))
     assert abs(actual - 0.010786973492702846) < 1e-4, actual
Example #5
0
 def test_subtract(self):
     vis1 = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame("stokesIQUV"))
     vis1.data['vis'][...] = 1.0
     vis2 = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame("stokesIQUV"))
     vis2.data['vis'][...] = 1.0
     zerovis = subtract_visibility(vis1, vis2)
     qa = qa_visibility(zerovis, context='test_qa')
     self.assertAlmostEqual(qa.data['maxabs'], 0.0, 7)
Example #6
0
 def test_create_visibility_from_rows1(self):
     self.vis = create_visibility(self.lowcore,
                                  self.times,
                                  self.frequency,
                                  channel_bandwidth=self.channel_bandwidth,
                                  phasecentre=self.phasecentre,
                                  weight=1.0)
     rows = self.vis.time > 150.0
     for makecopy in [True, False]:
         selected_vis = create_visibility_from_rows(self.vis,
                                                    rows,
                                                    makecopy=makecopy)
         assert selected_vis.nvis == numpy.sum(numpy.array(rows))
Example #7
0
 def test_visibilitysum(self):
     self.vis = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame("stokesIQUV"))
     self.vismodel = predict_skycomponent_visibility(self.vis, self.comp)
     # Sum the visibilities in the correct_visibility direction. This is limited by numerical precision
     summedflux, weight = sum_visibility(self.vismodel,
                                         self.compreldirection)
     assert_allclose(self.flux, summedflux, rtol=1e-7)
Example #8
0
 def createVis(self, config, dec=-35.0, rmax=None):
     self.config = create_named_configuration(config, rmax=rmax)
     self.phasecentre = SkyCoord(ra=+15 * u.deg,
                                 dec=dec * u.deg,
                                 frame='icrs',
                                 equinox='J2000')
     self.vis = create_visibility(
         self.config,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame('stokesI'))
Example #9
0
 def test_qa(self):
     self.vis = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame("stokesIQUV"))
     self.vismodel = predict_skycomponent_visibility(self.vis, self.comp)
     qa = qa_visibility(self.vis, context='test_qa')
     self.assertAlmostEqual(qa.data['maxabs'], 100.0, 7)
     self.assertAlmostEqual(qa.data['medianabs'], 11.0, 7)
     assert qa.context == 'test_qa'
Example #10
0
 def test_copy_visibility(self):
     self.vis = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame("stokesIQUV"))
     vis = copy_visibility(self.vis)
     self.vis.data['vis'] = 0.0
     vis.data['vis'] = 1.0
     assert (vis.data['vis'][0, 0].real == 1.0)
     assert (self.vis.data['vis'][0, 0].real == 0.0)
 def test_phase_rotation_inverse(self):
     self.vis = create_visibility(self.lowcore, self.times, self.frequency,
                                  channel_bandwidth=self.channel_bandwidth,
                                  phasecentre=self.phasecentre, weight=1.0,
                                  polarisation_frame=PolarisationFrame("stokesIQUV"))
     self.vismodel = predict_skycomponent_visibility(self.vis, self.comp)
     there = SkyCoord(ra=+250.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     # Phase rotating back should not make a difference
     original_vis = self.vismodel.vis
     original_uvw = self.vismodel.uvw
     rotatedvis = phaserotate_visibility(phaserotate_visibility(self.vismodel, there, tangent=False,
                                                                inverse=True),
                                         self.phasecentre, tangent=False, inverse=True)
     assert_allclose(rotatedvis.uvw, original_uvw, rtol=1e-7)
     assert_allclose(rotatedvis.vis, original_vis, rtol=1e-7)
 def test_phase_rotation_identity(self):
     self.vis = create_visibility(self.lowcore, self.times, self.frequency,
                                  channel_bandwidth=self.channel_bandwidth,
                                  phasecentre=self.phasecentre, weight=1.0,
                                  polarisation_frame=PolarisationFrame("stokesIQUV"))
     self.vismodel = predict_skycomponent_visibility(self.vis, self.comp)
     newphasecenters = [SkyCoord(182, -35, unit=u.deg), SkyCoord(182, -30, unit=u.deg),
                        SkyCoord(177, -30, unit=u.deg), SkyCoord(176, -35, unit=u.deg),
                        SkyCoord(216, -35, unit=u.deg), SkyCoord(180, -70, unit=u.deg)]
     for newphasecentre in newphasecenters:
         # Phase rotating back should not make a difference
         original_vis = self.vismodel.vis
         original_uvw = self.vismodel.uvw
         rotatedvis = phaserotate_visibility(phaserotate_visibility(self.vismodel, newphasecentre, tangent=False),
                                             self.phasecentre, tangent=False)
         assert_allclose(rotatedvis.uvw, original_uvw, rtol=1e-7)
         assert_allclose(rotatedvis.vis, original_vis, rtol=1e-7)
Example #13
0
    def test_fit_visibility(self):
        # Sum the visibilities in the correct_visibility direction. This is limited by numerical precision
        methods = ['CG', 'BFGS', 'Powell', 'trust-ncg', 'trust-exact', 'trust-krylov']
        for method in methods:
            self.actualSetup()
            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.vismodel = predict_skycomponent_visibility(self.vis, self.comp)
            initial_comp = Skycomponent(direction=self.comp_start_direction, frequency=self.frequency,
                                        flux=2.0 * self.flux, polarisation_frame=PolarisationFrame("stokesI"))
    
            sc, res = fit_visibility(self.vismodel, initial_comp, niter=200, tol=1e-5, method=method, verbose=False)
#            print(method, res)
            assert sc.direction.separation(self.comp_actual_direction).to('rad').value < 1e-6, \
                sc.direction.separation(self.comp_actual_direction).to('rad')
Example #14
0
 def createVis(self, config='MID', dec=-35.0, rmax=1e3, freq=1e9):
     self.frequency = numpy.linspace(freq, 1.5*freq, 3)
     self.channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7])
     self.flux = numpy.array([[100.0], [100.0], [100.0]])
     self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000')
     self.config = create_named_configuration(config)
     self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
     nants = self.config.xyz.shape[0]
     assert nants > 1
     assert len(self.config.names) == nants
     assert len(self.config.mount) == nants
 
     self.config = create_named_configuration(config, rmax=rmax)
     self.phasecentre = SkyCoord(ra=+15 * u.deg, dec=dec * u.deg, frame='icrs', equinox='J2000')
     self.vis = create_visibility(self.config, self.times, self.frequency,
                                  channel_bandwidth=self.channel_bandwidth,
                                  phasecentre=self.phasecentre, weight=1.0,
                                  polarisation_frame=PolarisationFrame('stokesI'))
Example #15
0
    def setUp(self):

        self.lowcore = create_named_configuration('LOWBD2', rmax=1000.0)

        self.times = numpy.linspace(-300.0, 300.0, 11) * numpy.pi / 43200.0

        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e8])
        self.phasecentre = SkyCoord(ra=+15.0 * u.deg,
                                    dec=-35.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)
 def test_readwritevisibility(self):
     self.vis = create_visibility(self.lowcore, self.times, self.frequency,
                                  channel_bandwidth=self.channel_bandwidth,
                                  phasecentre=self.phasecentre,
                                  polarisation_frame=PolarisationFrame("linear"),
                                  weight=1.0)
     self.vis = predict_skycomponent_visibility(self.vis, self.comp)
     export_visibility_to_hdf5(self.vis, '%s/test_data_model_helpers_visibility.hdf' % self.dir)
     newvis = import_visibility_from_hdf5('%s/test_data_model_helpers_visibility.hdf' % self.dir)
     
     assert str(newvis) == str(self.vis), "Original %s, import %s" % (str(newvis), str(self.vis))
     assert numpy.array_equal(newvis.frequency, self.vis.frequency)
     assert newvis.data.shape == self.vis.data.shape
     assert numpy.array_equal(newvis.frequency, self.vis.frequency)
     assert numpy.max(numpy.abs(self.vis.vis - newvis.vis)) < 1e-15
     assert numpy.max(numpy.abs(self.vis.uvw - newvis.uvw)) < 1e-15
     assert numpy.abs(newvis.configuration.location.x.value - self.vis.configuration.location.x.value) < 1e-15
     assert numpy.abs(newvis.configuration.location.y.value - self.vis.configuration.location.y.value) < 1e-15
     assert numpy.abs(newvis.configuration.location.z.value - self.vis.configuration.location.z.value) < 1e-15
     assert numpy.max(numpy.abs(newvis.configuration.xyz - self.vis.configuration.xyz)) < 1e-15
    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)
        window = numpy.zeros(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'))
Example #18
0
    def setUp(self):
        from data_models.parameters import arl_path
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.dir = arl_path('test_results')
        self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7)
        self.image_frequency = numpy.linspace(0.9e8, 1.1e8, 5)
        self.component_frequency = numpy.linspace(0.8e8, 1.2e8, 7)
        self.channel_bandwidth = numpy.array(5 * [1e7])
        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.image_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.model = create_test_image(cellsize=0.0015,
                                       phasecentre=self.vis.phasecentre,
                                       frequency=self.image_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

        dphasecentre = SkyCoord(ra=+181.0 * u.deg,
                                dec=-58.0 * u.deg,
                                frame='icrs',
                                equinox='J2000')
        flux = [[numpy.power(f / 1e8, -0.7)] for f in self.component_frequency]
        self.sc = create_skycomponent(
            direction=dphasecentre,
            flux=flux,
            frequency=self.component_frequency,
            polarisation_frame=PolarisationFrame('stokesI'))
    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))
 def setUp(self):
     from data_models.parameters import arl_path
     self.dir = arl_path('test_results')
     self.persist = False
     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)
     if self.persist: export_image_to_fits(beam, "%s/test_deconvolve_mmclean_beam.fits" % self.dir)
     self.test_model.data *= beam.data
     if self.persist: 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)
     if self.persist: export_image_to_fits(self.dirty, "%s/test_deconvolve_mmclean-dirty.fits" % self.dir)
     if self.persist: 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'))
    def ingest_visibility(self,
                          freq=None,
                          chan_width=None,
                          times=None,
                          add_errors=False,
                          block=True,
                          bandpass=False):
        if freq is None:
            freq = [1e8]
        if chan_width is None:
            chan_width = [1e6]
        if times is None:
            times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5)

        lowcore = create_named_configuration('LOWBD2', rmax=750.0)
        frequency = numpy.array(freq)
        channel_bandwidth = numpy.array(chan_width)

        phasecentre = SkyCoord(ra=+180.0 * u.deg,
                               dec=-60.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')
        if block:
            vt = create_blockvisibility(
                lowcore,
                times,
                frequency,
                channel_bandwidth=channel_bandwidth,
                weight=1.0,
                phasecentre=phasecentre,
                polarisation_frame=PolarisationFrame("stokesI"))
        else:
            vt = create_visibility(
                lowcore,
                times,
                frequency,
                channel_bandwidth=channel_bandwidth,
                weight=1.0,
                phasecentre=phasecentre,
                polarisation_frame=PolarisationFrame("stokesI"))
        cellsize = 0.001
        model = create_image_from_visibility(
            vt,
            npixel=self.npixel,
            cellsize=cellsize,
            npol=1,
            frequency=frequency,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"))
        nchan = len(self.frequency)
        flux = numpy.array(nchan * [[100.0]])
        facets = 4

        rpix = model.wcs.wcs.crpix - 1.0
        spacing_pixels = self.npixel // facets
        centers = [-1.5, -0.5, 0.5, 1.5]
        comps = list()
        for iy in centers:
            for ix in centers:
                p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[0]))), \
                    int(round(rpix[1] + iy * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[1])))
                sc = pixel_to_skycoord(p[0], p[1], model.wcs, origin=1)
                comp = create_skycomponent(
                    direction=sc,
                    flux=flux,
                    frequency=frequency,
                    polarisation_frame=PolarisationFrame("stokesI"))
                comps.append(comp)
        if block:
            predict_skycomponent_visibility(vt, comps)
        else:
            predict_skycomponent_visibility(vt, comps)
        insert_skycomponent(model, comps)
        self.comps = comps
        self.model = copy_image(model)
        self.empty_model = create_empty_image_like(model)
        export_image_to_fits(
            model, '%s/test_pipeline_functions_model.fits' % (self.dir))

        if add_errors:
            # These will be the same for all calls
            numpy.random.seed(180555)
            gt = create_gaintable_from_blockvisibility(vt)
            gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.0)
            vt = apply_gaintable(vt, gt)

            if bandpass:
                bgt = create_gaintable_from_blockvisibility(vt, timeslice=1e5)
                bgt = simulate_gaintable(bgt,
                                         phase_error=0.01,
                                         amplitude_error=0.01,
                                         smooth_channels=4)
                vt = apply_gaintable(vt, bgt)

        return vt
 def test_create_visibility_time(self):
     self.vis = create_visibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre,
                                       weight=1.0, channel_bandwidth=self.channel_bandwidth)
     assert self.vis.nvis == len(self.vis.time)