Exemplo n.º 1
0
    def setUp(self):

        self.lowcore = create_named_configuration('LOWBD2-CORE')

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

        self.frequency = numpy.linspace(1e8, 1.5e9, 7)

        self.channel_bandwidth = numpy.array(
            7 * [self.frequency[1] - self.frequency[0]])

        self.phasecentre = SkyCoord(ra=+15.0 * u.deg,
                                    dec=-35.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
Exemplo n.º 2
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)
    def setUp(self):
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 30.0)
        self.frequency = numpy.linspace(1.0e8, 1.1e8, 3)
        self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7])
        # 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])

        # 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')
        pcof = self.phasecentre.skyoffset_frame()
        self.compreldirection = self.compabsdirection.transform_to(pcof)
        self.comp = Skycomponent(direction=self.compreldirection, frequency=self.frequency, flux=self.flux)
Exemplo n.º 4
0
    def test_rfi(self):
        sample_freq = 3e4
        nchannels = 1000
        frequency = 170.5e6 + numpy.arange(nchannels) * sample_freq

        ntimes = 100
        integration_time = 0.5
        times = numpy.arange(ntimes) * integration_time

        # Perth from Google for the moment
        perth = EarthLocation(lon="115.8605", lat="-31.9505", height=0.0)

        rmax = 1000.0
        low = create_named_configuration('LOWR3', rmax=rmax)
        antskip = 33
        low.data = low.data[::antskip]
        nants = len(low.names)

        # Calculate the power spectral density of the DTV station: Watts/Hz
        emitter = simulate_DTV(frequency,
                               times,
                               power=50e3,
                               timevariable=False)
        numpy.testing.assert_almost_equal(numpy.max(numpy.abs(emitter)),
                                          0.00166834)
        assert emitter.shape == (ntimes, nchannels)

        # Calculate the propagators for signals from Perth to the stations in low
        # These are fixed in time but vary with frequency. The ad hoc attenuation
        # is set to produce signal roughly equal to noise at LOW
        attenuation = 1.0
        propagators = create_propagators(low,
                                         perth,
                                         frequency=frequency,
                                         attenuation=attenuation)
        assert propagators.shape == (nants, nchannels), propagators.shape

        # Now calculate the RFI at the stations, based on the emitter and the propagators
        rfi_at_station = calculate_rfi_at_station(propagators, emitter)
        assert rfi_at_station.shape == (ntimes, nants,
                                        nchannels), rfi_at_station.shape

        # Calculate the rfi correlation
        # [nants, nants, ntimes, nchan]
        correlation = calculate_station_correlation_rfi(rfi_at_station)
        assert correlation.shape == (ntimes, nants, nants, nchannels,
                                     1), correlation.shape
Exemplo n.º 5
0
 def createVis(self, config='MID', dec=-35.0, rmax=1e2, freq=1.3e9):
     self.frequency = numpy.array([freq])
     self.channel_bandwidth = numpy.array([1e6])
     self.flux = numpy.array([[100.0, 60.0, -10.0, +1.0]])
     self.phasecentre = SkyCoord(ra=+15.0 * u.deg,
                                 dec=dec * u.deg,
                                 frame='icrs',
                                 equinox='J2000')
     self.config = create_named_configuration(config, rmax=rmax)
     self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
     nants = self.config.xyz.shape[0]
     self.npixel = 512
     self.fov = 4
     self.cellsize = numpy.pi * self.fov / (self.npixel * 180.0)
     assert nants > 1
     assert len(self.config.names) == nants
     assert len(self.config.mount) == nants
Exemplo n.º 6
0
 def setUp(self):
     from rascil.data_models.parameters import rascil_path
     self.dir = rascil_path('test_results')
     
     self.mid = create_named_configuration('MID', rmax=1000.0)
     self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 100.0)
     self.frequency = numpy.linspace(1.0e8, 1.1e8, 3)
     self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7])
     # 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])
     
     # 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)
