def test_readwriteblockvisibility(self):
        self.vis = create_blockvisibility(
            self.mid,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            polarisation_frame=PolarisationFrame("linear"),
            weight=1.0)
        self.vis = dft_skycomponent_visibility(self.vis, self.comp)
        export_blockvisibility_to_hdf5(
            self.vis,
            '%s/test_data_model_helpers_blockvisibility.hdf' % self.dir)
        newvis = import_blockvisibility_from_hdf5(
            '%s/test_data_model_helpers_blockvisibility.hdf' % self.dir)

        for key in self.vis.data.dtype.fields:
            assert numpy.max(
                numpy.abs(newvis.data[key] - self.vis.data[key])) < 1e-15

        assert numpy.array_equal(newvis.frequency, self.vis.frequency)
        assert newvis.data.shape == self.vis.data.shape
        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 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 = dft_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)
            assert sc.direction.separation(self.comp_actual_direction).to('rad').value < 1e-6, \
                sc.direction.separation(self.comp_actual_direction).to('rad')
Ejemplo n.º 3
0
    def ft_ift_sm(ov, sm, g):
        assert isinstance(ov, Visibility) or isinstance(ov,
                                                        BlockVisibility), ov
        assert isinstance(sm, SkyModel), sm
        if g is not None:
            assert len(g) == 2, g
            assert isinstance(g[0], Image), g[0]
            assert isinstance(g[1], ConvolutionFunction), g[1]

        v = copy_visibility(ov)

        v.data['vis'][...] = 0.0 + 0.0j

        if len(sm.components) > 0:

            if isinstance(sm.mask, Image):
                comps = copy_skycomponent(sm.components)
                comps = apply_beam_to_skycomponent(comps, sm.mask)
                v = dft_skycomponent_visibility(v, comps)
            else:
                v = dft_skycomponent_visibility(v, sm.components)

        if isinstance(sm.image, Image):
            if numpy.max(numpy.abs(sm.image.data)) > 0.0:
                if isinstance(sm.mask, Image):
                    model = copy_image(sm.image)
                    model.data *= sm.mask.data
                else:
                    model = sm.image
                v = predict_list_serial_workflow([v], [model],
                                                 context=context,
                                                 vis_slices=vis_slices,
                                                 facets=facets,
                                                 gcfcf=[g],
                                                 **kwargs)[0]

        assert isinstance(sm.image, Image), sm.image

        result = invert_list_serial_workflow([v], [sm.image],
                                             context=context,
                                             vis_slices=vis_slices,
                                             facets=facets,
                                             gcfcf=[g],
                                             **kwargs)[0]
        if isinstance(sm.mask, Image):
            result[0].data *= sm.mask.data
        return result
    def test_phase_rotation_block(self):
        self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency,
                                          channel_bandwidth=self.channel_bandwidth,
                                          phasecentre=self.phasecentre, weight=1.0,
                                          polarisation_frame=PolarisationFrame("stokesIQUV"))
        self.vismodel = dft_skycomponent_visibility(self.vis, self.comp)
        # Predict visibilities with new phase centre independently
        ha_diff = -(self.compabsdirection.ra - self.phasecentre.ra).to(u.rad).value
        vispred = create_blockvisibility(self.lowcore, self.times + ha_diff, self.frequency,
                                         channel_bandwidth=self.channel_bandwidth,
                                         phasecentre=self.compabsdirection, weight=1.0,
                                         polarisation_frame=PolarisationFrame("stokesIQUV"))
        vismodel2 = dft_skycomponent_visibility(vispred, self.comp)

        # Should yield the same results as rotation
        rotatedvis = phaserotate_visibility(self.vismodel, newphasecentre=self.compabsdirection, tangent=False)
        assert_allclose(rotatedvis.vis, vismodel2.vis, rtol=3e-6)
        assert_allclose(rotatedvis.uvw, vismodel2.uvw, rtol=3e-6)
