예제 #1
0
    def test_grid_gaintable_to_screen(self):
        screen = import_image_from_fits(
            arl_path('data/models/test_mpc_screen.fits'))
        beam = create_test_image(cellsize=0.0015,
                                 phasecentre=self.vis.phasecentre,
                                 frequency=self.frequency)

        beam = create_low_test_beam(beam, use_local=False)

        gleam_components = create_low_test_skycomponents_from_gleam(
            flux_limit=1.0,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.2)

        pb_gleam_components = apply_beam_to_skycomponent(
            gleam_components, beam)

        actual_components = filter_skycomponents_by_flux(pb_gleam_components,
                                                         flux_min=1.0)

        gaintables = create_gaintable_from_screen(self.vis, actual_components,
                                                  screen)
        assert len(gaintables) == len(actual_components), len(gaintables)
        assert gaintables[0].gain.shape == (3, 94, 3, 1,
                                            1), gaintables[0].gain.shape

        newscreen = create_empty_image_like(screen)

        newscreen, weights = grid_gaintable_to_screen(self.vis, gaintables,
                                                      newscreen)
        assert numpy.max(numpy.abs(screen.data)) > 0.0
        if self.persist:
            export_image_to_fits(
                newscreen,
                arl_path('test_results/test_mpc_screen_gridded.fits'))
        if self.persist:
            export_image_to_fits(
                weights,
                arl_path('test_results/test_mpc_screen_gridded_weights.fits'))
    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()