Beispiel #1
0
    def _invert_base(self,
                     context,
                     extra='',
                     fluxthreshold=1.0,
                     positionthreshold=1.0,
                     check_components=True,
                     facets=1,
                     vis_slices=1,
                     gcfcf=None,
                     **kwargs):

        centre = self.freqwin // 2
        dirty = invert_list_arlexecute_workflow(self.vis_list,
                                                self.model_list,
                                                context=context,
                                                dopsf=False,
                                                normalize=True,
                                                facets=facets,
                                                vis_slices=vis_slices,
                                                gcfcf=gcfcf,
                                                **kwargs)
        dirty = arlexecute.compute(dirty, sync=True)[centre]

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

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

        if check_components:
            self._checkcomponents(dirty[0], fluxthreshold, positionthreshold)
Beispiel #2
0
    def test_deconvolve_spectral(self):
        self.actualSetUp(add_errors=True)
        dirty_imagelist = invert_list_arlexecute_workflow(self.vis_list,
                                                          self.model_imagelist,
                                                          context='2d',
                                                          dopsf=False,
                                                          normalize=True)
        psf_imagelist = invert_list_arlexecute_workflow(self.vis_list,
                                                        self.model_imagelist,
                                                        context='2d',
                                                        dopsf=True,
                                                        normalize=True)
        dirty_imagelist = arlexecute.persist(dirty_imagelist)
        psf_imagelist = arlexecute.persist(psf_imagelist)
        deconvolved = deconvolve_list_arlexecute_workflow(
            dirty_imagelist,
            psf_imagelist,
            self.model_imagelist,
            niter=1000,
            fractional_threshold=0.1,
            scales=[0, 3, 10],
            threshold=0.1,
            gain=0.7)
        deconvolved = arlexecute.persist(deconvolved)
        deconvolved = arlexecute.compute(deconvolved, sync=True)

        export_image_to_fits(
            deconvolved[0], '%s/test_imaging_%s_deconvolve_spectral.fits' %
            (self.dir, arlexecute.type()))
 def test_restored_list_facet(self):
     self.actualSetUp(zerow=True)
     
     centre = self.freqwin // 2
     psf_image_list = invert_list_arlexecute_workflow(self.vis_list, self.model_list, context='2d', dopsf=True)
     residual_image_list = residual_list_arlexecute_workflow(self.vis_list, self.model_list, context='2d')
     restored_4facets_image_list = restore_list_arlexecute_workflow(self.model_list, psf_image_list,
                                                                    residual_image_list,
                                                                    restore_facets=4, psfwidth=1.0)
     restored_4facets_image_list = arlexecute.compute(restored_4facets_image_list, sync=True)
     
     restored_1facets_image_list = restore_list_arlexecute_workflow(self.model_list, psf_image_list,
                                                                    residual_image_list,
                                                                    restore_facets=1, psfwidth=1.0)
     restored_1facets_image_list = arlexecute.compute(restored_1facets_image_list, sync=True)
     
     if self.persist: export_image_to_fits(restored_4facets_image_list[0],
                                           '%s/test_imaging_invert_%s_restored_4facets.fits' %
                                           (self.dir, arlexecute.type()))
     
     qa = qa_image(restored_4facets_image_list[centre])
     assert numpy.abs(qa.data['max'] - 99.43438263927833) < 1e-7, str(qa)
     assert numpy.abs(qa.data['min'] + 0.6328915148563354) < 1e-7, str(qa)
     
     restored_4facets_image_list[centre].data -= restored_1facets_image_list[centre].data
     if self.persist: export_image_to_fits(restored_4facets_image_list[centre],
                                           '%s/test_imaging_invert_%s_restored_4facets_error.fits' %
                                           (self.dir, arlexecute.type()))
     qa = qa_image(restored_4facets_image_list[centre])
     assert numpy.abs(qa.data['max']) < 1e-10, str(qa)
 def test_restored_list_noresidual(self):
     self.actualSetUp(zerow=True)
     
     centre = self.freqwin // 2
     psf_image_list = invert_list_arlexecute_workflow(self.vis_list, self.model_list, context='2d', dopsf=True)
     restored_image_list = restore_list_arlexecute_workflow(self.model_list, psf_image_list, psfwidth=1.0)
     restored_image_list = arlexecute.compute(restored_image_list, sync=True)
     if self.persist: export_image_to_fits(restored_image_list[centre],
                                           '%s/test_imaging_invert_%s_restored_noresidual.fits' %
                                           (self.dir, arlexecute.type()))
     
     qa = qa_image(restored_image_list[centre])
     assert numpy.abs(qa.data['max'] - 100.0) < 1e-7, str(qa)
     assert numpy.abs(qa.data['min']) < 1e-7, str(qa)
 def test_map_create_pb(self):
     self.createVis(config='LOWBD2', rmax=1000.0)
     model = create_image_from_visibility(self.vis,
                                          cellsize=0.001,
                                          override_cellsize=False)
     beam = image_arlexecute_map_workflow(model,
                                          create_pb,
                                          facets=4,
                                          pointingcentre=self.phasecentre,
                                          telescope='MID')
     beam = arlexecute.compute(beam, sync=True)
     assert numpy.max(beam.data) > 0.0
     export_image_to_fits(
         beam, "%s/test_image_arlexecute_scatter_gather.fits" % (self.dir))
    def test_deconvolve_and_restore_cube_mmclean_facets(self):
        self.actualSetUp(add_errors=True)
        dirty_imagelist = invert_list_arlexecute_workflow(self.vis_list,
                                                          self.model_imagelist,
                                                          context='2d',
                                                          dopsf=False,
                                                          normalize=True)
        psf_imagelist = invert_list_arlexecute_workflow(self.vis_list,
                                                        self.model_imagelist,
                                                        context='2d',
                                                        dopsf=True,
                                                        normalize=True)
        dirty_imagelist = arlexecute.persist(dirty_imagelist)
        psf_imagelist = arlexecute.persist(psf_imagelist)
        dec_imagelist = deconvolve_list_arlexecute_workflow(
            dirty_imagelist,
            psf_imagelist,
            self.model_imagelist,
            niter=1000,
            fractional_threshold=0.1,
            scales=[0, 3, 10],
            algorithm='mmclean',
            nmoment=3,
            nchan=self.freqwin,
            threshold=0.01,
            gain=0.7,
            deconvolve_facets=8,
            deconvolve_overlap=8,
            deconvolve_taper='tukey')
        dec_imagelist = arlexecute.persist(dec_imagelist)
        residual_imagelist = residual_list_arlexecute_workflow(
            self.vis_list, model_imagelist=dec_imagelist, context='2d')
        residual_imagelist = arlexecute.persist(residual_imagelist)
        restored_list = restore_list_arlexecute_workflow(
            model_imagelist=dec_imagelist,
            psf_imagelist=psf_imagelist,
            residual_imagelist=residual_imagelist,
            empty=self.model_imagelist)

        restored = arlexecute.compute(restored_list, sync=True)[0]

        if self.persist:
            export_image_to_fits(
                restored, '%s/test_imaging_%s_overlap_mmclean_restored.fits' %
                (self.dir, arlexecute.type()))
 def _predict_base(self, context='2d', extra='', fluxthreshold=1.0, facets=1, vis_slices=1, **kwargs):
     vis_list = zero_list_arlexecute_workflow(self.vis_list)
     vis_list = predict_list_arlexecute_workflow(vis_list, self.model_list, context=context,
                                                 vis_slices=vis_slices, facets=facets, **kwargs)
     vis_list = subtract_list_arlexecute_workflow(self.vis_list, vis_list)[0]
     
     vis_list = arlexecute.compute(vis_list, sync=True)
     
     dirty = invert_list_arlexecute_workflow([vis_list], [self.model_list[0]], context='2d', dopsf=False,
                                             normalize=True)[0]
     dirty = arlexecute.compute(dirty, sync=True)
     
     assert numpy.max(numpy.abs(dirty[0].data)), "Residual image is empty"
     export_image_to_fits(dirty[0], '%s/test_imaging_predict_%s%s_%s_dirty.fits' %
                          (self.dir, context, extra, arlexecute.type()))
     
     maxabs = numpy.max(numpy.abs(dirty[0].data))
     assert maxabs < fluxthreshold, "Error %.3f greater than fluxthreshold %.3f " % (maxabs, fluxthreshold)
 def test_deconvolve_and_restore_cube_mmclean(self):
     self.actualSetUp(add_errors=True)
     dirty_imagelist = invert_list_arlexecute_workflow(self.vis_list, self.model_imagelist, context='2d',
                                                       dopsf=False, normalize=True)
     psf_imagelist = invert_list_arlexecute_workflow(self.vis_list, self.model_imagelist, context='2d',
                                                     dopsf=True, normalize=True)
     dec_imagelist, _ = deconvolve_list_arlexecute_workflow(dirty_imagelist, psf_imagelist, self.model_imagelist, niter=1000,
                                                            fractional_threshold=0.01, scales=[0, 3, 10],
                                                            algorithm='mmclean', nmoments=3, nchan=self.freqwin,
                                                            threshold=0.1, gain=0.7)
     residual_imagelist = residual_list_arlexecute_workflow(self.vis_list, model_imagelist=dec_imagelist,
                                                            context='wstack', vis_slices=51)
     restored = restore_list_arlexecute_workflow(model_imagelist=dec_imagelist, psf_imagelist=psf_imagelist,
                                                 residual_imagelist=residual_imagelist,
                                                 empty=self.model_imagelist)[0]
     
     restored = arlexecute.compute(restored, sync=True)
     
     export_image_to_fits(restored, '%s/test_imaging_%s_mmclean_restored.fits' % (self.dir, arlexecute.type()))