Ejemplo n.º 5
0
    def ft_cal_sm(obv, sm):
        assert isinstance(obv, BlockVisibility), obv
        bv = copy_visibility(obv)

        bv.data['vis'][...] = 0.0 + 0.0j

        assert len(sm.components) > 0

        if isinstance(sm.mask, Image):
            comps = copy_skycomponent(sm.components)
            comps = apply_beam_to_skycomponent(comps, sm.mask)
            bv = dft_skycomponent_visibility(bv, comps)
        else:
            bv = dft_skycomponent_visibility(bv, sm.components)

        if docal and isinstance(sm.gaintable, GainTable):
            bv = apply_gaintable(bv, sm.gaintable, inverse=True)

        return bv
 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 = dft_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'
    def ft_cal_sm(ov, sm, g):
        assert isinstance(ov, Visibility), ov
        assert isinstance(sm, SkyModel), sm
        if g is not None:
            assert len(g) == 2, g
            assert isinstance(g[0], Image), g[0]
            assert isinstance(g[1], ConvolutionFunction), g[1]

        v = copy_visibility(ov)

        v.data['vis'][...] = 0.0 + 0.0j

        if len(sm.components) > 0:

            if isinstance(sm.mask, Image):
                comps = copy_skycomponent(sm.components)
                comps = apply_beam_to_skycomponent(comps, sm.mask)
                v = dft_skycomponent_visibility(v, comps)
            else:
                v = dft_skycomponent_visibility(v, sm.components)

        if isinstance(sm.image, Image):
            if numpy.max(numpy.abs(sm.image.data)) > 0.0:
                if isinstance(sm.mask, Image):
                    model = copy_image(sm.image)
                    model.data *= sm.mask.data
                else:
                    model = sm.image
                v = predict_list_serial_workflow([v], [model],
                                                 context=context,
                                                 vis_slices=vis_slices,
                                                 facets=facets,
                                                 gcfcf=[g],
                                                 **kwargs)[0]

        if docal and isinstance(sm.gaintable, GainTable):
            bv = convert_visibility_to_blockvisibility(v)
            bv = apply_gaintable(bv, sm.gaintable, inverse=True)
            v = convert_blockvisibility_to_visibility(bv)

        return v
Ejemplo n.º 8
0
    def actualSetUp(self, freqwin=1, block=True, dopol=False):

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

        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 freqwin > 1:
            self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
            self.channelwidth = numpy.array(
                freqwin * [self.frequency[1] - self.frequency[0]])
            flux = numpy.array(
                [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
        else:
            self.frequency = numpy.array([1e8])
            self.channelwidth = numpy.array([1e6])
            flux = numpy.array([f])

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.bvis = ingest_unittest_visibility(self.low,
                                               self.frequency,
                                               self.channelwidth,
                                               self.times,
                                               self.vis_pol,
                                               self.phasecentre,
                                               block=block)

        self.vis = convert_blockvisibility_to_visibility(self.bvis)

        self.model = create_unittest_model(self.vis,
                                           self.image_pol,
                                           npixel=self.npixel,
                                           nchan=freqwin)

        self.components = create_unittest_components(self.model, flux)

        self.model = insert_skycomponent(self.model, self.components)

        self.bvis = dft_skycomponent_visibility(self.bvis, self.components)
 def test_phase_rotation_inverse_block(self):
     self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency,
                                       channel_bandwidth=self.channel_bandwidth,
                                       phasecentre=self.phasecentre, weight=1.0,
                                       polarisation_frame=PolarisationFrame("stokesIQUV"))
     self.vismodel = dft_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)
