Ejemplo n.º 1
0
    def ft_ift_sm(ov, sm, g):
        assert isinstance(ov, Visibility), ov
        assert isinstance(sm, SkyModel), sm
        if g is not None:
            assert len(g) == 2, g
            assert isinstance(g[0], Image), g[0]
            assert isinstance(g[1], ConvolutionFunction), g[1]

        v = copy_visibility(ov)

        v.data['vis'][...] = 0.0 + 0.0j

        if len(sm.components) > 0:

            if isinstance(sm.mask, Image):
                comps = copy_skycomponent(sm.components)
                comps = apply_beam_to_skycomponent(comps, sm.mask)
                v = predict_skycomponent_visibility(v, comps)
            else:
                v = predict_skycomponent_visibility(v, sm.components)

        if isinstance(sm.image, Image):
            if numpy.max(numpy.abs(sm.image.data)) > 0.0:
                if isinstance(sm.mask, Image):
                    model = copy_image(sm.image)
                    model.data *= sm.mask.data
                else:
                    model = sm.image
                v = predict_list_serial_workflow([v], [model],
                                                 context=context,
                                                 vis_slices=vis_slices,
                                                 facets=facets,
                                                 gcfcf=[g],
                                                 **kwargs)[0]

        assert isinstance(sm.image, Image), sm.image

        result = invert_list_serial_workflow([v], [sm.image],
                                             context=context,
                                             vis_slices=vis_slices,
                                             facets=facets,
                                             gcfcf=gcfcf,
                                             **kwargs)[0]
        if isinstance(sm.mask, Image):
            result[0].data *= sm.mask.data
        return result