Exemplo n.º 7
0
    def actualSetUp(self, freqwin=1, block=False, dopol=False, zerow=False):

        self.npixel = 1024
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        self.vis_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])

        self.phasecentre = SkyCoord(ra=+30.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis_list = [
            rsexecute.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.vis_list = rsexecute.compute(self.vis_list)
 def setUp(self):
     self.lowcore = create_named_configuration('LOWBD2-CORE')
     self.times = (numpy.pi / 43200.0) * numpy.arange(
         -21600, +21600, 3600.0)
     self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                 dec=-65.0 * u.deg,
                                 frame='icrs',
                                 equinox='J2000')
     self.frequency = numpy.linspace(1.0e8, 1.1e8, 3)
     self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7])
     self.bvis = create_blockvisibility(
         self.lowcore,
         self.times,
         self.frequency,
         channel_bandwidth=self.channel_bandwidth,
         phasecentre=self.phasecentre,
         weight=1.0)
Exemplo n.º 9
0
    def setUp(self):
        from rascil.data_models.parameters import rascil_path
        self.dir = rascil_path('test_results')

        self.frequency = numpy.linspace(0.8e8, 1.2e8, 5)
        self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7, 1e7, 1e7])
        self.flux = numpy.array([[100.0], [100.0], [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('LOWBD2-CORE')
        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
 def setUp(self):
     from rascil.data_models.parameters import rascil_path, rascil_data_path
     self.dir = rascil_path('test_results')
     
     self.vnchan = 7
     self.lowcore = create_named_configuration('LOWBD2', rmax=300.0)
     self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7)
     self.frequency = numpy.linspace(8e7, 1.2e8, self.vnchan)
     self.startfrequency = numpy.array([8e7])
     self.channel_bandwidth = numpy.array(self.vnchan * [(1.0 - 1.0e-7) * (self.frequency[1] - self.frequency[0])])
     self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     self.vis = create_visibility(self.lowcore, times=self.times, frequency=self.frequency,
                                  phasecentre=self.phasecentre, weight=1.0,
                                  polarisation_frame=PolarisationFrame('stokesI'),
                                  channel_bandwidth=self.channel_bandwidth)
     self.model = create_image_from_visibility(self.vis, npixel=128, cellsize=0.001, nchan=self.vnchan,
                                               frequency=self.startfrequency)
Exemplo n.º 11
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)
Exemplo n.º 12
0
    def setUp(self):

        self.lowcore = create_named_configuration('LOWBD2', rmax=300.0)
        self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 30 * 3.76, 3.76)
        df = 27343.75000
        self.frequency = numpy.array([1e8 - df, 1e8, 1e8 + df])
        self.channel_bandwidth = numpy.array([27343.75, 27343.75, 27343.75])
        self.phasecentre = SkyCoord(ra=+0.0 * u.deg,
                                    dec=-35.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.blockvis = create_blockvisibility(
            self.lowcore,
            self.times,
            self.frequency,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'),
            channel_bandwidth=self.channel_bandwidth,
            meta={"RASCIL": 0.1})
Exemplo n.º 13
0
    def setUp(self):

        self.persist = os.getenv("RASCIL_PERSIST", False)

        from rascil.data_models.parameters import rascil_path, rascil_data_path
        self.dir = rascil_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)
