예제 #1
0
 def test_create_image_from_visibility(self):
     self.actualSetUp()
     im = create_image_from_visibility(self.componentvis,
                                       nchan=1,
                                       npixel=128)
     assert im.data.shape == (1, 1, 128, 128)
     im = create_image_from_visibility(self.componentvis,
                                       frequency=self.frequency,
                                       npixel=128)
     assert im.data.shape == (len(self.frequency), 1, 128, 128)
     im = create_image_from_visibility(self.componentvis,
                                       frequency=self.frequency,
                                       npixel=128,
                                       nchan=1)
     assert im.data.shape == (1, 1, 128, 128)
예제 #2
0
    def setUp(self):
        self.dir = './test_results'
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        os.makedirs(self.dir, exist_ok=True)
        self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)
        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e6])
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.vis.data['vis'] *= 0.0

        # Create model
        self.model = create_test_image(cellsize=0.0015,
                                       phasecentre=self.vis.phasecentre,
                                       frequency=self.frequency)
        self.model.data[self.model.data > 1.0] = 1.0
        self.vis = predict_2d(self.vis, self.model)
        assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
        export_image_to_fits(
            self.model, '%s/test_solve_skycomponent_model.fits' % (self.dir))
        self.bigmodel = create_image_from_visibility(self.vis,
                                                     cellsize=0.0015,
                                                     npixel=512)
예제 #3
0
    def setUp(self):
        self.dir = './test_results'
        os.makedirs(self.dir, exist_ok=True)

        self.vnchan = 5
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        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 * [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=512,
            cellsize=0.001,
            nchan=self.vnchan,
            frequency=self.startfrequency)