Ejemplo n.º 2
0
    def ft_cal_sm(ov, sm, g):
        assert isinstance(ov, Visibility), ov
        assert isinstance(sm, SkyModel), sm
        if g is not None:
            assert len(g) == 2, g
            assert isinstance(g[0], Image), g[0]
            assert isinstance(g[1], ConvolutionFunction), g[1]

        v = copy_visibility(ov)

        v.data['vis'][...] = 0.0 + 0.0j

        if len(sm.components) > 0:

            if isinstance(sm.mask, Image):
                comps = copy_skycomponent(sm.components)
                comps = apply_beam_to_skycomponent(comps, sm.mask)
                v = predict_skycomponent_visibility(v, comps)
            else:
                v = predict_skycomponent_visibility(v, sm.components)

        if isinstance(sm.image, Image):
            if numpy.max(numpy.abs(sm.image.data)) > 0.0:
                if isinstance(sm.mask, Image):
                    model = copy_image(sm.image)
                    model.data *= sm.mask.data
                else:
                    model = sm.image
                v = predict_list_serial_workflow([v], [model],
                                                 context=context,
                                                 vis_slices=vis_slices,
                                                 facets=facets,
                                                 gcfcf=[g],
                                                 **kwargs)[0]

        if docal and isinstance(sm.gaintable, GainTable):
            bv = convert_visibility_to_blockvisibility(v)
            bv = apply_gaintable(bv, sm.gaintable, inverse=True)
            v = convert_blockvisibility_to_visibility(bv)

        return v
    def actualSetup(self, nsources=None, nvoronoi=None):

        n_workers = 8

        # Set up the observation: 10 minutes at transit, with 10s integration.
        # Skip 5/6 points to avoid outstation redundancy

        nfreqwin = 1
        ntimes = 3
        self.rmax = 2500.0
        dec = -40.0 * u.deg
        frequency = [1e8]
        channel_bandwidth = [0.1e8]
        times = numpy.linspace(-10.0, 10.0,
                               ntimes) * numpy.pi / (3600.0 * 12.0)

        phasecentre = SkyCoord(ra=+0.0 * u.deg,
                               dec=dec,
                               frame='icrs',
                               equinox='J2000')
        low = create_named_configuration('LOWBD2', rmax=self.rmax)

        centre = numpy.mean(low.xyz, axis=0)
        distance = numpy.hypot(low.xyz[:, 0] - centre[0],
                               low.xyz[:, 1] - centre[1],
                               low.xyz[:, 2] - centre[2])
        lowouter = low.data[distance > 1000.0][::6]
        lowcore = low.data[distance < 1000.0][::3]
        low.data = numpy.hstack((lowcore, lowouter))

        blockvis = create_blockvisibility(
            low,
            times,
            frequency=frequency,
            channel_bandwidth=channel_bandwidth,
            weight=1.0,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            zerow=True)

        vis = convert_blockvisibility_to_visibility(blockvis)
        advice = advise_wide_field(vis, guard_band_image=2.0, delA=0.02)

        cellsize = advice['cellsize']
        npixel = advice['npixels2']

        small_model = create_image_from_visibility(blockvis,
                                                   npixel=512,
                                                   frequency=frequency,
                                                   nchan=nfreqwin,
                                                   cellsize=cellsize,
                                                   phasecentre=phasecentre)

        vis.data['imaging_weight'][...] = vis.data['weight'][...]
        vis = weight_list_serial_workflow([vis], [small_model])[0]
        vis = taper_list_serial_workflow([vis], 3 * cellsize)[0]

        blockvis = convert_visibility_to_blockvisibility(vis)

        # ### Generate the model from the GLEAM catalog, including application of the primary beam.

        beam = create_image_from_visibility(blockvis,
                                            npixel=npixel,
                                            frequency=frequency,
                                            nchan=nfreqwin,
                                            cellsize=cellsize,
                                            phasecentre=phasecentre)
        beam = create_low_test_beam(beam, use_local=False)

        flux_limit = 0.5
        original_gleam_components = create_low_test_skycomponents_from_gleam(
            flux_limit=flux_limit,
            phasecentre=phasecentre,
            frequency=frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.15)

        all_components = apply_beam_to_skycomponent(original_gleam_components,
                                                    beam)
        all_components = filter_skycomponents_by_flux(all_components,
                                                      flux_min=flux_limit)
        voronoi_components = filter_skycomponents_by_flux(all_components,
                                                          flux_min=1.5)

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

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

        if nsources is not None:
            all_components = [all_components[0]]

        if nvoronoi is not None:
            voronoi_components = [voronoi_components[0]]

        self.screen = import_image_from_fits(
            arl_path('data/models/test_mpc_screen.fits'))
        all_gaintables = create_gaintable_from_screen(blockvis, all_components,
                                                      self.screen)

        gleam_skymodel_noniso = [
            SkyModel(components=[all_components[i]],
                     gaintable=all_gaintables[i])
            for i, sm in enumerate(all_components)
        ]

        # ### Now predict the visibility for each skymodel and apply the gaintable for that skymodel,
        # returning a list of visibilities, one for each skymodel. We then sum these to obtain
        # the total predicted visibility. All images and skycomponents in the same skymodel
        # get the same gaintable applied which means that in this case each skycomponent has a separate gaintable.

        self.all_skymodel_noniso_vis = convert_blockvisibility_to_visibility(
            blockvis)

        ngroup = n_workers
        future_vis = arlexecute.scatter(self.all_skymodel_noniso_vis)
        chunks = [
            gleam_skymodel_noniso[i:i + ngroup]
            for i in range(0, len(gleam_skymodel_noniso), ngroup)
        ]
        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:
                self.all_skymodel_noniso_vis.data['vis'] += w.data['vis']
            assert numpy.max(
                numpy.abs(self.all_skymodel_noniso_vis.data['vis'])) > 0.0

        self.all_skymodel_noniso_blockvis = convert_visibility_to_blockvisibility(
            self.all_skymodel_noniso_vis)

        # ### Remove weaker of components that are too close (0.02 rad)
        idx, voronoi_components = remove_neighbouring_components(
            voronoi_components, 0.02)

        model = create_image_from_visibility(blockvis,
                                             npixel=npixel,
                                             frequency=frequency,
                                             nchan=nfreqwin,
                                             cellsize=cellsize,
                                             phasecentre=phasecentre)

        # Use the gaintable for the brightest component as the starting gaintable
        all_gaintables[0].gain[...] = numpy.conjugate(
            all_gaintables[0].gain[...])
        all_gaintables[0].gain[...] = 1.0 + 0.0j
        self.theta_list = initialize_skymodel_voronoi(model,
                                                      voronoi_components,
                                                      all_gaintables[0])