Exemplo n.º 14
0
    def setUp(self):
        rsexecute.set_client(use_dask=True,
                             processes=True,
                             threads_per_worker=1)

        from rascil.data_models.parameters import rascil_path, rascil_data_path
        self.dir = rascil_path('test_results')

        self.frequency = numpy.linspace(1e8, 1.5e8, 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('LOWBD2-CORE')
        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.persist = os.getenv("RASCIL_PERSIST", False)
Exemplo n.º 15
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
Exemplo n.º 16
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)
Exemplo n.º 17
0
    def setUp(self):
        from rascil.data_models.parameters import rascil_path

        self.doplot = True

        self.midcore = create_named_configuration('MID', rmax=100.0)
        self.nants = len(self.midcore.names)
        self.dir = rascil_path('test_results')
        self.ntimes = 100
        interval = 10.0
        self.times = numpy.arange(0.0, float(self.ntimes)) * interval
        self.times *= numpy.pi / 43200.0

        self.frequency = numpy.array([1.4e9])
        self.channel_bandwidth = numpy.array([1e7])
        self.phasecentre = SkyCoord(ra=+15.0 * u.deg,
                                    dec=-45.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_blockvisibility(
            self.midcore,
            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

        # Create model
        self.model = create_image(
            npixel=512,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame("stokesI"),
            frequency=self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre)
Exemplo n.º 18
0
 def setUp(self):
     from rascil.data_models.parameters import rascil_path
     self.dir = rascil_path('test_results')
     self.persist = os.getenv("RASCIL_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 actualSetUp(self, freqwin=1, block=True, dopol=False, zerow=False):

        self.npixel = 1024
        self.low = create_named_configuration('LOWBD2', rmax=550.0)
        self.freqwin = freqwin
        self.blockvis_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])

        self.phasecentre = SkyCoord(ra=+0.0 * u.deg,
                                    dec=-40.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.blockvis_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.vis_list = [
            convert_blockvisibility_to_visibility(bv)
            for bv in self.blockvis_list
        ]

        self.skymodel_list = [
            create_low_test_skymodel_from_gleam(
                npixel=self.npixel,
                cellsize=self.cellsize,
                frequency=[self.frequency[f]],
                phasecentre=self.phasecentre,
                polarisation_frame=PolarisationFrame("stokesI"),
                flux_limit=0.6,
                flux_threshold=1.0,
                flux_max=5.0) for f, freq in enumerate(self.frequency)
        ]

        assert isinstance(self.skymodel_list[0].image,
                          Image), self.skymodel_list[0].image
        assert isinstance(self.skymodel_list[0].components[0],
                          Skycomponent), self.skymodel_list[0].components[0]
        assert len(self.skymodel_list[0].components) == 35, len(
            self.skymodel_list[0].components)
        self.skymodel_list = expand_skymodel_by_skycomponents(
            self.skymodel_list[0])
        assert len(self.skymodel_list) == 36, len(self.skymodel_list)
        assert numpy.max(numpy.abs(
            self.skymodel_list[-1].image.data)) > 0.0, "Image is empty"
        self.vis_list = [
            copy_visibility(self.vis_list[0], zero=True)
            for i, _ in enumerate(self.skymodel_list)
        ]
 def test_clip_configuration(self):
     for rmax in [
             100.0, 3000.0, 1000.0, 3000.0, 10000.0, 30000.0, 100000.0
     ]:
         self.config = create_named_configuration('LOWBD2', rmax=rmax)
         assert self.config.size() > 0.0
 def test_unknown_configuration(self):
     with self.assertRaises(ValueError):
         self.config = create_named_configuration("SKA1-OWL")
    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
Exemplo n.º 23
0
 # We pass in the scheduler from the invoking script
 if len(sys.argv) > 1:
     scheduler = sys.argv[1]
     client = Client(scheduler)
 else:
     client = Client()
 rsexecute.set_client(client=client)
 
 from rascil.data_models.parameters import rascil_path
 
 dir = rascil_path('test_results')
 
 frequency = numpy.linspace(1e8, 1.5e8, 3)
 channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7])
 flux = numpy.array([[100.0], [100.0], [100.0]])
 config = create_named_configuration('LOWBD2-CORE')
 times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
 nants = config.xyz.shape[0]
 assert nants > 1
 assert len(config.names) == nants
 assert len(config.mount) == nants
 
 config = create_named_configuration('LOWBD2', rmax=1000.0)
 phasecentre = SkyCoord(ra=+15 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')
 
 bvis_graph = rsexecute.execute(create_blockvisibility)(config, times, frequency,
                                                         channel_bandwidth=channel_bandwidth,
                                                         phasecentre=phasecentre, weight=1.0,
                                                         polarisation_frame=PolarisationFrame('stokesI'))
 vis_graph = rsexecute.execute(convert_blockvisibility_to_visibility)(bvis_graph)
 
Exemplo n.º 24
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)
            ]