예제 #4
0
 def ingest_visibility(self, freq=None, chan_width=None, times=None, reffrequency=None, add_errors=False,
                       block=True):
     if freq is None:
         freq = [1e8]
     if times is None:
         ntimes = 5
         times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)
     if chan_width is None:
         chan_width = [1e6]
     
     if reffrequency is None:
         reffrequency = [1e8]
     lowcore = create_named_configuration('LOWBD2-CORE')
     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=reffrequency, phasecentre=phasecentre,
                                          polarisation_frame=PolarisationFrame("stokesI"))
     flux = numpy.array([[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(flux=flux, frequency=frequency, direction=sc,
                                        polarisation_frame=PolarisationFrame("stokesI"))
             comps.append(comp)
     if block:
         predict_skycomponent_blockvisibility(vt, comps)
     else:
         predict_skycomponent_visibility(vt, comps)
     insert_skycomponent(model, comps)
     self.model = copy_image(model)
     self.empty_model = create_empty_image_like(model)
     export_image_to_fits(model, '%s/test_pipeline_bags_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)
     return vt
예제 #5
0
 def test_get_frequency_map_different_channel(self):
     self.model = create_image_from_visibility(self.vis, npixel=512, cellsize=0.001,
                                               frequency=self.startfrequency, nchan=3,
                                               channel_bandwidth=2e7)
     spectral_mode, vfrequency_map = get_frequency_map(self.vis, self.model)
     assert numpy.max(vfrequency_map) == self.model.nchan - 1
     assert spectral_mode == 'channel'
예제 #6
0
    def ingest_visibility(self,
                          freq=1e8,
                          chan_width=1e6,
                          times=None,
                          reffrequency=None,
                          add_errors=False):
        if times is None:
            times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5)

        if reffrequency is None:
            reffrequency = [1e8]
        lowcore = create_named_configuration('LOWBD2-CORE')
        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')
        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=reffrequency,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"))
        flux = numpy.array([[100.0]])
        facets = 4

        rpix = model.wcs.wcs.crpix
        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=0)
                comp = create_skycomponent(
                    flux=flux,
                    frequency=frequency,
                    direction=sc,
                    polarisation_frame=PolarisationFrame("stokesI"))
                comps.append(comp)
        predict_skycomponent_visibility(vt, comps)
        insert_skycomponent(model, comps)
        self.model = copy_image(model)
        export_image_to_fits(model,
                             '%s/test_bags_model.fits' % (self.results_dir))
        return vt
예제 #7
0
 def get_LSM(self, vt, cellsize=0.001, reffrequency=None, flux=0.0):
     if reffrequency is None:
         reffrequency = [1e8]
     model = create_image_from_visibility(vt, npixel=self.npixel, cellsize=cellsize, npol=1,
                                          frequency=reffrequency,
                                          polarisation_frame=PolarisationFrame("stokesI"))
     model.data[..., 32, 32] = flux
     return model
예제 #8
0
 def test_get_frequency_map_channel(self):
     self.model = create_image_from_visibility(self.vis, npixel=512, cellsize=0.001,
                                               nchan=self.vnchan,
                                               frequency=self.startfrequency)
     spectral_mode, vfrequency_map = get_frequency_map(self.vis, self.model)
     assert numpy.max(vfrequency_map) == self.model.nchan - 1
     assert numpy.min(vfrequency_map) == 0
     assert spectral_mode == 'channel'
 def test_create_image_from_visibility(self):
     self.actualSetUp()
     self.componentvis = create_visibility(
         self.lowcore,
         self.times,
         self.frequency,
         phasecentre=self.phasecentre,
         weight=1.0,
         polarisation_frame=self.vis_pol,
         channel_bandwidth=self.channel_bandwidth)
     im = create_image_from_visibility(self.componentvis,
                                       nchan=1,
                                       npixel=128)
     assert im.data.shape == (1, 1, 128, 128)
     im = create_image_from_visibility(self.componentvis,
                                       frequency=self.frequency,
                                       npixel=128)
     assert im.data.shape == (len(self.frequency), 1, 128, 128)
     im = create_image_from_visibility(self.componentvis,
                                       frequency=self.frequency,
                                       npixel=128,
                                       nchan=1)
     assert im.data.shape == (1, 1, 128, 128)
예제 #10
0
def create_unittest_model(vis, model_pol, npixel=None, cellsize=None, nchan=1):
    advice = advise_wide_field(vis,
                               guard_band_image=2.0,
                               delA=0.02,
                               facets=1,
                               wprojection_planes=1,
                               oversampling_synthesised_beam=4.0)
    if cellsize is None:
        cellsize = advice['cellsize']
    if npixel is None:
        npixel = advice['npixels2']
    model = create_image_from_visibility(vis,
                                         npixel=npixel,
                                         cellsize=cellsize,
                                         nchan=nchan,
                                         polarisation_frame=model_pol)
    return model
예제 #11
0
 def ingest_visibility(self, freq=1e8, chan_width=1e6, times=None, reffrequency=None, add_errors=False):
     if times is None:
         times = [0.0]
     if reffrequency is None:
         reffrequency = [1e8]
     lowcore = create_named_configuration('LOWBD2-CORE')
     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')
     # Observe at zenith to ensure that timeslicing works well. We test that elsewhere.
     phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     vt = create_blockvisibility(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=reffrequency,
                                          polarisation_frame=PolarisationFrame("stokesI"))
     flux = numpy.array([[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)
             comps.append(create_skycomponent(flux=flux, frequency=vt.frequency, direction=sc,
                                              polarisation_frame=PolarisationFrame("stokesI")))
     predict_skycomponent_blockvisibility(vt, comps)
     insert_skycomponent(model, comps)
     self.actualmodel = copy_image(model)
     export_image_to_fits(model, '%s/test_imaging_model.fits' % (self.results_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)
     return vt
예제 #12
0
def wproject(vis, npixel_advice, cell_advice, channel, results_dir):
    """Do w-projected imaging of visibility data.
    
    Args:
    vis (obj): ARL visibility data.
    npixel_advice (float): number of pixels in output image.
    cell_advice (float): cellsize in output image.
    channel (int): channel number to be imaged (affects output filename).
    results_dir (str): directory to save results.
    
    Returns:
    dirty: dirty image.
    psf: image of psf.
    """
    try:
        vis_slices = len(np.unique(vis.time))
        print("There are %d timeslices" % vis_slices)
        # Obtain advice on w-proj parameters:
        advice = advise_wide_field(vis)
        # Create a model image:
        model = create_image_from_visibility(vis, cellsize=cell_advice,
                                             npixel=npixel_advice,
                                             polarisation_frame=PolarisationFrame('stokesIQUV'))
        # Weight the visibilities:
        vis, _, _ = weight_visibility(vis, model)
        # Create a dirty image:
        dirty, sumwt = create_invert_graph([vis], model, kernel='wprojection',
                                           wstep=advice['w_sampling_primary_beam'],
                                           oversampling=2).compute()
        # Create the psf:
        psf, sumwt = create_invert_graph([vis], model, dopsf=True, kernel='wprojection',
                                         wstep=advice['w_sampling_primary_beam'],
                                         oversampling=2).compute()
        # Save to disk:
        export_image_to_fits(dirty, '%s/imaging_dirty_WProj-%s.fits'
                             % (results_dir, channel))
        export_image_to_fits(psf, '%s/imaging_psf_WProj-%s.fits'
                             % (results_dir, channel))
    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise
    return dirty, psf
    def test_peel_skycomponent_blockvisibility(self):
        df = 1e6
        frequency = numpy.array([1e8 - df, 1e8, 1e8 + df])
        channel_bandwidth = numpy.array([df, df, df])

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

        config = create_named_configuration('LOWBD2-CORE')
        peeldirection = SkyCoord(+15 * u.deg, -60.0 * u.deg)
        times = numpy.linspace(-3.0, 3.0, 7) * numpy.pi / 12.0

        # Make the visibility
        vis = create_blockvisibility(
            config,
            times,
            frequency,
            phasecentre=phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('linear'),
            channel_bandwidth=channel_bandwidth)
        vis.data['vis'][...] = 0.0

        # First add in the source to be peeled.
        peel = Skycomponent(direction=peeldirection,
                            frequency=frequency,
                            flux=flux,
                            polarisation_frame=PolarisationFrame("stokesIQUV"))
        vis = predict_skycomponent_visibility(vis, peel)

        # Make a gaintable and apply it to the visibility of the peeling source
        gt = create_gaintable_from_blockvisibility(vis, timeslice='auto')
        gt = simulate_gaintable(gt,
                                phase_error=0.01,
                                amplitude_error=0.01,
                                timeslice='auto')
        gt.data['gain'] *= 0.3
        vis = apply_gaintable(vis, gt, timeslice='auto')

        # Now create a plausible field using the GLEAM sources
        model = create_image_from_visibility(
            vis,
            cellsize=0.001,
            frequency=frequency,
            polarisation_frame=PolarisationFrame('stokesIQUV'))

        bm = create_low_test_beam(model=model)
        sc = create_low_test_skycomponents_from_gleam(
            flux_limit=1.0,
            polarisation_frame=PolarisationFrame("stokesIQUV"),
            frequency=frequency,
            kind='cubic',
            phasecentre=phasecentre,
            radius=0.1)
        sc = apply_beam_to_skycomponent(sc, bm)
        # Add in the visibility due to these sources
        vis = predict_skycomponent_visibility(vis, sc)
        assert numpy.max(numpy.abs(vis.vis)) > 0.0

        # Now we can peel
        vis, peel_gts = peel_skycomponent_blockvisibility(vis, peel)

        assert len(peel_gts) == 1
        residual = numpy.max(peel_gts[0].residual)
        assert residual < 0.7, "Peak residual %.6f too large" % (residual)

        im, sumwt = invert_timeslice(vis, model, timeslice='auto')
        qa = qa_image(im)

        assert numpy.abs(qa.data['max'] - 14.2) < 1.0, str(qa)
    def actualSetUp(self, time=None, dospectral=False, dopol=False):
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5)

        if time is not None:
            self.times = time
        log.info("Times are %s" % self.times)

        if dospectral:
            self.nchan = 3
            self.frequency = numpy.array([0.9e8, 1e8, 1.1e8])
            self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7])
        else:
            self.frequency = numpy.array([1e8])
            self.channel_bandwidth = numpy.array([1e7])

        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, 0.8 * f, 0.6 * f])
        else:
            flux = numpy.array([f])

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.componentvis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=self.vis_pol)
        self.uvw = self.componentvis.data['uvw']
        self.componentvis.data['vis'][...] = 0.0

        # Create model
        self.model = create_image_from_visibility(
            self.componentvis,
            npixel=self.params['npixel'],
            cellsize=0.0005,
            nchan=len(self.frequency),
            polarisation_frame=self.image_pol)

        # Fill the visibility with exactly computed point sources.
        spacing_pixels = 512 // 8
        log.info('Spacing in pixels = %s' % spacing_pixels)

        centers = [(x, x) for x in numpy.linspace(-1.4, +1.4, 9)]

        for x in numpy.linspace(-1.4, +1.4, 9):
            centers.append((-x, x))

        centers.append((0.5, 1.1))
        centers.append((1e-7, 1e-7))

        # Make the list of components
        rpix = self.model.wcs.wcs.crpix
        self.components = []
        for center in centers:
            ix, iy = center
            # The phase center in 0-relative coordinates is n // 2 so we centre the grid of
            # components on ny // 2, nx // 2. The wcs must be defined consistently.
            p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[0]))), \
                int(round(rpix[1] + iy * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[1])))
            sc = pixel_to_skycoord(p[0], p[1], self.model.wcs, origin=1)
            log.info("Component at (%f, %f) [0-rel] %s" %
                     (p[0], p[1], str(sc)))

            if ix != 0 and iy != 0:
                # Channel images
                comp = create_skycomponent(flux=flux,
                                           frequency=self.frequency,
                                           direction=sc,
                                           polarisation_frame=self.image_pol)
                self.components.append(comp)

        # Predict the visibility from the components exactly
        self.componentvis.data['vis'] *= 0.0
        self.beam = create_low_test_beam(self.model)

        self.components = apply_beam_to_skycomponent(self.components,
                                                     self.beam)
        self.componentvis = predict_skycomponent_visibility(
            self.componentvis, self.components)
        self.model = insert_skycomponent(self.model, self.components)

        # Calculate the model convolved with a Gaussian.
        self.cmodel = smooth_image(self.model)
        export_image_to_fits(self.model,
                             '%s/test_imaging_functions_model.fits' % self.dir)
        export_image_to_fits(
            self.cmodel, '%s/test_imaging_functions_cmodel.fits' % self.dir)
