コード例 #1
0
 def _checkcomponents(self, dirty, fluxthreshold=0.6, positionthreshold=1.0):
     comps = find_skycomponents(dirty, fwhm=1.0, threshold=10 * fluxthreshold, npixels=5)
     assert len(comps) == len(self.components), "Different number of components found: original %d, recovered %d" % \
                                                (len(self.components), len(comps))
     cellsize = abs(dirty.wcs.wcs.cdelt[0])
     
     for comp in comps:
         # Check for agreement in direction
         ocomp, separation = find_nearest_skycomponent(comp.direction, self.components)
         assert separation / cellsize < positionthreshold, "Component differs in position %.3f pixels" % \
                                                           separation / cellsize
    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()
コード例 #3
0
                                              [(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)
    idx, ical_components = remove_neighbouring_components(
        ical_components, 0.02)
    ical_components = sorted(ical_components,
                             key=lambda comp: numpy.max(comp.flux),
                             reverse=True)
    print("Voronoi decomposition based on %d point sources" %
          len(ical_components))

    print(qa_image(ical_restored, context='ICAL restored image'))
    show_image(ical_restored,