示例#1
0
    def test_mpccal_ICAL_onesource(self):

        self.actualSetup(nsources=1, nvoronoi=1)

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

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

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

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

        combined_model = calculate_skymodel_equivalent_image(self.theta_list)

        psf_obs = invert_list_rsexecute_workflow([self.all_skymodel_noniso_vis], [model], context='2d', dopsf=True)
        result = restore_list_rsexecute_workflow([combined_model], psf_obs, [(residual, 0.0)])
        result = rsexecute.compute(result, sync=True)

        if self.persist: export_image_to_fits(residual,
                                              rascil_path('test_results/test_mpccal_ical_onesource_residual.fits'))
        if self.persist: export_image_to_fits(result[0],
                                              rascil_path('test_results/test_mpccal_ical_onesource_restored.fits'))
        if self.persist: export_image_to_fits(combined_model,
                                              rascil_path('test_results/test_mpccal_ical_onesource_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 0', recovered_mpccal_components[0].name
        assert numpy.abs(recovered_mpccal_components[0].flux[0, 0] - 1.138095494391862) < 1e-6, \
            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,
                                              rascil_path('test_results/test_mpccal_ical_onesource_screen.fits'))
        if self.persist: export_image_to_fits(weights,
                                              rascil_path('test_results/test_mpccal_ical_onesource_screenweights.fits'))

        rsexecute.close()
    difference_image.data -= ical_restored.data

    print(qa_image(difference_image, context='MPCCAL - ICAL image'))
    show_image(difference_image,
               title='MPCCAL - ICAL image',
               components=ical_components)
    plt.show(block=block_plots)
    export_image_to_fits(
        difference_image,
        rascil_path(
            'test_results/low-sims-mpc-mpccal-ical-restored_%.1frmax.fits' %
            rmax))

    newscreen = create_empty_image_like(screen)
    gaintables = [sm.gaintable for sm in mpccal_skymodel]
    newscreen, weights = grid_gaintable_to_screen(block_vis, gaintables,
                                                  newscreen)
    export_image_to_fits(
        newscreen,
        rascil_path('test_results/low-sims-mpc-mpccal-screen_%.1frmax.fits' %
                    rmax))
    export_image_to_fits(
        weights,
        rascil_path(
            'test_results/low-sims-mpc-mpccal-screenweights_%.1frmax.fits' %
            rmax))
    print(qa_image(weights))
    print(qa_image(newscreen))

    plot_gaintable_on_screen(block_vis, gaintables)
    plt.savefig(
        rascil_path('test_results/low-sims-mpc-mpccal-screen_%.1frmax.png' %