Exemplo n.º 25
0
    def actualSetUp(self, zerow=True):
        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.vis_pol = PolarisationFrame('linear')
        self.image_pol = PolarisationFrame('stokesIQUV')

        f = numpy.array([100.0, 20.0, -10.0, 1.0])

        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=False,
                                              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 = predict_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,
                    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 = \
            [rsexecute.execute(ingest_unittest_visibility, nout=1)(self.low,
                                                                   [self.frequency[i]],
                                                                   [self.channelwidth[i]],
                                                                   self.times,
                                                                   self.vis_pol,
                                                                   self.phasecentre, block=True,
                                                                   zerow=zerow)
             for i in range(nfreqwin)]
        self.blockvis_list = rsexecute.compute(self.blockvis_list, sync=True)
        self.blockvis_list = rsexecute.scatter(self.blockvis_list)

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

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

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

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

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

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

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

        self.model_imagelist = [
            rsexecute.execute(create_unittest_model,
                              nout=1)(self.vis_list[i],
                                      self.image_pol,
                                      npixel=self.npixel,
                                      cellsize=0.0005) for i in range(nfreqwin)
        ]
        self.model_imagelist = rsexecute.compute(self.model_imagelist,
                                                 sync=True)
        self.model_imagelist = rsexecute.scatter(self.model_imagelist)
Exemplo n.º 27
0
    def actualSetUp(self,
                    nfreqwin=3,
                    dospectral=True,
                    dopol=False,
                    amp_errors=None,
                    phase_errors=None,
                    zerow=True):

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

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

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

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

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

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

        for v in self.blockvis_list:
            v.data['vis'][...] = 1.0 + 0.0j

        self.error_blockvis_list = [
            rsexecute.execute(copy_visibility(v)) for v in self.blockvis_list
        ]
        gt = rsexecute.execute(create_gaintable_from_blockvisibility)(
            self.blockvis_list[0])
        gt = rsexecute.execute(simulate_gaintable)(gt,
                                                   phase_error=0.1,
                                                   amplitude_error=0.0,
                                                   smooth_channels=1,
                                                   leakage=0.0,
                                                   seed=180555)
        self.error_blockvis_list = [
            rsexecute.execute(apply_gaintable)(self.error_blockvis_list[i], gt)
            for i in range(self.freqwin)
        ]

        self.error_blockvis_list = rsexecute.compute(self.error_blockvis_list,
                                                     sync=True)

        assert numpy.max(
            numpy.abs(self.error_blockvis_list[0].vis -
                      self.blockvis_list[0].vis)) > 0.0
Exemplo n.º 28
0
from rascil.processing_components.imaging.base import invert_2d, predict_2d, shift_vis_to_image, normalize_sumwt
from rascil.processing_components.visibility.base import copy_visibility
from rascil.processing_components.imaging.ng import predict_ng, invert_ng
from rascil.processing_components.griddata.kernels import create_awterm_convolutionfunction

# In[3]:

rdir = './'
verbosity = True
dopol = False
dospectral = True
zerow = False
block = True
persist = True
npixel = 1024
low = create_named_configuration('LOWBD2', rmax=750.0)
freqwin = 21
blockvis = list()
ntimes = 5
times = numpy.linspace(-3.0, +3.0, ntimes) * numpy.pi / 12.0

if freqwin > 1:
    frequency = numpy.linspace(0.99e8, 1.01e8, freqwin)
    channelwidth = numpy.array(freqwin * [frequency[1] - frequency[0]])
else:
    frequency = numpy.array([1e8])
    channelwidth = numpy.array([1e6])

if dopol:
    blockvis_pol = PolarisationFrame('linear')
    image_pol = PolarisationFrame('stokesIQUV')