#print("uvw", block_vis.uvw, numpy.sum(block_vis.uvw))
#print("vis", block_vis.vis, numpy.sum(block_vis.vis))
#print("weight", block_vis.weight, numpy.sum(block_vis.weight))
#print("time", block_vis.time, numpy.sum(block_vis.time))
#print("integration_time", block_vis.integration_time, numpy.sum(block_vis.integration_time))
#print("nvis, size", block_vis.nvis, block_vis.size())

gt = create_gaintable_from_blockvisibility(block_vis)
#print("np.sum(gt.data): ", numpy.sum(gt.data['gain']))
gt = simulate_gaintable(gt, phase_error=1.0)
#print("np.sum(gt.data): ", numpy.sum(gt.data['gain']))
blockvis = apply_gaintable(block_vis, gt)
#print("np.sum(blockvis.data): ", numpy.sum(blockvis.data['vis']))


model = create_image_from_visibility(block_vis, npixel=npixel, frequency=[numpy.average(frequency)], nchan=1,
    channel_bandwidth=[numpy.sum(channel_bandwidth)], cellsize=cellsize, phasecentre=phasecentre)

#print("model sum, min, max, shape: ", numpy.sum(model.data), numpy.amin(model.data), numpy.amax(model.data), model.shape)

print(qa_image(model, context='Blockvis model image'))
export_image_to_fits(model, '%s/imaging-blockvis_model.fits'
                     % (results_dir))