Beispiel #9
0
    def progress(res, tl_list, gt_list, it, context='MPCCAL'):
        print('Iteration %d' % it)

        print(
            qa_image(res,
                     context='%s residual image: iteration %d' %
                     (context, it)))
        export_image_to_fits(
            res,
            arl_path(
                "test_results/low-sims-mpc-%s-residual_iteration%d_rmax%.1f.fits"
                % (context, it, rmax)))
        show_image(res,
                   title='%s residual image: iteration %d' % (context, it))
        plt.show(block=block_plots)

        combined_model = calculate_skymodel_equivalent_image(tl_list)
        print(
            qa_image(combined_model,
                     context='Combined model: iteration %d' % it))
        export_image_to_fits(
            combined_model,
            arl_path(
                "test_results/low-sims-mpc-%s-model_iteration%d_rmax%.1f.fits"
                % (context, it, rmax)))

        plt.clf()
        for i in range(len(tl_list)):
            plt.plot(
                numpy.angle(tl_list[i].gaintable.gain[:, :, 0, 0,
                                                      0]).flatten(),
                numpy.angle(gt_list[i]['T'].gain[:, :, 0, 0, 0]).flatten(),
                '.')
        plt.xlabel('Current phase')
        plt.ylabel('Update to phase')
        plt.title("%s iteration%d: Change in phase" % (context, it))
        plt.savefig(
            arl_path(
                "test_results/low-sims-mpc-%s-skymodel-phase-change_iteration%d.jpg"
                % (context, it)))
        plt.show(block=block_plots)
        return tl_list
Beispiel #10
0
    def test_continuum_imaging_pipeline_serialclean(self):
        self.actualSetUp(add_errors=False, zerow=True)
        continuum_imaging_list = \
            continuum_imaging_list_arlexecute_workflow(self.vis_list,
                                                       model_imagelist=self.model_imagelist,
                                                       context='2d',
                                                       algorithm='mmclean', facets=1,
                                                       scales=[0, 3, 10],
                                                       niter=1000, fractional_threshold=0.1, threshold=0.1,
                                                       nmoment=3,
                                                       nmajor=5, gain=0.1,
                                                       deconvolve_facets=4, deconvolve_overlap=32,
                                                       deconvolve_taper='tukey', psf_support=64,
                                                       use_serial_clean=True)
        clean, residual, restored = arlexecute.compute(continuum_imaging_list,
                                                       sync=True)
        centre = len(clean) // 2
        if self.persist:
            export_image_to_fits(
                clean[centre],
                '%s/test_pipelines_continuum_imaging_pipeline_arlexecute_clean.fits'
                % self.dir)
            export_image_to_fits(
                residual[centre][0],
                '%s/test_pipelines_continuum_imaging_pipeline_arlexecute_residual.fits'
                % self.dir)
            export_image_to_fits(
                restored[centre],
                '%s/test_pipelines_continuum_imaging_pipeline_arlexecute_restored.fits'
                % self.dir)

        qa = qa_image(restored[centre])
        assert numpy.abs(qa.data['max'] - 100.13762476849081) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.03627273884170454) < 1.0, str(qa)
    def test_continuum_imaging_pipeline(self):
        self.actualSetUp(add_errors=False, block=True)
        continuum_imaging_list = \
            continuum_imaging_list_arlexecute_workflow(self.vis_list, model_imagelist=self.model_imagelist, context='2d',
                                                       algorithm='mmclean', facets=1,
                                                       scales=[0, 3, 10],
                                                       niter=1000, fractional_threshold=0.1,
                                                       nmoments=2, nchan=self.freqwin,
                                                       threshold=2.0, nmajor=5, gain=0.1,
                                                       deconvolve_facets=8, deconvolve_overlap=16,
                                                       deconvolve_taper='tukey')
        clean, residual, restored = arlexecute.compute(continuum_imaging_list,
                                                       sync=True)
        export_image_to_fits(
            clean[0],
            '%s/test_pipelines_continuum_imaging_pipeline_clean.fits' %
            self.dir)
        export_image_to_fits(
            residual[0][0],
            '%s/test_pipelines_continuum_imaging_pipeline_residual.fits' %
            self.dir)
        export_image_to_fits(
            restored[0],
            '%s/test_pipelines_continuum_imaging_pipeline_restored.fits' %
            self.dir)

        qa = qa_image(restored[0])
        assert numpy.abs(qa.data['max'] - 116.9) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.118) < 1.0, str(qa)
Beispiel #12
0
    def test_ical_pipeline_global(self):
        self.actualSetUp(add_errors=True)
        controls = create_calibration_controls()
        controls['T']['first_selfcal'] = 1
        controls['T']['timeslice'] = 'auto'
        
        ical_list = \
            ical_list_arlexecute_workflow(self.vis_list,
                                          model_imagelist=self.model_imagelist,
                                          context='2d',
                                          algorithm='mmclean', facets=1,
                                          scales=[0, 3, 10],
                                          niter=1000, fractional_threshold=0.1, threshold=0.1,
                                          nmoment=3,
                                          nmajor=1, gain=0.1,
                                          deconvolve_facets=4, deconvolve_overlap=32,
                                          deconvolve_taper='tukey', psf_support=64,
                                          restore_facets=4, psfwidth=1.0,
                                          calibration_context='T', controls=controls, do_selfcal=True,
                                          global_solution=True)
        clean, residual, restored, gt_list = arlexecute.compute(ical_list, sync=True)
        centre = len(clean) // 2
        if self.persist:
            export_image_to_fits(clean[centre], '%s/test_pipelines_ical_global_pipeline_arlexecute_clean.fits' % self.dir)
            export_image_to_fits(residual[centre][0], '%s/test_pipelines_ical_global_pipeline_arlexecute_residual.fits' % self.dir)
            export_image_to_fits(restored[centre], '%s/test_pipelines_ical_global_pipeline_arlexecute_restored.fits' % self.dir)
            export_gaintable_to_hdf5(gt_list[0]['T'],
                                     '%s/test_pipelines_ical_global_pipeline_arlexecute_gaintable.hdf5' %
                                     self.dir)

        qa = qa_image(restored[centre])
        assert numpy.abs(qa.data['max'] - 98.92656340122159) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.7024492707920869) < 1.0, str(qa)
    def test_ical_pipeline(self):
        amp_errors = {'T': 0.0, 'G': 0.00, 'B': 0.0}
        phase_errors = {'T': 0.1, 'G': 0.0, 'B': 0.0}
        self.actualSetUp(add_errors=True,
                         block=True,
                         amp_errors=amp_errors,
                         phase_errors=phase_errors)

        controls = create_calibration_controls()

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

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

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

        qa = qa_image(restored[centre])
        assert numpy.abs(qa.data['max'] - 100.13739440876233) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.03644435471804354) < 1.0, str(qa)
    def test_ical_pipeline(self):
        self.actualSetUp(add_errors=True)
        controls = create_calibration_controls()
        controls['T']['first_selfcal'] = 1
        controls['T']['timescale'] = 'auto'

        ical_list = \
            ical_list_arlexecute_workflow(self.vis_list,
                                          model_imagelist=self.model_imagelist,
                                          context='2d',
                                          algorithm='mmclean', facets=1,
                                          scales=[0, 3, 10],
                                          niter=1000, fractional_threshold=0.1, threshold=0.1,
                                          nmoment=3,
                                          nmajor=1, gain=0.1,
                                          deconvolve_facets=4, deconvolve_overlap=32,
                                          deconvolve_taper='tukey', psf_support=64,
                                          calibration_context='T', controls=controls, do_selfcal=True,
                                          global_solution=False)
        clean, residual, restored = arlexecute.compute(ical_list, sync=True)
        centre = len(clean) // 2
        if self.persist:
            export_image_to_fits(
                clean[centre],
                '%s/test_pipelines_ical_pipeline_arlexecute_clean.fits' %
                self.dir)
            export_image_to_fits(
                residual[centre][0],
                '%s/test_pipelines_ical_pipeline_arlexecute_residual.fits' %
                self.dir)
            export_image_to_fits(
                restored[centre],
                '%s/test_pipelines_ical_pipeline_arlexecute_restored.fits' %
                self.dir)

        qa = qa_image(restored[centre])
        assert numpy.abs(qa.data['max'] - 99.32729396999524) < 1.0, str(qa)
        assert numpy.abs(qa.data['min'] + 0.6501547522800477) < 1.0, str(qa)