Ejemplo n.º 10
0
    def actualSetup(self,
                    sky_pol_frame='stokesIQUV',
                    data_pol_frame='linear',
                    f=None,
                    vnchan=1):
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / 43200.0) * numpy.linspace(0.0, 30.0, 3)
        self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan)
        if vnchan > 1:
            self.channel_bandwidth = numpy.array(
                vnchan * [self.frequency[1] - self.frequency[0]])
        else:
            self.channel_bandwidth = numpy.array([2e7])

        if f is None:
            f = [100.0, 50.0, -10.0, 40.0]

        if sky_pol_frame == 'stokesI':
            f = [100.0]

        self.flux = numpy.outer(
            numpy.array(
                [numpy.power(freq / 1e8, -0.7) for freq in self.frequency]), f)

        # The phase centre is absolute and the component is specified relative (for now).
        # This means that the component should end up at the position phasecentre+compredirection
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-35.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.compabsdirection = SkyCoord(ra=+181.0 * u.deg,
                                         dec=-35.0 * u.deg,
                                         frame='icrs',
                                         equinox='J2000')
        self.comp = Skycomponent(
            direction=self.compabsdirection,
            frequency=self.frequency,
            flux=self.flux,
            polarisation_frame=PolarisationFrame(sky_pol_frame))
        self.vis = create_blockvisibility(
            self.lowcore,
            self.times,
            self.frequency,
            phasecentre=self.phasecentre,
            channel_bandwidth=self.channel_bandwidth,
            weight=1.0,
            polarisation_frame=PolarisationFrame(data_pol_frame))
        self.vis = dft_skycomponent_visibility(self.vis, self.comp)
Ejemplo n.º 11
0
    def test_insert_skycomponent_dft(self):
        self.actualSetup()

        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 = dft_skycomponent_visibility(self.vis, self.sc)
        im, sumwt = invert_2d(self.vis, self.model)
        if self.persist:
            export_image_to_fits(im,
                                 '%s/test_skycomponent_dft.fits' % self.dir)
        assert numpy.max(numpy.abs(self.vis.vis.imag)) < 1e-3
 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 = dft_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)
    def test_readwriteblockvisibility(self):
        self.vis = create_blockvisibility(
            self.midcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            polarisation_frame=PolarisationFrame("linear"),
            weight=1.0,
            meta={"RASCIL": 0.0})
        self.vis = dft_skycomponent_visibility(self.vis, self.comp)

        config = {
            "buffer": {
                "directory": self.dir
            },
            "vislist": {
                "name": "test_bufferblockvisibility.hdf",
                "data_model": "BlockVisibility"
            }
        }
        bdm = BufferBlockVisibility(config["buffer"], config["vislist"],
                                    self.vis)
        bdm.sync()
        new_bdm = BufferBlockVisibility(config["buffer"], config["vislist"])
        new_bdm.sync()
        newvis = bdm.memory_data_model

        assert isinstance(newvis, BlockVisibility)
        assert numpy.array_equal(newvis.frequency, self.vis.frequency)
        assert newvis.data.shape == self.vis.data.shape
        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
        assert newvis.meta == self.vis.meta