dirty, sumwt = invert_function(predicted_vis, model, vis_slices=vis_slices, dopsf=False, context='wstack')


print(qa_image(dirty, context='Dirty image'))
export_image_to_fits(dirty, '%s/imaging-dirty.fits'
                     % (results_dir))

 def actualSetup(self, sky_pol_frame='stokesI', data_pol_frame='stokesI', f=None, vnchan=1, doiso=True,
                 ntimes=1, flux_limit=18.0):
     
     nfreqwin = vnchan
     ntimes = ntimes
     rmax = 300.0
     npixel = 1024
     cellsize = 0.001
     frequency = numpy.linspace(0.8e8, 1.2e8, nfreqwin)
     if nfreqwin > 1:
         channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]])
     else:
         channel_bandwidth = [0.4e8]
     times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)
     
     phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')
     
     lowcore = create_named_configuration('LOWBD2', rmax=rmax)
     
     block_vis = create_blockvisibility(lowcore, times, frequency=frequency, channel_bandwidth=channel_bandwidth,
                                        weight=1.0, phasecentre=phasecentre,
                                        polarisation_frame=PolarisationFrame("stokesI"))
     
     block_vis.data['uvw'][..., 2] = 0.0
     self.beam = create_image_from_visibility(block_vis, npixel=npixel, frequency=[numpy.average(frequency)],
                                              nchan=nfreqwin,
                                              channel_bandwidth=[numpy.sum(channel_bandwidth)], cellsize=cellsize,
                                              phasecentre=phasecentre)
     
     self.components = create_low_test_skycomponents_from_gleam(flux_limit=flux_limit, phasecentre=phasecentre,
                                                                frequency=frequency,
                                                                polarisation_frame=PolarisationFrame('stokesI'),
                                                                radius=npixel * cellsize)
     self.beam = create_low_test_beam(self.beam)
     self.components = apply_beam_to_skycomponent(self.components, self.beam, flux_limit=flux_limit / 100.0)
     print("Number of components %d" % len(self.components))
     
     self.vis = copy_visibility(block_vis, zero=True)
     gt = create_gaintable_from_blockvisibility(block_vis, timeslice='auto')
     for i, sc in enumerate(self.components):
         if sc.flux[0, 0] > 10:
             sc.flux[...] /= 10.0
         print('Component %d, flux = %s' % (i, str(sc.flux[0, 0])))
         component_vis = copy_visibility(block_vis, zero=True)
         gt = simulate_gaintable(gt, amplitude_error=0.0, phase_error=0.1, seed=None)
         component_vis = predict_skycomponent_visibility(component_vis, sc)
         component_vis = apply_gaintable(component_vis, gt)
         self.vis.data['vis'][...] += component_vis.data['vis'][...]
     
     # Do an isoplanatic selfcal
     self.model_vis = copy_visibility(self.vis, zero=True)
     self.model_vis = predict_skycomponent_visibility(self.model_vis, self.components)
     if doiso:
         gt = solve_gaintable(self.vis, self.model_vis, phase_only=True, timeslice='auto')
         self.vis = apply_gaintable(self.vis, gt, inverse=True)
     
     self.model_vis = convert_blockvisibility_to_visibility(self.model_vis)
     self.model_vis, _, _ = weight_visibility(self.model_vis, self.beam)
     self.dirty_model, sumwt = invert_function(self.model_vis, self.beam, context='2d')
     export_image_to_fits(self.dirty_model, "%s/test_sagecal-model_dirty.fits" % self.dir)
     
     lvis = convert_blockvisibility_to_visibility(self.vis)
     lvis, _, _ = weight_visibility(lvis, self.beam)
     dirty, sumwt = invert_function(lvis, self.beam, context='2d')
     print(qa_image(dirty))
     export_image_to_fits(dirty, "%s/test_sagecal-initial_dirty.fits" % self.dir)