Ejemplo n.º 4
0
def create_simulation_components(context,
                                 phasecentre,
                                 frequency,
                                 pbtype,
                                 offset_dir,
                                 flux_limit,
                                 pbradius,
                                 pb_npixel,
                                 pb_cellsize,
                                 show=False):
    """ Construct components for simulation
    
    :param context:
    :param phasecentre:
    :param frequency:
    :param pbtype:
    :param offset_dir:
    :param flux_limit:
    :param pbradius:
    :param pb_npixel:
    :param pb_cellsize:
    :return:
    """

    HWHM_deg, null_az_deg, null_el_deg = find_pb_width_null(pbtype, frequency)

    dec = phasecentre.dec.deg
    ra = phasecentre.ra.deg

    if context == 'singlesource':
        log.info("create_simulation_components: Constructing single component")
        offset = [HWHM_deg * offset_dir[0], HWHM_deg * offset_dir[1]]
        log.info(
            "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg"
            % (offset[0], offset[1]))

        # The point source is offset to approximately the halfpower point
        offset_direction = SkyCoord(
            ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) *
            units.deg,
            dec=(dec + offset[1]) * units.deg,
            frame='icrs',
            equinox='J2000')

        original_components = [
            Skycomponent(flux=[[1.0]],
                         direction=offset_direction,
                         frequency=frequency,
                         polarisation_frame=PolarisationFrame('stokesI'))
        ]

    elif context == 'null':
        log.info(
            "create_simulation_components: Constructing single component at the null"
        )

        offset = [null_az_deg * offset_dir[0], null_el_deg * offset_dir[1]]
        HWHM = HWHM_deg * numpy.pi / 180.0

        log.info(
            "create_simulation_components: Offset from pointing centre = %.3f, %.3f deg"
            % (offset[0], offset[1]))

        # The point source is offset to approximately the null point
        offset_direction = SkyCoord(
            ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) *
            units.deg,
            dec=(dec + offset[1]) * units.deg,
            frame='icrs',
            equinox='J2000')

        original_components = [
            Skycomponent(flux=[[1.0]],
                         direction=offset_direction,
                         frequency=frequency,
                         polarisation_frame=PolarisationFrame('stokesI'))
        ]

    else:
        offset = [0.0, 0.0]
        # Make a skymodel from S3
        max_flux = 0.0
        total_flux = 0.0
        log.info("create_simulation_components: Constructing s3sky components")
        from wrappers.serial.simulation.testing_support import create_test_skycomponents_from_s3

        original_components = create_test_skycomponents_from_s3(
            flux_limit=flux_limit / 100.0,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            frequency=numpy.array(frequency),
            radius=pbradius)
        log.info(
            "create_simulation_components: %d components before application of primary beam"
            % (len(original_components)))

        pbmodel = create_image(npixel=pb_npixel,
                               cellsize=pb_cellsize,
                               phasecentre=phasecentre,
                               frequency=frequency,
                               polarisation_frame=PolarisationFrame("stokesI"))
        pb = create_pb(pbmodel,
                       "MID_GAUSS",
                       pointingcentre=phasecentre,
                       use_local=False)
        pb_feko = create_pb(pbmodel,
                            pbtype,
                            pointingcentre=phasecentre,
                            use_local=True)
        pb.data = pb_feko.data[:, 0, ...][:, numpy.newaxis, ...]
        pb_applied_components = [
            copy_skycomponent(c) for c in original_components
        ]
        pb_applied_components = apply_beam_to_skycomponent(
            pb_applied_components, pb)
        filtered_components = []
        for icomp, comp in enumerate(pb_applied_components):
            if comp.flux[0, 0] > flux_limit:
                total_flux += comp.flux[0, 0]
                if abs(comp.flux[0, 0]) > max_flux:
                    max_flux = abs(comp.flux[0, 0])
                filtered_components.append(original_components[icomp])
        log.info(
            "create_simulation_components: %d components > %.3f Jy after application of primary beam"
            % (len(filtered_components), flux_limit))
        log.info(
            "create_simulation_components: Strongest components is %g (Jy)" %
            max_flux)
        log.info(
            "create_simulation_components: Total flux in components is %g (Jy)"
            % total_flux)
        original_components = [
            copy_skycomponent(c) for c in filtered_components
        ]
        if show:
            plt.clf()
            show_image(pb, components=original_components)
            plt.show(block=False)

        log.info("create_simulation_components: Created %d components" %
                 len(original_components))
        # Primary beam points to the phasecentre
        offset_direction = SkyCoord(ra=ra * units.deg,
                                    dec=dec * units.deg,
                                    frame='icrs',
                                    equinox='J2000')

    return original_components, offset_direction
Ejemplo n.º 5
0
    beam = create_image_from_visibility(block_vis,
                                        npixel=npixel,
                                        frequency=frequency,
                                        nchan=nfreqwin,
                                        cellsize=cellsize,
                                        phasecentre=phasecentre)
    beam = create_low_test_beam(beam, use_local=False)

    original_gleam_components = create_low_test_skycomponents_from_gleam(
        flux_limit=flux_limit,
        phasecentre=phasecentre,
        frequency=frequency,
        polarisation_frame=PolarisationFrame('stokesI'),
        radius=0.15)

    all_components = apply_beam_to_skycomponent(original_gleam_components,
                                                beam)
    all_components = filter_skycomponents_by_flux(all_components,
                                                  flux_min=flux_limit)
    all_components = sorted(all_components,
                            key=lambda comp: numpy.max(comp.flux),
                            reverse=True)
    print("Number of components in simulation %d" % len(all_components))

    screen = import_image_from_fits(
        arl_path('data/models/test_mpc_screen.fits'))
    all_gaintables = create_gaintable_from_screen(block_vis, all_components,
                                                  screen)

    all_skymodel = [
        SkyModel(components=[all_components[i]], gaintable=all_gaintables[i])
        for i, sm in enumerate(all_components)