Exemplo n.º 29
0
    def test_export_ms(self):
        if run_ms_tests == False:
            return

        msoutfile = rascil_path("test_results/test_export_ms_ASKAP_output.ms")

        from astropy.coordinates import SkyCoord
        from astropy import units as u

        from rascil.processing_components.image.operations import show_image, export_image_to_fits
        from rascil.processing_components.simulation import create_named_configuration
        from rascil.processing_components.simulation import create_test_image
        from rascil.processing_components.imaging.base import create_image_from_visibility
        from rascil.processing_components.imaging.base import advise_wide_field

        from rascil.workflows.serial.imaging.imaging_serial import invert_list_serial_workflow, predict_list_serial_workflow

        from rascil.data_models.polarisation import PolarisationFrame

        lowr3 = create_named_configuration('LOWBD2', rmax=750.0)

        times = numpy.zeros([1])
        frequency = numpy.array([1e8])
        channelbandwidth = numpy.array([1e6])
        phasecentre = SkyCoord(ra=+15.0 * u.deg,
                               dec=-45.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')

        bvis = create_blockvisibility(
            lowr3,
            times,
            frequency,
            phasecentre=phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'),
            channel_bandwidth=channelbandwidth)

        vt = convert_blockvisibility_to_visibility(bvis)

        advice = advise_wide_field(vt,
                                   guard_band_image=3.0,
                                   delA=0.1,
                                   facets=1,
                                   wprojection_planes=1,
                                   oversampling_synthesised_beam=4.0)
        cellsize = advice['cellsize']

        m31image = create_test_image(frequency=frequency, cellsize=cellsize)
        nchan, npol, ny, nx = m31image.data.shape
        m31image.wcs.wcs.crval[0] = vt.phasecentre.ra.deg
        m31image.wcs.wcs.crval[1] = vt.phasecentre.dec.deg
        m31image.wcs.wcs.crpix[0] = float(nx // 2)
        m31image.wcs.wcs.crpix[1] = float(ny // 2)
        vt = predict_list_serial_workflow([vt], [m31image], context='2d')[0]
        # uvdist = numpy.sqrt(vt.data['uvw'][:, 0] ** 2 + vt.data['uvw'][:, 1] ** 2)
        #
        # model = create_image_from_visibility(vt, cellsize=cellsize, npixel=512)
        # dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0]
        # psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0]
        #
        # show_image(dirty)
        # print("Max, min in dirty image = %.6f, %.6f, sumwt = %f" % (dirty.data.max(), dirty.data.min(), sumwt))
        #
        # print("Max, min in PSF         = %.6f, %.6f, sumwt = %f" % (psf.data.max(), psf.data.min(), sumwt))
        # results_dir="/Users/f.wang"
        # export_image_to_fits(dirty, '%s/imaging_dirty.fits' % (results_dir))
        # export_image_to_fits(psf, '%s/imaging_psf.fits' % (results_dir))

        v = convert_visibility_to_blockvisibility(vt)
        vis_list = []
        vis_list.append(v)
        export_blockvisibility_to_ms(msoutfile, vis_list, source_name='M31')
if __name__ == '__main__':

    dir = '.'

    # Set up a short observation with MID
    dec = -45.0
    rmax = 1e3
    freq = 1.4e9
    frequency = numpy.linspace(freq, 1.5 * freq, 3)
    channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7])
    flux = numpy.array([[100.0], [100.0], [100.0]])
    phasecentre = SkyCoord(ra=+15.0 * u.deg,
                           dec=-35.0 * u.deg,
                           frame='icrs',
                           equinox='J2000')
    config = create_named_configuration('MIDR5', rmax=rmax)
    times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
    nants = config.xyz.shape[0]
    assert nants > 1
    assert len(config.names) == nants
    assert len(config.mount) == nants

    vis = create_visibility(config,
                            times,
                            frequency,
                            channel_bandwidth=channel_bandwidth,
                            phasecentre=phasecentre,
                            weight=1.0,
                            polarisation_frame=PolarisationFrame('stokesI'))

    cellsize = 8 * numpy.pi / 180.0 / 280