def progress(self, res, tl_list, gt_list, it):
        """Write progress information
        
        Cannot use this if using Dask
        
        :param res: Residual image
        :param tl_list: Theta list
        :param gt_list: Gaintable list
        :param it: iteration
        :return:
        """

        combined_model = calculate_skymodel_equivalent_image(tl_list)

        import matplotlib.pyplot as plt
        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.xlim([-numpy.pi, numpy.pi])
        # plt.ylim([-numpy.pi, numpy.pi])
        plt.title("MPCCal iteration%d: Change in phase" % (it))
        plt.show()

        return tl_list
Ejemplo n.º 2
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
    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()
Ejemplo n.º 4
0
                                                      algorithm='hogbom',
                                                      fractional_threshold=0.3,
                                                      threshold=0.1,
                                                      gain=0.1,
                                                      niter=1000,
                                                      psf_support=512,
                                                      deconvolve_facets=8,
                                                      deconvolve_overlap=16,
                                                      deconvolve_taper='tukey')

    (ical_skymodel, residual) = arlexecute.compute(result, sync=True)
    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))

    #######################################################################################################