def trial_case(results, seed=180555, context='wstack', nworkers=8, threads_per_worker=1, memory=8,
               processes=True, order='frequency', nfreqwin=7, ntimes=3, rmax=750.0,
               facets=1, wprojection_planes=1, use_dask=True, use_serial_imaging=False,
               flux_limit=0.3, nmajor=5, dft_threshold=1.0):
    """ Single trial for performance-timings
    
    Simulates visibilities from GLEAM including phase errors
    Makes dirty image and PSF
    Runs ICAL pipeline
    
    The results are in a dictionary:
    
    'context': input - a string describing concisely the purpose of the test
    'time overall',  overall execution time (s)
    'time create gleam', time to create GLEAM prediction graph
    'time predict', time to execute GLEAM prediction graph
    'time corrupt', time to corrupt data_models
    'time invert', time to make dirty image
    'time psf invert', time to make PSF
    'time ICAL graph', time to create ICAL graph
    'time ICAL', time to execute ICAL graph
    'context', type of imaging e.g. 'wstack'
    'nworkers', number of workers to create
    'threads_per_worker',
    'nnodes', Number of nodes,
    'processes', 'order', Ordering of data_models
    'nfreqwin', Number of frequency windows in simulation
    'ntimes', Number of hour angles in simulation
    'rmax', Maximum radius of stations used in simulation (m)
    'facets', Number of facets in deconvolution and imaging
    'wprojection_planes', Number of wprojection planes
    'vis_slices', Number of visibility slices (per Visibbility)
    'npixel', Number of pixels in image
    'cellsize', Cellsize in radians
    'seed', Random number seed
    'dirty_max', Maximum in dirty image
    'dirty_min', Minimum in dirty image
    'psf_max',
    'psf_min',
    'restored_max',
    'restored_min',
    'deconvolved_max',
    'deconvolved_min',
    'residual_max',
    'residual_min',
    'git_info', GIT hash (not definitive since local mods are possible)
    
    :param results: Initial state
    :param seed: Random number seed (used in gain simulations)
    :param context: imaging context
    :param context: Type of context: '2d'|'timeslice'|'wstack'
    :param nworkers: Number of dask workers to use
    :param threads_per_worker: Number of threads per worker
    :param processes: Use processes instead of threads 'processes'|'threads'
    :param order: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param nfreqwin: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param ntimes: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param rmax: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param facets: Number of facets to use
    :param wprojection_planes: Number of wprojection planes to use
    :param use_dask: Use dask or immediate evaluation
    :return: results dictionary
    """
    if use_dask:
        client = get_dask_Client(threads_per_worker=threads_per_worker,
                                 processes = threads_per_worker == 1,
                                 memory_limit=memory * 1024 * 1024 * 1024,
                                 n_workers=nworkers)
        arlexecute.set_client(client)
        nodes = findNodes(arlexecute.client)
        print("Defined %d workers on %d nodes" % (nworkers, len(nodes)))
        print("Workers are: %s" % str(nodes))
    else:
        arlexecute.set_client(use_dask=use_dask)
        results['nnodes'] = 1

    def init_logging():
        logging.basicConfig(filename='pipelines-arlexecute-timings.log',
                            filemode='a',
                            format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
                            datefmt='%H:%M:%S',
                            level=logging.INFO)

    init_logging()
    log = logging.getLogger()
    
    # Initialise logging on the workers. This appears to only work using the process scheduler.
    arlexecute.run(init_logging)

    
    def lprint(s):
        log.info(s)
        print(s)
    
    lprint("Starting pipelines-arlexecute-timings")
    
    numpy.random.seed(seed)
    results['seed'] = seed
    
    start_all = time.time()
    
    results['context'] = context
    results['hostname'] = socket.gethostname()
    results['git_hash'] = git_hash()
    results['epoch'] = time.strftime("%Y-%m-%d %H:%M:%S")
    
    lprint("Context is %s" % context)
    
    results['nworkers'] = nworkers
    results['threads_per_worker'] = threads_per_worker
    results['processes'] = processes
    results['memory'] = memory
    results['order'] = order
    results['nfreqwin'] = nfreqwin
    results['ntimes'] = ntimes
    results['rmax'] = rmax
    results['facets'] = facets
    results['wprojection_planes'] = wprojection_planes
    results['dft threshold'] = dft_threshold
    
    results['use_dask'] = use_dask
    
    lprint("At start, configuration is:")
    lprint(results)
    
    # Parameters determining scale
    frequency = numpy.linspace(1.0e8, 1.2e8, nfreqwin)
    centre = nfreqwin // 2
    if nfreqwin > 1:
        channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]])
    else:
        channel_bandwidth = numpy.array([1e6])
    
    times = numpy.linspace(-numpy.pi / 4.0, numpy.pi / 4.0, ntimes)
    phasecentre = SkyCoord(ra=+30.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
    
    bvis_list = simulate_list_arlexecute_workflow('LOWBD2',
                                                  frequency=frequency,
                                                  channel_bandwidth=channel_bandwidth,
                                                  times=times,
                                                  phasecentre=phasecentre,
                                                  order=order,
                                                  format='blockvis',
                                                  rmax=rmax)
    
    lprint("****** Visibility creation ******")
    bvis_list = arlexecute.compute(bvis_list, sync=True)
    
    vis_list = [arlexecute.execute(convert_blockvisibility_to_visibility(bv)) for bv in bvis_list]
    vis_list = arlexecute.compute(vis_list, sync=True)
    
    # Find the best imaging parameters but don't bring the vis_list back here
    def get_wf(v):
        return advise_wide_field(v, guard_band_image=6.0,
                                 delA=0.1,
                                 facets=facets,
                                 wprojection_planes=wprojection_planes,
                                 oversampling_synthesised_beam=4.0)
    
    advice = arlexecute.compute(arlexecute.execute(get_wf)(vis_list[-1]), sync=True)
    
    # Deconvolution via sub-images requires 2^n
    npixel = advice['npixels2']
    results['npixel'] = npixel
    cellsize = advice['cellsize']
    results['cellsize'] = cellsize
    lprint("Image will have %d by %d pixels, cellsize = %.6f rad" % (npixel, npixel, cellsize))
    
    # Create an empty model image
    model_list = [arlexecute.execute(create_image_from_visibility)
                  (vis_list[f],
                   npixel=npixel, cellsize=cellsize,
                   frequency=[frequency[f]],
                   channel_bandwidth=[channel_bandwidth[f]],
                   polarisation_frame=PolarisationFrame("stokesI"))
                  for f, freq in enumerate(frequency)]
    model_list = arlexecute.compute(model_list, sync=True)
    model_list = arlexecute.scatter(model_list)
    
    start = time.time()
    vis_list = weight_list_arlexecute_workflow(vis_list, model_list)
    vis_list = taper_list_arlexecute_workflow(vis_list, 0.003 * 750.0 / rmax)
    print("****** Starting weighting and tapering ******")
    vis_list = arlexecute.compute(vis_list, sync=True)
    end = time.time()
    results['time weight'] = end - start
    print("Weighting took %.3f seconds" % (end - start))
    vis_list = arlexecute.scatter(vis_list)
    
    # Now set up the imaging parameters
    gcfcf_list = [None for i in range(nfreqwin)]
    
    if context == 'timeslice':
        vis_slices = ntimes
        lprint("Using timeslice with %d slices" % vis_slices)
    elif context == '2d':
        vis_slices = 1
    elif context == "wprojection":
        wstep = advice['wstep']
        nw = advice['wprojection_planes']
        vis_slices = 1
        support = advice['nwpixels']
        results['wprojection_planes'] = nw
        lprint("Using wprojection with %d planes with wstep %.1f wavelengths" % (nw, wstep))
        
        start = time.time()
        lprint("****** Starting W projection kernel creation ******")
        gcfcf_list = [arlexecute.execute(create_awterm_convolutionfunction, nout=1)
                      (m, nw=nw, wstep=wstep, oversampling=8, support=support, use_aaf=True)
                      for m in model_list]
        gcfcf_list = arlexecute.compute(gcfcf_list, sync=True)
        end = time.time()
        results['time create wprojection'] = end - start
        lprint("Creating W projection kernel took %.3f seconds" % (end - start))
        cf_image = convert_convolutionfunction_to_image(gcfcf_list[centre][1])
        cf_image.data = numpy.real(cf_image.data)
        export_image_to_fits(cf_image, "pipelines-arlexecute-timings-wterm-cf.fits")
        gcfcf_list = arlexecute.scatter(gcfcf_list)
    
    else:
        context = 'wstack'
        vis_slices = advice['vis_slices']
        lprint("Using wstack with %d slices" % vis_slices)
    
    results['vis_slices'] = vis_slices
    
    # Make a skymodel from gleam, with bright sources as components and weak sources in an image
    lprint("****** Starting GLEAM skymodel creation ******")
    start = time.time()
    skymodel_list = [arlexecute.execute(create_low_test_skymodel_from_gleam)
                     (npixel=npixel, cellsize=cellsize, frequency=[frequency[f]],
                      phasecentre=phasecentre,
                      polarisation_frame=PolarisationFrame("stokesI"),
                      flux_limit=flux_limit,
                      flux_threshold=dft_threshold,
                      flux_max=5.0) for f, freq in enumerate(frequency)]
    skymodel_list = arlexecute.compute(skymodel_list, sync=True)
    end = time.time()
    lprint("GLEAM skymodel creation took %.3f seconds" % (end - start))
    results['time create gleam'] = end - start
    
    lprint("****** Starting GLEAM skymodel prediction ******")
    start = time.time()
    predicted_vis_list = [predict_skymodel_list_arlexecute_workflow(vis_list[f], [skymodel_list[f]], context=context,
                                                                   vis_slices=vis_slices, facets=facets,
                                                                   gcfcf=[gcfcf_list[f]])[0]
                          for f, freq in enumerate(frequency)]
    predicted_vis_list = arlexecute.compute(predicted_vis_list, sync=True)
    end = time.time()
    lprint("GLEAM skymodel prediction took %.3f seconds" % (end - start))
    results['time predict gleam'] = end - start
    
    lprint("****** Starting psf image calculation ******")
    start = time.time()
    predicted_vis_list = arlexecute.scatter(predicted_vis_list)
    psf_list = invert_list_arlexecute_workflow(predicted_vis_list, model_list, vis_slices=vis_slices,
                                               dopsf=True, context=context, facets=facets,
                                               use_serial_invert=use_serial_imaging, gcfcf=gcfcf_list)
    psf, sumwt = arlexecute.compute(psf_list, sync=True)[centre]
    end = time.time()
    results['time psf invert'] = end - start
    lprint("PSF invert took %.3f seconds" % (end - start))
    lprint("Maximum in psf image is %f, sumwt is %s" % (numpy.max(numpy.abs(psf.data)), str(sumwt)))
    qa = qa_image(psf)
    results['psf_max'] = qa.data['max']
    results['psf_min'] = qa.data['min']
    export_image_to_fits(psf, "pipelines-arlexecute-timings-%s-psf.fits" % context)
    
    # Make a smoothed model image for comparison
    
    # smoothed_model_list = restore_list_arlexecute_workflow(gleam_model_list, psf_list)
    # smoothed_model_list = arlexecute.compute(smoothed_model_list, sync=True)
    # smoothed_cube = image_gather_channels(smoothed_model_list)
    # export_image_to_fits(smoothed_cube, "pipelines-arlexecute-timings-cmodel.fits")
    
    # Create an empty model image
    model_list = [arlexecute.execute(create_image_from_visibility)
                  (predicted_vis_list[f],
                   npixel=npixel, cellsize=cellsize,
                   frequency=[frequency[f]],
                   channel_bandwidth=[channel_bandwidth[f]],
                   polarisation_frame=PolarisationFrame("stokesI"))
                  for f, freq in enumerate(frequency)]
    model_list = arlexecute.compute(model_list, sync=True)
    model_list = arlexecute.scatter(model_list)
    
    lprint("****** Starting dirty image calculation ******")
    start = time.time()
    dirty_list = invert_list_arlexecute_workflow(predicted_vis_list, model_list, vis_slices=vis_slices,
                                                 context=context, facets=facets,
                                                 use_serial_invert=use_serial_imaging, gcfcf=gcfcf_list)
    dirty, sumwt = arlexecute.compute(dirty_list, sync=True)[centre]
    end = time.time()
    results['time invert'] = end - start
    lprint("Dirty image invert took %.3f seconds" % (end - start))
    lprint("Maximum in dirty image is %f, sumwt is %s" % (numpy.max(numpy.abs(dirty.data)), str(sumwt)))
    qa = qa_image(dirty)
    results['dirty_max'] = qa.data['max']
    results['dirty_min'] = qa.data['min']
    export_image_to_fits(dirty, "pipelines-arlexecute-timings-%s-dirty.fits" % context)
    
    # Corrupt the visibility for the GLEAM model
    lprint("****** Visibility corruption ******")
    start = time.time()
    corrupted_vis_list = corrupt_list_arlexecute_workflow(predicted_vis_list, phase_error=1.0, seed=seed)
    corrupted_vis_list = arlexecute.compute(corrupted_vis_list, sync=True)
    end = time.time()
    results['time corrupt'] = end - start
    lprint("Visibility corruption took %.3f seconds" % (end - start))
    
    # Create the ICAL pipeline to run major cycles, starting selfcal at cycle 1. A global solution across all
    # frequencies (i.e. Visibilities) is performed.
    lprint("****** Starting ICAL ******")
    
    controls = create_calibration_controls()
    
    controls['T']['first_selfcal'] = 1
    controls['T']['timescale'] = 'auto'
    
    start = time.time()
    ical_list = ical_list_arlexecute_workflow(corrupted_vis_list,
                                              model_imagelist=model_list,
                                              context=context,
                                              vis_slices=vis_slices,
                                              scales=[0, 3, 10],
                                              algorithm='mmclean',
                                              nmoment=3, niter=1000,
                                              fractional_threshold=0.1,
                                              threshold=0.01, nmajor=nmajor,
                                              gain=0.25,
                                              psf_support=64,
                                              deconvolve_facets=8,
                                              deconvolve_overlap=32,
                                              deconvolve_taper='tukey',
                                              timeslice='auto',
                                              global_solution=True,
                                              do_selfcal=True,
                                              calibration_context='T',
                                              controls=controls,
                                              use_serial_predict=use_serial_imaging,
                                              use_serial_invert=use_serial_imaging,
                                              gcfcf=gcfcf_list)
    end = time.time()
    results['time ICAL graph'] = end - start
    lprint("Construction of ICAL graph took %.3f seconds" % (end - start))
    
    # Execute the graph
    start = time.time()
    result = arlexecute.compute(ical_list, sync=True)
    deconvolved, residual, restored, gaintables = result
    end = time.time()
    
    results['time ICAL'] = end - start
    lprint("ICAL graph execution took %.3f seconds" % (end - start))
    qa = qa_image(deconvolved[centre])
    results['deconvolved_max'] = qa.data['max']
    results['deconvolved_min'] = qa.data['min']
    deconvolved_cube = image_gather_channels(deconvolved)
    export_image_to_fits(deconvolved_cube, "pipelines-arlexecute-timings-%s-ical_deconvolved.fits" % context)
    
    qa = qa_image(residual[centre][0])
    results['residual_max'] = qa.data['max']
    results['residual_min'] = qa.data['min']
    residual_cube = remove_sumwt(residual)
    residual_cube = image_gather_channels(residual_cube)
    export_image_to_fits(residual_cube, "pipelines-arlexecute-timings-%s-ical_residual.fits" % context)
    
    qa = qa_image(restored[centre])
    results['restored_max'] = qa.data['max']
    results['restored_min'] = qa.data['min']
    restored_cube = image_gather_channels(restored)
    export_image_to_fits(restored_cube, "pipelines-arlexecute-timings-%s-ical_restored.fits" % context)
    #
    arlexecute.close()
    
    end_all = time.time()
    results['time overall'] = end_all - start_all
    
    lprint("At end, results are:")
    lprint(results)
    
    return results
    log.info('About to run ical_list_serial_workflow')
    result = arlexecute.compute(ical_list, sync=True)
    deconvolved = result[0][0]
    residual = result[1][0]
    restored = result[2][0]
    arlexecute.close()

    show_image(deconvolved,
               title='Clean image',
               cm='Greys',
               vmax=0.1,
               vmin=-0.01)
    print(qa_image(deconvolved, context='Clean image'))
    plt.show()
    export_image_to_fits(
        deconvolved,
        '%s/gleam_ical_arlexecute_deconvolved.fits' % (results_dir))

    show_image(restored,
               title='Restored clean image',
               cm='Greys',
               vmax=0.1,
               vmin=-0.01)
    print(qa_image(restored, context='Restored clean image'))
    plt.show()
    export_image_to_fits(
        restored, '%s/gleam_ical_arlexecute_restored.fits' % (results_dir))

    show_image(residual[0],
               title='Residual clean image',
               cm='Greys',
Beispiel #17
0
    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, -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 = [
            arlexecute.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 = arlexecute.compute(self.blockvis_list, sync=True)
        self.blockvis_list = arlexecute.scatter(self.blockvis_list)

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

        self.model_imagelist = [
            arlexecute.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 = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        self.model_imagelist = arlexecute.scatter(self.model_imagelist)

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

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

        self.model_imagelist = [
            arlexecute.execute(insert_skycomponent,
                               nout=1)(self.model_imagelist[freqwin],
                                       self.components_list[freqwin])
            for freqwin in range(nfreqwin)
        ]
        self.model_imagelist = arlexecute.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_arlexecute_model.fits' % self.dir)
            export_image_to_fits(
                self.cmodel,
                '%s/test_pipelines_arlexecute_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,
                                    seed=180555)
            self.blockvis_list = [
                arlexecute.execute(apply_gaintable,
                                   nout=1)(self.blockvis_list[i], gt)
                for i in range(self.freqwin)
            ]
            self.blockvis_list = arlexecute.compute(self.blockvis_list,
                                                    sync=True)
            self.blockvis_list = arlexecute.scatter(self.blockvis_list)

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

        self.model_imagelist = [
            arlexecute.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 = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        self.model_imagelist = arlexecute.scatter(self.model_imagelist)
Beispiel #18
0
            d, sumwt = invert_list_serial_workflow([v], [m], context=context, dopsf=False,
                                                   vis_slices=vis_slices)[0]
            p, sumwt = invert_list_serial_workflow([v], [m], context=context, dopsf=True,
                                                   vis_slices=vis_slices)[0]
        c, resid = deconvolve_cube(d, p, m, threshold=0.01, fracthresh=0.01, window_shape='quarter',
                                   niter=100, gain=0.1, algorithm='hogbom-complex')
        r = restore_cube(c, p, resid, psfwidth=psfwidth)
        return r
    
    def do_list(chan_list):
        print("In rank %d: %s" % (rank, str(chan_list)))
        return [load_invert_and_deconvolve(chan) for chan in chan_list]
    
    if rank == 0:
        subchannels = numpy.array_split(range(nchan), size)
    else:
        subchannels = list()
    
    channels = comm.scatter(subchannels, root=0)
    restored_images = do_list(channels)
    restored_list = comm.gather(restored_images)

    if rank ==0:
        print('About to assemble cubes')
        restored_list = [item for sublist in restored_list for item in sublist]
        restored_cube = image_gather_channels(restored_list)
        print("Processing took %.3f s" % (time.time() - start))

        print(qa_image(restored_cube, context='CLEAN restored cube'))
        export_image_to_fits(restored_cube, '%s/dprepb_arlexecute_%s_clean_restored_cube.fits' % (results_dir, context))
Beispiel #19
0
    print(qa_image(residual, context='ICAL residual image'))

    print('ical finished')

    combined_model = calculate_skymodel_equivalent_image(ical_skymodel)
    print(qa_image(combined_model, context='ICAL combined model'))
    psf_obs = invert_list_arlexecute_workflow([future_vis], [future_model],
                                              context='2d',
                                              dopsf=True)
    result = restore_list_arlexecute_workflow([combined_model], psf_obs,
                                              [(residual, 0.0)])
    result = arlexecute.compute(result, sync=True)
    ical_restored = result[0]

    export_image_to_fits(
        ical_restored,
        arl_path('test_results/low-sims-mpc-ical-restored_%.1frmax.fits' %
                 rmax))

    #######################################################################################################
    # Now set up the skymodels for MPCCAL. We find the brightest components in the ICAL image, remove
    # sources that are too close to another stronger source, and then use these to set up
    # a Voronoi tesselation to define the skymodel masks

    ical_components = find_skycomponents(ical_restored,
                                         fwhm=2,
                                         threshold=args.finding_threshold,
                                         npixels=12)
    for comp in all_components[:args.ninitial]:
        ical_components.append(comp)

    # ### Remove weaker of components that are too close (0.02 rad)
def trial_case(results,
               seed=180555,
               context='wstack',
               nworkers=8,
               threads_per_worker=1,
               memory=8,
               processes=True,
               order='frequency',
               nfreqwin=7,
               ntimes=3,
               rmax=750.0,
               facets=1,
               wprojection_planes=1,
               use_dask=True,
               use_serial_imaging=True,
               flux_limit=0.3,
               nmajor=5,
               dft_threshold=1.0,
               use_serial_clean=True,
               write_fits=False):
    """ Single trial for performance-timings
    
    Simulates visibilities from GLEAM including phase errors
    Makes dirty image and PSF
    Runs ICAL pipeline
    
    The results are in a dictionary:
    
    'context': input - a string describing concisely the purpose of the test
    'time overall',  overall execution time (s)
    'time predict', time to execute GLEAM prediction graph
    'time invert', time to make dirty image
    'time invert graph', time to make dirty image graph
    'time ICAL graph', time to create ICAL graph
    'time ICAL', time to execute ICAL graph
    'context', type of imaging e.g. 'wstack'
    'nworkers', number of workers to create
    'threads_per_worker',
    'nnodes', Number of nodes,
    'processes', 'order', Ordering of data_models
    'nfreqwin', Number of frequency windows in simulation
    'ntimes', Number of hour angles in simulation
    'rmax', Maximum radius of stations used in simulation (m)
    'facets', Number of facets in deconvolution and imaging
    'wprojection_planes', Number of wprojection planes
    'vis_slices', Number of visibility slices (per Visibbility)
    'npixel', Number of pixels in image
    'cellsize', Cellsize in radians
    'seed', Random number seed
    'dirty_max', Maximum in dirty image
    'dirty_min', Minimum in dirty image
    'restored_max',
    'restored_min',
    'deconvolved_max',
    'deconvolved_min',
    'residual_max',
    'residual_min',
    'git_info', GIT hash (not definitive since local mods are possible)
    
    :param results: Initial state
    :param seed: Random number seed (used in gain simulations)
    :param context: imaging context
    :param context: Type of context: '2d'|'timeslice'|'wstack'
    :param nworkers: Number of dask workers to use
    :param threads_per_worker: Number of threads per worker
    :param processes: Use processes instead of threads 'processes'|'threads'
    :param order: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param nfreqwin: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param ntimes: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param rmax: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param facets: Number of facets to use
    :param wprojection_planes: Number of wprojection planes to use
    :param use_dask: Use dask or immediate evaluation
    :return: results dictionary
    """
    if use_dask:
        client = get_dask_Client(threads_per_worker=threads_per_worker,
                                 processes=threads_per_worker == 1,
                                 memory_limit=memory * 1024 * 1024 * 1024,
                                 n_workers=nworkers)
        arlexecute.set_client(client)
        nodes = findNodes(arlexecute.client)
        print("Defined %d workers on %d nodes" % (nworkers, len(nodes)))
        print("Workers are: %s" % str(nodes))
    else:
        arlexecute.set_client(use_dask=use_dask)
        results['nnodes'] = 1

    def init_logging():
        logging.basicConfig(
            filename='pipelines_arlexecute_timings.log',
            filemode='w',
            format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
            datefmt='%H:%M:%S',
            level=logging.INFO)

    init_logging()
    log = logging.getLogger()

    # Initialise logging on the workers. This appears to only work using the process scheduler.
    arlexecute.run(init_logging)

    def lprint(*args):
        log.info(*args)
        print(*args)

    lprint("Starting pipelines_arlexecute_timings")

    numpy.random.seed(seed)
    results['seed'] = seed

    start_all = time.time()

    results['context'] = context
    results['hostname'] = socket.gethostname()
    results['git_hash'] = git_hash()
    results['epoch'] = time.strftime("%Y-%m-%d %H:%M:%S")

    lprint("Context is %s" % context)

    results['nworkers'] = nworkers
    results['threads_per_worker'] = threads_per_worker
    results['processes'] = processes
    results['memory'] = memory
    results['order'] = order
    results['nfreqwin'] = nfreqwin
    results['ntimes'] = ntimes
    results['rmax'] = rmax
    results['facets'] = facets
    results['wprojection_planes'] = wprojection_planes
    results['dft threshold'] = dft_threshold

    results['use_dask'] = use_dask

    lprint("At start, configuration is:")
    lprint(sort_dict(results))

    # Parameters determining scale of simulation.
    frequency = numpy.linspace(1.0e8, 1.2e8, nfreqwin)
    centre = nfreqwin // 2
    if nfreqwin > 1:
        channel_bandwidth = numpy.array(nfreqwin *
                                        [frequency[1] - frequency[0]])
    else:
        channel_bandwidth = numpy.array([1e6])

    times = numpy.linspace(-numpy.pi / 4.0, numpy.pi / 4.0, ntimes)
    phasecentre = SkyCoord(ra=+0.0 * u.deg,
                           dec=-40.0 * u.deg,
                           frame='icrs',
                           equinox='J2000')

    lprint("****** Visibility creation ******")
    # Create the empty BlockVisibility's and persist these on the cluster
    tmp_bvis_list = simulate_list_arlexecute_workflow(
        'LOWBD2',
        frequency=frequency,
        channel_bandwidth=channel_bandwidth,
        times=times,
        phasecentre=phasecentre,
        order=order,
        format='blockvis',
        rmax=rmax)
    tmp_vis_list = [
        arlexecute.execute(convert_blockvisibility_to_visibility)(bv)
        for bv in tmp_bvis_list
    ]
    tmp_vis_list = arlexecute.client.compute(tmp_vis_list, sync=True)
    vis_list = arlexecute.gather(tmp_vis_list)

    import matplotlib.pyplot as plt
    plt.clf()
    plt.hist(vis_list[0].w, bins=100)
    plt.title('Histogram of w samples: rms=%.1f (wavelengths)' %
              numpy.std(vis_list[0].w))
    plt.xlabel('W (wavelengths)')
    plt.show()
    plt.clf()
    plt.hist(vis_list[0].uvdist, bins=100)
    plt.title('Histogram of uvdistance samples')
    plt.xlabel('UV Distance (wavelengths)')
    plt.show()

    arlexecute.client.cancel(tmp_vis_list)
    future_vis_list = arlexecute.scatter(vis_list)

    # Find the best imaging parameters but don't bring the vis_list back here
    print("****** Finding wide field parameters ******")
    future_advice = [
        arlexecute.execute(advise_wide_field)(
            v,
            guard_band_image=6.0,
            delA=0.1,
            facets=facets,
            wprojection_planes=wprojection_planes,
            oversampling_synthesised_beam=4.0) for v in future_vis_list
    ]

    future_advice = arlexecute.compute(future_advice)
    advice = arlexecute.client.gather(future_advice)[-1]
    arlexecute.client.cancel(future_advice)

    # Deconvolution via sub-images requires 2^n
    npixel = advice['npixels2']
    results['npixel'] = npixel
    cellsize = advice['cellsize']
    results['cellsize'] = cellsize
    lprint("Image will have %d by %d pixels, cellsize = %.6f rad" %
           (npixel, npixel, cellsize))

    # Create an empty model image
    tmp_model_list = [
        arlexecute.execute(create_image)(
            npixel=npixel,
            cellsize=cellsize,
            frequency=[frequency[f]],
            channel_bandwidth=[channel_bandwidth[f]],
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"))
        for f, freq in enumerate(frequency)
    ]
    model_list = arlexecute.compute(tmp_model_list, sync=True)
    future_model_list = arlexecute.scatter(model_list)

    lprint("****** Setting up imaging parameters ******")
    # Now set up the imaging parameters
    template_model = create_image(
        npixel=npixel,
        cellsize=cellsize,
        frequency=[frequency[centre]],
        phasecentre=phasecentre,
        channel_bandwidth=[channel_bandwidth[centre]],
        polarisation_frame=PolarisationFrame("stokesI"))
    gcfcf = [create_pswf_convolutionfunction(template_model)]

    if context == 'timeslice':
        vis_slices = ntimes
        lprint("Using timeslice with %d slices" % vis_slices)
    elif context == '2d':
        vis_slices = 1
    elif context == "wprojection":
        wstep = advice['wstep']
        nw = advice['wprojection_planes']
        vis_slices = 1
        support = advice['nwpixels']
        results['wprojection_planes'] = nw

        lprint("****** Starting W projection kernel creation ******")
        lprint("Using wprojection with %d planes with wstep %.1f wavelengths" %
               (nw, wstep))
        lprint("Support of wprojection = %d pixels" % support)
        gcfcf = [
            create_awterm_convolutionfunction(template_model,
                                              nw=nw,
                                              wstep=wstep,
                                              oversampling=4,
                                              support=support,
                                              use_aaf=True)
        ]
        lprint("Size of W projection gcf, cf = %.2E bytes" % get_size(gcfcf))
    else:
        context = 'wstack'
        vis_slices = advice['vis_slices']
        lprint("Using wstack with %d slices" % vis_slices)

    gcfcf = arlexecute.scatter(gcfcf, broadcast=True)

    results['vis_slices'] = vis_slices

    # Make a skymodel from gleam, with bright sources as components and weak sources in an image
    lprint("****** Starting GLEAM skymodel creation ******")
    future_skymodel_list = [
        arlexecute.execute(create_low_test_skymodel_from_gleam)(
            npixel=npixel,
            cellsize=cellsize,
            frequency=[frequency[f]],
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            flux_limit=flux_limit,
            flux_threshold=dft_threshold,
            flux_max=5.0) for f, freq in enumerate(frequency)
    ]

    # We use predict_skymodel so that we can use skycomponents as well as images
    lprint("****** Starting GLEAM skymodel prediction ******")
    predicted_vis_list = [
        predict_skymodel_list_arlexecute_workflow(future_vis_list[f],
                                                  [future_skymodel_list[f]],
                                                  context=context,
                                                  vis_slices=vis_slices,
                                                  facets=facets,
                                                  gcfcf=gcfcf)[0]
        for f, freq in enumerate(frequency)
    ]

    # Corrupt the visibility for the GLEAM model
    lprint("****** Visibility corruption ******")
    tmp_corrupted_vis_list = corrupt_list_arlexecute_workflow(
        predicted_vis_list, phase_error=1.0, seed=seed)
    lprint("****** Weighting and tapering ******")
    tmp_corrupted_vis_list = weight_list_arlexecute_workflow(
        tmp_corrupted_vis_list, future_model_list)
    tmp_corrupted_vis_list = taper_list_arlexecute_workflow(
        tmp_corrupted_vis_list, 0.003 * 750.0 / rmax)
    tmp_corrupted_vis_list = arlexecute.compute(tmp_corrupted_vis_list,
                                                sync=True)

    corrupted_vis_list = arlexecute.gather(tmp_corrupted_vis_list)
    # arlexecute.client.cancel(predicted_vis_list)
    arlexecute.client.cancel(tmp_corrupted_vis_list)
    future_corrupted_vis_list = arlexecute.scatter(corrupted_vis_list)

    # At this point the only futures are of scatter'ed data so no repeated calculations should be
    # incurred.
    lprint("****** Starting dirty image calculation ******")
    start = time.time()
    dirty_list = invert_list_arlexecute_workflow(
        future_corrupted_vis_list,
        future_model_list,
        vis_slices=vis_slices,
        context=context,
        facets=facets,
        use_serial_invert=use_serial_imaging,
        gcfcf=gcfcf)
    results['size invert graph'] = get_size(dirty_list)
    lprint('Size of dirty graph is %.3E bytes' %
           (results['size invert graph']))
    end = time.time()
    results['time invert graph'] = end - start
    lprint("Construction of invert graph took %.3f seconds" % (end - start))

    start = time.time()
    dirty, sumwt = arlexecute.compute(dirty_list, sync=True)[centre]
    end = time.time()
    results['time invert'] = end - start
    lprint("Dirty image invert took %.3f seconds" % (end - start))
    lprint("Maximum in dirty image is %f, sumwt is %s" %
           (numpy.max(numpy.abs(dirty.data)), str(sumwt)))
    qa = qa_image(dirty)
    results['dirty_max'] = qa.data['max']
    results['dirty_min'] = qa.data['min']
    if write_fits:
        export_image_to_fits(
            dirty, "pipelines_arlexecute_timings-%s-dirty.fits" % context)

    lprint("****** Starting prediction ******")
    start = time.time()
    tmp_vis_list = predict_list_arlexecute_workflow(
        future_corrupted_vis_list,
        future_model_list,
        vis_slices=vis_slices,
        context=context,
        facets=facets,
        use_serial_predict=use_serial_imaging,
        gcfcf=gcfcf)
    result = arlexecute.compute(tmp_vis_list, sync=True)
    # arlexecute.client.cancel(tmp_vis_list)
    end = time.time()
    results['time predict'] = end - start
    lprint("Predict took %.3f seconds" % (end - start))

    # Create the ICAL pipeline to run major cycles, starting selfcal at cycle 1. A global solution across all
    # frequencies (i.e. Visibilities) is performed.

    print("Using subimage clean")
    deconvolve_facets = 8
    deconvolve_overlap = 16
    deconvolve_taper = 'tukey'

    lprint("****** Starting ICAL graph creation ******")

    controls = create_calibration_controls()

    controls['T']['first_selfcal'] = 1
    controls['T']['timescale'] = 'auto'

    start = time.time()
    ical_list = ical_list_arlexecute_workflow(
        future_corrupted_vis_list,
        model_imagelist=future_model_list,
        context=context,
        vis_slices=vis_slices,
        scales=[0, 3, 10],
        algorithm='mmclean',
        nmoment=3,
        niter=1000,
        fractional_threshold=0.1,
        threshold=0.01,
        nmajor=nmajor,
        gain=0.25,
        psf_support=64,
        deconvolve_facets=deconvolve_facets,
        deconvolve_overlap=deconvolve_overlap,
        deconvolve_taper=deconvolve_taper,
        timeslice='auto',
        global_solution=True,
        do_selfcal=True,
        calibration_context='T',
        controls=controls,
        use_serial_predict=use_serial_imaging,
        use_serial_invert=use_serial_imaging,
        use_serial_clean=use_serial_clean,
        gcfcf=gcfcf)

    results['size ICAL graph'] = get_size(ical_list)
    lprint('Size of ICAL graph is %.3E bytes' % results['size ICAL graph'])
    end = time.time()
    results['time ICAL graph'] = end - start
    lprint("Construction of ICAL graph took %.3f seconds" % (end - start))

    print("Current objects on cluster: ")
    pp.pprint(arlexecute.client.who_has())
    #
    # Execute the graph
    lprint("****** Executing ICAL graph ******")
    start = time.time()
    deconvolved, residual, restored, gaintables = arlexecute.compute(ical_list,
                                                                     sync=True)
    end = time.time()

    results['time ICAL'] = end - start
    lprint("ICAL graph execution took %.3f seconds" % (end - start))
    qa = qa_image(deconvolved[centre])
    results['deconvolved_max'] = qa.data['max']
    results['deconvolved_min'] = qa.data['min']
    deconvolved_cube = image_gather_channels(deconvolved)
    if write_fits:
        export_image_to_fits(
            deconvolved_cube,
            "pipelines_arlexecute_timings-%s-ical_deconvolved.fits" % context)

    qa = qa_image(residual[centre][0])
    results['residual_max'] = qa.data['max']
    results['residual_min'] = qa.data['min']
    residual_cube = remove_sumwt(residual)
    residual_cube = image_gather_channels(residual_cube)
    if write_fits:
        export_image_to_fits(
            residual_cube,
            "pipelines_arlexecute_timings-%s-ical_residual.fits" % context)

    qa = qa_image(restored[centre])
    results['restored_max'] = qa.data['max']
    results['restored_min'] = qa.data['min']
    restored_cube = image_gather_channels(restored)
    if write_fits:
        export_image_to_fits(
            restored_cube,
            "pipelines_arlexecute_timings-%s-ical_restored.fits" % context)
    #
    arlexecute.close()

    end_all = time.time()
    results['time overall'] = end_all - start_all

    lprint("At end, results are:")
    results = sort_dict(results)
    lprint(results)

    return results
Beispiel #21
0
        chunk_final_pole_result = sum_invert_results_arlexecute(
            chunk_pole_results)
        pole_results.append(chunk_final_pole_result)

    # Now construct and run a graph to sum the results from the summations over each chunk
    final_result = sum_invert_results_arlexecute(results)
    dirty, sumwt = arlexecute.compute(final_result, sync=True)

    # We are done! make plots and fits files
    type = 'dirty'
    if dopsf:
        type = 'psf'

    if args.write_fits == "True":
        imagename = "simulate_rfi_%.1f_%s.fits" % (declination, type)
        export_image_to_fits(dirty, imagename)

    plt.clf()
    show_image(dirty, chan=len(frequency) // channel_average // 2)
    plotname = "simulate_rfi_%.1f_%s.png" % (declination, type)
    plt.title('Image of the target field')
    plt.savefig(plotname)
    plt.show(block=False)

    final_pole_result = sum_invert_results_arlexecute(pole_results)
    pole_dirty, pole_sumwt = arlexecute.compute(final_pole_result, sync=True)

    if args.write_fits == "True":
        imagename = "simulate_rfi_pole_%s.fits" % (type)
        export_image_to_fits(pole_dirty, imagename)
Beispiel #22
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 = [
            arlexecute.execute(ingest_unittest_visibility)(
                self.low, [self.frequency[freqwin]],
                [self.channelwidth[freqwin]],
                self.times,
                self.vis_pol,
                self.phasecentre,
                block=block,
                zerow=zerow) for freqwin, _ in enumerate(self.frequency)
        ]

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

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

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

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

        # Calculate the model convolved with a Gaussian.

        self.model_imagelist = arlexecute.compute(self.model_imagelist,
                                                  sync=True)
        model = self.model_imagelist[0]

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

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

        #        self.vis_list = arlexecute.compute(self.vis_list, sync=True)
        self.vis_list = arlexecute.persist(self.vis_list)
        self.model_imagelist = arlexecute.scatter(self.model_imagelist)
Beispiel #23
0
 def actualSetUp(self, add_errors=False, freqwin=3, block=False, dospectral=True, dopol=False, zerow=False,
                 makegcfcf=False):
     
     self.npixel = 256
     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])
     
     if dospectral:
         flux = numpy.array([f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
     else:
         flux = numpy.array([f])
     
     self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     self.vis_list = [arlexecute.execute(ingest_unittest_visibility)(self.low,
                                                                     [self.frequency[freqwin]],
                                                                     [self.channelwidth[freqwin]],
                                                                     self.times,
                                                                     self.vis_pol,
                                                                     self.phasecentre, block=block,
                                                                     zerow=zerow)
                      for freqwin, _ in enumerate(self.frequency)]
     
     self.model_list = [arlexecute.execute(create_unittest_model, nout=freqwin)(self.vis_list[freqwin],
                                                                                self.image_pol,
                                                                                cellsize=self.cellsize,
                                                                                npixel=self.npixel)
                        for freqwin, _ in enumerate(self.frequency)]
     
     self.components_list = [arlexecute.execute(create_unittest_components)(self.model_list[freqwin],
                                                                            flux[freqwin, :][numpy.newaxis, :],
                                                                            single=True)
                             for freqwin, _ in enumerate(self.frequency)]
     
     self.components_list = arlexecute.compute(self.components_list, sync=True)
     
     self.model_list = [arlexecute.execute(insert_skycomponent, nout=1)(self.model_list[freqwin],
                                                                        self.components_list[freqwin])
                        for freqwin, _ in enumerate(self.frequency)]
     
     self.model_list = arlexecute.compute(self.model_list, sync=True)
     
     self.vis_list = [arlexecute.execute(predict_skycomponent_visibility)(self.vis_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)
     export_image_to_fits(self.model, '%s/test_imaging_model.fits' % self.dir)
     export_image_to_fits(self.cmodel, '%s/test_imaging_cmodel.fits' % self.dir)
     
     if add_errors and block:
         self.vis_list = [arlexecute.execute(insert_unittest_errors)(self.vis_list[i])
                          for i, _ in enumerate(self.frequency)]
     
     self.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
Beispiel #24
0
 for chunk in chunks:
     result = predict_skymodel_list_arlexecute_workflow(future_vis, chunk, context='2d', docal=True)
     work_vis = arlexecute.compute(result, sync=True)
     for w in work_vis:
         all_skymodel_vis.data['vis'] += w.data['vis']
     assert numpy.max(numpy.abs(all_skymodel_vis.data['vis'])) > 0.0
 
 all_skymodel_blockvis = convert_visibility_to_blockvisibility(all_skymodel_vis)
 
 #######################################################################################################
 # Now proceed to run MPCCAL in ICAL mode i.e. with only one skymodel
 def progress(res, tl_list, gt_list, it, context='MPCCAL'):
     print('Iteration %d' % it)
     
     print(qa_image(res, context='%s residual image: iteration %d' % (context, it)))
     export_image_to_fits(res, arl_path("test_results/low-sims-mpc-%s-residual_iteration%d_rmax%.1f.fits" %
                                        (context, it, rmax)))
     show_image(res, title='%s residual image: iteration %d' % (context, it))
     plt.show(block=block_plots)
     
     combined_model = calculate_skymodel_equivalent_image(tl_list)
     print(qa_image(combined_model, context='Combined model: iteration %d' % it))
     export_image_to_fits(combined_model, arl_path("test_results/low-sims-mpc-%s-model_iteration%d_rmax%.1f.fits" %
                                                   (context, it, rmax)))
     
     plt.clf()
     for i in range(len(tl_list)):
         plt.plot(numpy.angle(tl_list[i].gaintable.gain[:, :, 0, 0, 0]).flatten(),
                  numpy.angle(gt_list[i]['T'].gain[:, :, 0, 0, 0]).flatten(),
                  '.')
     plt.xlabel('Current phase')
     plt.ylabel('Update to phase')
    def test_mpccal_MPCCAL_manysources_subimages(self):

        self.actualSetup()

        model = create_empty_image_like(self.theta_list[0].image)

        if arlexecute.using_dask:
            progress = None
        else:
            progress = self.progress

        future_vis = arlexecute.scatter(self.all_skymodel_noniso_vis)
        future_model = arlexecute.scatter(model)
        future_theta_list = arlexecute.scatter(self.theta_list)
        result = mpccal_skymodel_list_arlexecute_workflow(
            future_vis,
            future_model,
            future_theta_list,
            mpccal_progress=progress,
            nmajor=5,
            context='2d',
            algorithm='hogbom',
            scales=[0, 3, 10],
            fractional_threshold=0.3,
            threshold=0.2,
            gain=0.1,
            niter=1000,
            psf_support=256,
            deconvolve_facets=8,
            deconvolve_overlap=8,
            deconvolve_taper='tukey')

        (self.theta_list, residual) = arlexecute.compute(result, sync=True)

        combined_model = calculate_skymodel_equivalent_image(self.theta_list)

        psf_obs = invert_list_arlexecute_workflow(
            [self.all_skymodel_noniso_vis], [model], context='2d', dopsf=True)
        result = restore_list_arlexecute_workflow([combined_model], psf_obs,
                                                  [(residual, 0.0)])
        result = arlexecute.compute(result, sync=True)

        if self.persist:
            export_image_to_fits(
                residual,
                arl_path('test_results/test_mpccal_no_edge_residual.fits'))
        if self.persist:
            export_image_to_fits(
                result[0],
                arl_path('test_results/test_mpccal_no_edge_restored.fits'))
        if self.persist:
            export_image_to_fits(
                combined_model,
                arl_path('test_results/test_mpccal_no_edge_deconvolved.fits'))

        recovered_mpccal_components = find_skycomponents(result[0],
                                                         fwhm=2,
                                                         threshold=0.32,
                                                         npixels=12)

        def max_flux(elem):
            return numpy.max(elem.flux)

        recovered_mpccal_components = sorted(recovered_mpccal_components,
                                             key=max_flux,
                                             reverse=True)

        assert recovered_mpccal_components[
            0].name == 'Segment 8', recovered_mpccal_components[0].name
        assert numpy.abs(recovered_mpccal_components[0].flux[0, 0] - 7.773751416364857) < 1e-7, \
            recovered_mpccal_components[0].flux[0, 0]

        newscreen = create_empty_image_like(self.screen)
        gaintables = [th.gaintable for th in self.theta_list]
        newscreen, weights = grid_gaintable_to_screen(
            self.all_skymodel_noniso_blockvis, gaintables, newscreen)
        if self.persist:
            export_image_to_fits(
                newscreen,
                arl_path('test_results/test_mpccal_no_edge_screen.fits'))
        if self.persist:
            export_image_to_fits(
                weights,
                arl_path(
                    'test_results/test_mpccal_no_edge_screenweights.fits'))

        arlexecute.close()
    def actualSetup(self,
                    vnchan=1,
                    doiso=True,
                    ntimes=5,
                    flux_limit=2.0,
                    zerow=True,
                    fixed=False):

        nfreqwin = vnchan
        rmax = 300.0
        npixel = 512
        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=-60.0 * u.deg,
                               dec=-60.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"),
            zerow=zerow)

        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)

        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
            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_list_arlexecute_workflow(
            self.model_vis, self.beam, context='2d')
        export_image_to_fits(
            self.dirty_model,
            "%s/test_modelpartition-model_dirty.fits" % self.dir)

        lvis = convert_blockvisibility_to_visibility(self.vis)
        lvis, _, _ = weight_visibility(lvis, self.beam)
        dirty, sumwt = invert_list_arlexecute_workflow(lvis,
                                                       self.beam,
                                                       context='2d')
        if doiso:
            export_image_to_fits(
                dirty,
                "%s/test_modelpartition-initial-iso-residual.fits" % self.dir)
        else:
            export_image_to_fits(
                dirty, "%s/test_modelpartition-initial-noiso-residual.fits" %
                self.dir)

        self.skymodels = [
            SkyModel(components=[cm], fixed=fixed) for cm in self.components
        ]