Ejemplo n.º 14
0
def rcal(vis: BlockVisibility, components, **kwargs) -> GainTable:
    """ Real-time calibration pipeline.

    Reads visibilities through a BlockVisibility iterator, calculates model visibilities according to a
    component-based sky model, and performs calibration solution, writing a gaintable for each chunk of
    visibilities.

    :param vis: Visibility or Union(Visibility, Iterable)
    :param components: Component-based sky model
    :param kwargs: Parameters
    :return: gaintable
   """

    if not isinstance(vis, collections.abc.Iterable):
        vis = [vis]

    for ichunk, vischunk in enumerate(vis):
        vispred = copy_visibility(vischunk, zero=True)
        vispred = dft_skycomponent_visibility(vispred, components)
        gt = solve_gaintable(vischunk, vispred, **kwargs)
        yield gt
    def test_zero_list(self):
        self.actualSetUp()

        centre = self.freqwin // 2
        vis_list = zero_list_serial_workflow(self.bvis_list)

        assert numpy.max(numpy.abs(vis_list[centre].vis)) < 1e-15, numpy.max(
            numpy.abs(vis_list[centre].vis))

        predicted_vis_list = [
            dft_skycomponent_visibility(vis_list[freqwin],
                                        self.components_list[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]
        assert numpy.max(numpy.abs(predicted_vis_list[centre].vis)) > 0.0, \
            numpy.max(numpy.abs(predicted_vis_list[centre].vis))

        diff_vis_list = subtract_list_serial_workflow(self.bvis_list,
                                                      predicted_vis_list)

        assert numpy.max(numpy.abs(
            diff_vis_list[centre].vis)) < 1e-15, numpy.max(
                numpy.abs(diff_vis_list[centre].vis))
Ejemplo n.º 16
0
 def test_predict_sky_components_coalesce(self):
     sc = create_low_test_skycomponents_from_gleam(
         flux_limit=10.0,
         polarisation_frame=PolarisationFrame("stokesI"),
         frequency=self.frequency,
         kind='cubic',
         phasecentre=SkyCoord("17h20m31s", "-00d58m45s"),
         radius=0.1)
     self.config = create_named_configuration('LOWBD2-CORE')
     self.phasecentre = SkyCoord("17h20m31s", "-00d58m45s")
     sampling_time = 3.76
     self.times = numpy.arange(0.0, +300 * sampling_time, sampling_time)
     self.vis = create_blockvisibility(
         self.config,
         self.times,
         self.frequency,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=PolarisationFrame('stokesI'),
         channel_bandwidth=self.channel_bandwidth)
     self.vis = dft_skycomponent_visibility(self.vis, sc)
     cvt = convert_blockvisibility_to_visibility(self.vis)
     assert cvt.cindex is not None
Ejemplo n.º 17
0
    def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear'):
        self.lowcore = create_named_configuration('LOWBD2', rmax=100.0)
        self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 3000.0, 60.0)
        vnchan = 3
        self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan)
        self.channel_bandwidth = numpy.array(
            vnchan * [self.frequency[1] - self.frequency[0]])

        # Define the component and give it some spectral behaviour
        f = numpy.array([100.0, 20.0, -10.0, 1.0])
        self.flux = numpy.array([f, 0.8 * f, 0.6 * f])

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-35.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.compabsdirection = SkyCoord(ra=+181.0 * u.deg,
                                         dec=-35.0 * u.deg,
                                         frame='icrs',
                                         equinox='J2000')
        if sky_pol_frame == 'stokesI':
            self.flux = self.flux[:, 0][:, numpy.newaxis]

        self.comp = Skycomponent(
            direction=self.compabsdirection,
            frequency=self.frequency,
            flux=self.flux,
            polarisation_frame=PolarisationFrame(sky_pol_frame))
        self.vis = create_blockvisibility(
            self.lowcore,
            self.times,
            self.frequency,
            phasecentre=self.phasecentre,
            channel_bandwidth=self.channel_bandwidth,
            weight=1.0,
            polarisation_frame=PolarisationFrame(data_pol_frame))
        self.vis = dft_skycomponent_visibility(self.vis, self.comp)
    def actualSetUp(self,
                    add_errors=False,
                    freqwin=3,
                    block=True,
                    dospectral=True,
                    dopol=False,
                    zerow=False,
                    makegcfcf=False):

        self.npixel = 256
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        self.bvis_list = list()
        self.ntimes = 5
        self.cellsize = 0.0005
        # Choose the interval so that the maximum change in w is smallish
        integration_time = numpy.pi * (24 / (12 * 60))
        self.times = numpy.linspace(-integration_time * (self.ntimes // 2),
                                    integration_time * (self.ntimes // 2),
                                    self.ntimes)

        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([1.0e8])
            self.channelwidth = numpy.array([4e7])

        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.bvis_list = [
            ingest_unittest_visibility(
                self.low,
                numpy.array([self.frequency[freqwin]]),
                numpy.array([self.channelwidth[freqwin]]),
                self.times,
                self.vis_pol,
                self.phasecentre,
                block=block,
                zerow=zerow) for freqwin, _ in enumerate(self.frequency)
        ]

        self.model_list = [
            create_unittest_model(self.bvis_list[freqwin],
                                  self.image_pol,
                                  cellsize=self.cellsize,
                                  npixel=self.npixel)
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.components_list = [
            create_unittest_components(self.model_list[freqwin],
                                       flux[freqwin, :][numpy.newaxis, :],
                                       single=False)
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.model_list = [
            insert_skycomponent(self.model_list[freqwin],
                                self.components_list[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.bvis_list = [
            dft_skycomponent_visibility(self.bvis_list[freqwin],
                                        self.components_list[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]
        centre = self.freqwin // 2
        # Calculate the model convolved with a Gaussian.
        self.model = self.model_list[centre]

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

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

        self.components = self.components_list[centre]

        if makegcfcf:
            self.gcfcf = [
                create_awterm_convolutionfunction(self.model,
                                                  nw=61,
                                                  wstep=16.0,
                                                  oversampling=8,
                                                  support=64,
                                                  use_aaf=True)
            ]
            self.gcfcf_clipped = [
                (self.gcfcf[0][0],
                 apply_bounding_box_convolutionfunction(self.gcfcf[0][1],
                                                        fractional_level=1e-3))
            ]

            self.gcfcf_joint = [
                create_awterm_convolutionfunction(self.model,
                                                  nw=11,
                                                  wstep=16.0,
                                                  oversampling=8,
                                                  support=64,
                                                  use_aaf=True)
            ]

        else:
            self.gcfcf = None
            self.gcfcf_clipped = None
            self.gcfcf_joint = None
Ejemplo n.º 19
0
    def actualSetUp(self,
                    add_errors=False,
                    freqwin=7,
                    block=False,
                    dospectral=True,
                    dopol=False,
                    zerow=True):

        self.npixel = 256
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        self.vis_list = list()
        self.ntimes = 5
        cellsize = 0.001
        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 = [
            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_imagelist = [
            create_unittest_model(self.vis_list[freqwin],
                                  self.image_pol,
                                  cellsize=cellsize,
                                  npixel=self.npixel)
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.componentlist = [
            create_unittest_components(self.model_imagelist[freqwin],
                                       flux[freqwin, :][numpy.newaxis, :])
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.model_imagelist = [
            insert_skycomponent(self.model_imagelist[freqwin],
                                self.componentlist[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        self.vis_list = [
            dft_skycomponent_visibility(self.vis_list[freqwin],
                                        self.componentlist[freqwin])
            for freqwin, _ in enumerate(self.frequency)
        ]

        # Calculate the model convolved with a Gaussian.

        model = self.model_imagelist[0]

        self.cmodel = smooth_image(model)
        if self.persist:
            export_image_to_fits(
                model,
                '%s/test_imaging_serial_deconvolved_model.fits' % self.dir)
        if self.persist:
            export_image_to_fits(
                self.cmodel,
                '%s/test_imaging_serial_deconvolved_cmodel.fits' % self.dir)

        if add_errors and block:
            self.vis_list = [
                insert_unittest_errors(self.vis_list[i])
                for i, _ in enumerate(self.frequency)
            ]
Ejemplo n.º 20
0
    def actualSetUp(self,
                    zerow=True,
                    block=False,
                    image_pol=PolarisationFrame("stokesIQUV")):
        self.doplot = False
        self.npixel = 256
        self.cellsize = 0.0009
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = 1
        self.vis_list = list()
        self.ntimes = 3
        self.times = numpy.linspace(-2.0, +2.0, self.ntimes) * numpy.pi / 12.0

        if self.freqwin == 1:
            self.frequency = numpy.array([1e8])
            self.channelwidth = numpy.array([4e7])
        else:
            self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
            self.channelwidth = numpy.array(
                self.freqwin * [self.frequency[1] - self.frequency[0]])

        self.image_pol = image_pol
        if image_pol == PolarisationFrame("stokesI"):
            self.vis_pol = PolarisationFrame("stokesI")
            f = numpy.array([100.0])
        elif image_pol == PolarisationFrame("stokesIQUV"):
            self.vis_pol = PolarisationFrame("linear")
            f = numpy.array([100.0, 20.0, -10.0, 1.0])
        elif image_pol == PolarisationFrame("stokesIQ"):
            self.vis_pol = PolarisationFrame("linearnp")
            f = numpy.array([100.0, 20.0])
        elif image_pol == PolarisationFrame("stokesIV"):
            self.vis_pol = PolarisationFrame("circularnp")
            f = numpy.array([100.0, 20.0])
        else:
            raise ValueError("Polarisation {} not supported".format(image_pol))

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

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = ingest_unittest_visibility(self.low,
                                              self.frequency,
                                              self.channelwidth,
                                              self.times,
                                              self.vis_pol,
                                              self.phasecentre,
                                              block=block,
                                              zerow=zerow)

        self.model = create_unittest_model(self.vis,
                                           self.image_pol,
                                           cellsize=self.cellsize,
                                           npixel=self.npixel,
                                           nchan=self.freqwin)
        self.components = create_unittest_components(self.model,
                                                     flux,
                                                     applypb=False,
                                                     scale=0.5,
                                                     single=False,
                                                     symmetric=True)
        self.model = insert_skycomponent(self.model, self.components)

        self.vis = dft_skycomponent_visibility(self.vis, self.components)

        # Calculate the model convolved with a Gaussian.
        self.cmodel = smooth_image(self.model)
        if self.persist:
            export_image_to_fits(self.model,
                                 '%s/test_gridding_model.fits' % self.dir)
            export_image_to_fits(self.cmodel,
                                 '%s/test_gridding_cmodel.fits' % self.dir)
        pb = create_pb_generic(self.model,
                               diameter=35.0,
                               blockage=0.0,
                               use_local=False)
        self.cmodel.data *= pb.data
        if self.persist:
            export_image_to_fits(self.cmodel,
                                 '%s/test_gridding_cmodel_pb.fits' % self.dir)
        self.peak = numpy.unravel_index(
            numpy.argmax(numpy.abs(self.cmodel.data)), self.cmodel.shape)
    def actualSetUp(self,
                    freqwin=1,
                    block=True,
                    dospectral=True,
                    image_pol=PolarisationFrame('stokesI'),
                    zerow=False,
                    mfs=False):

        self.npixel = 512
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        self.blockvis = 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([1e8])
            self.channelwidth = numpy.array([1e6])

        if image_pol == PolarisationFrame('stokesIQUV'):
            self.blockvis_pol = PolarisationFrame('linear')
            self.image_pol = image_pol
            f = numpy.array([100.0, 20.0, -10.0, 1.0])
        elif image_pol == PolarisationFrame('stokesIQ'):
            self.blockvis_pol = PolarisationFrame('linearnp')
            self.image_pol = image_pol
            f = numpy.array([100.0, 20.0])
        elif image_pol == PolarisationFrame('stokesIV'):
            self.blockvis_pol = PolarisationFrame('circularnp')
            self.image_pol = image_pol
            f = numpy.array([100.0, 20.0])
        else:
            self.blockvis_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=-45.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.blockvis = ingest_unittest_visibility(self.low,
                                                   self.frequency,
                                                   self.channelwidth,
                                                   self.times,
                                                   self.blockvis_pol,
                                                   self.phasecentre,
                                                   block=block,
                                                   zerow=zerow)

        self.model = create_unittest_model(self.blockvis,
                                           self.image_pol,
                                           npixel=self.npixel,
                                           nchan=freqwin)

        self.components = create_unittest_components(self.model, flux)

        self.model = insert_skycomponent(self.model, self.components)

        self.blockvis = dft_skycomponent_visibility(self.blockvis,
                                                    self.components)

        # Calculate the model convolved with a Gaussian.

        self.cmodel = smooth_image(self.model)
        if self.persist:
            export_image_to_fits(self.model,
                                 '%s/test_imaging_ng_model.fits' % self.dir)
        if self.persist:
            export_image_to_fits(self.cmodel,
                                 '%s/test_imaging_ng_cmodel.fits' % self.dir)

        if mfs:
            self.model = create_unittest_model(self.blockvis,
                                               self.image_pol,
                                               npixel=self.npixel,
                                               nchan=1)
Ejemplo n.º 22
0
    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:
            dft_skycomponent_visibility(vt, comps)
        else:
            dft_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 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, 0.0, 0.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 = [ingest_unittest_visibility(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.vis_list = [convert_blockvisibility_to_visibility(bv) for bv in self.blockvis_list]
     
     self.model_imagelist = [
         create_unittest_model(self.vis_list[i], self.image_pol, npixel=self.npixel, cellsize=0.0005)
         for i in range(nfreqwin)]
     
     self.components_list = [create_unittest_components(self.model_imagelist[freqwin],
                                                        flux[freqwin, :][numpy.newaxis, :])
                             for freqwin, m in enumerate(self.model_imagelist)]
     
     self.blockvis_list = [
         dft_skycomponent_visibility(self.blockvis_list[freqwin], self.components_list[freqwin])
         for freqwin, _ in enumerate(self.blockvis_list)]
     
     self.model_imagelist = [insert_skycomponent(self.model_imagelist[freqwin], self.components_list[freqwin])
                             for freqwin in range(nfreqwin)]
     model = self.model_imagelist[0]
     self.cmodel = smooth_image(model)
     if self.persist:
         export_image_to_fits(model, '%s/test_imaging_serial_model.fits' % self.dir)
         export_image_to_fits(self.cmodel, '%s/test_imaging_serial_cmodel.fits' % self.dir)
     
     if add_errors:
         gt = create_gaintable_from_blockvisibility(self.blockvis_list[0])
         gt = simulate_gaintable(gt, phase_error=0.1, amplitude_error=0.0, smooth_channels=1, leakage=0.0)
         self.blockvis_list = [apply_gaintable(self.blockvis_list[i], gt)
                               for i in range(self.freqwin)]
     
     self.vis_list = [convert_blockvisibility_to_visibility(bv) for bv in self.blockvis_list]
     
     self.model_imagelist = [
         create_unittest_model(self.vis_list[i], self.image_pol, npixel=self.npixel, cellsize=0.0005)
         for i in range(nfreqwin)]
Ejemplo n.º 24
0
def create_blockvisibility_iterator(
        config: Configuration,
        times: numpy.array,
        frequency: numpy.array,
        channel_bandwidth,
        phasecentre: SkyCoord,
        weight: float = 1,
        polarisation_frame=PolarisationFrame('stokesI'),
        integration_time=1.0,
        number_integrations=1,
        predict=predict_2d,
        model=None,
        components=None,
        phase_error=0.0,
        amplitude_error=0.0,
        sleep=0.0,
        **kwargs):
    """ Create a sequence of Visibilities and optionally predicting and coalescing

    This is useful mainly for performing large simulations. Do something like::
    
        vis_iter = create_blockvisibility_iterator(config, times, frequency, channel_bandwidth, phasecentre=phasecentre,
                                              weight=1.0, integration_time=30.0, number_integrations=3)

        for i, vis in enumerate(vis_iter):
        if i == 0:
            fullvis = vis
        else:
            fullvis = append_visibility(fullvis, vis)


    :param config: Configuration of antennas
    :param times: hour angles in radians
    :param frequency: frequencies (Hz] Shape [nchan]
    :param weight: weight of a single sample
    :param phasecentre: phasecentre of observation
    :param npol: Number of polarizations
    :param integration_time: Integration time ('auto' or value in s)
    :param number_integrations: Number of integrations to be created at each time.
    :param model: Model image to be inserted
    :param components: Components to be inserted
    :param sleep_time: Time to sleep between yields
    :return: Visibility

    """
    for time in times:
        actualtimes = time + numpy.arange(
            0, number_integrations) * integration_time * numpy.pi / 43200.0
        bvis = create_blockvisibility(config,
                                      actualtimes,
                                      frequency=frequency,
                                      phasecentre=phasecentre,
                                      weight=weight,
                                      polarisation_frame=polarisation_frame,
                                      integration_time=integration_time,
                                      channel_bandwidth=channel_bandwidth)

        if model is not None:
            vis = convert_blockvisibility_to_visibility(bvis)
            vis = predict(vis, model, **kwargs)
            bvis = convert_visibility_to_blockvisibility(vis)

        if components is not None:
            vis = dft_skycomponent_visibility(bvis, components)

        # Add phase errors
        if phase_error > 0.0 or amplitude_error > 0.0:
            gt = create_gaintable_from_blockvisibility(bvis)
            gt = simulate_gaintable(gt=gt,
                                    phase_error=phase_error,
                                    amplitude_error=amplitude_error)
            bvis = apply_gaintable(bvis, gt)

        import time
        time.sleep(sleep)

        yield bvis