コード例 #1
0
ファイル: test_skycomponent.py プロジェクト: Yonhua/rascil
    def test_partition_skycomponent_neighbours(self):
        all_components = create_low_test_skycomponents_from_gleam(
            flux_limit=0.1,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.5)

        bright_components = create_low_test_skycomponents_from_gleam(
            flux_limit=1.0,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.5)
        model = create_image(npixel=512,
                             cellsize=0.001,
                             phasecentre=self.phasecentre,
                             frequency=self.frequency,
                             polarisation_frame=PolarisationFrame('stokesI'))
        beam = create_low_test_beam(model, use_local=False)
        all_components = apply_beam_to_skycomponent(all_components, beam)
        all_components = filter_skycomponents_by_flux(all_components,
                                                      flux_min=0.1)
        bright_components = apply_beam_to_skycomponent(bright_components, beam)
        bright_components = filter_skycomponents_by_flux(bright_components,
                                                         flux_min=2.0)

        comps_lists = partition_skycomponent_neighbours(
            all_components, bright_components)
        assert len(comps_lists) == len(bright_components)
        assert len(comps_lists[0]) > 0
        assert len(comps_lists[-1]) > 0
コード例 #2
0
    def test_create_gaintable_from_screen(self):
        screen = import_image_from_fits(
            rascil_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
コード例 #3
0
    def test_expand_skymodel_by_skycomponents(self):
        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)

        assert len(actual_components) == 37, len(actual_components)
        sm = SkyModel(image=self.model, components=actual_components)
        assert len(sm.components) == len(actual_components)

        scatter_sm = expand_skymodel_by_skycomponents(sm)
        assert len(scatter_sm) == len(actual_components) + 1
        assert len(scatter_sm[0].components) == 1
コード例 #4
0
def create_unittest_components(model,
                               flux,
                               applypb=False,
                               telescope='LOW',
                               npixel=None,
                               scale=1.0,
                               single=False,
                               symmetric=False,
                               angular_scale=1.0):
    # Fill the visibility with exactly computed point sources.

    if npixel is None:
        _, _, _, npixel = model.data.shape
    spacing_pixels = int(scale * npixel) // 4
    log.info('Spacing in pixels = %s' % spacing_pixels)

    if not symmetric:
        centers = [(0.2 * angular_scale, 1.1 * angular_scale)]
    else:
        centers = list()

    if not single:
        centers.append([0.0, 0.0])

        for x in numpy.linspace(-1.2 * angular_scale, 1.2 * angular_scale, 7):
            if abs(x) > 1e-15:
                centers.append([x, x])
                centers.append([x, -x])
    model_pol = model.polarisation_frame
    # Make the list of components
    rpix = model.wcs.wcs.crpix
    components = []
    for center in centers:
        ix, iy = center
        # The phase center in 0-relative coordinates is n // 2 so we centre the grid of
        # components on ny // 2, nx // 2. The wcs must be defined consistently.
        p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[0]))), \
            int(round(rpix[1] + iy * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[1])))
        sc = pixel_to_skycoord(p[0], p[1], model.wcs, origin=1)
        log.info("Component at (%f, %f) [0-rel] %s" % (p[0], p[1], str(sc)))

        # Channel images
        comp = create_skycomponent(direction=sc,
                                   flux=flux,
                                   frequency=model.frequency,
                                   polarisation_frame=model_pol)
        components.append(comp)

    if applypb:
        beam = create_pb(model, telescope=telescope, use_local=False)
        components = apply_beam_to_skycomponent(components, beam)

    return components
コード例 #5
0
ファイル: test_skycomponent.py プロジェクト: Yonhua/rascil
    def test_voronoi_decomposition(self):
        bright_components = create_low_test_skycomponents_from_gleam(
            flux_limit=1.0,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.5)
        model = create_image(npixel=512,
                             cellsize=0.001,
                             phasecentre=self.phasecentre,
                             frequency=self.frequency,
                             polarisation_frame=PolarisationFrame('stokesI'))
        beam = create_low_test_beam(model, use_local=False)
        bright_components = apply_beam_to_skycomponent(bright_components, beam)
        bright_components = filter_skycomponents_by_flux(bright_components,
                                                         flux_min=2.0)

        vor, vor_array = voronoi_decomposition(model, bright_components)
        assert len(bright_components) == (numpy.max(vor_array) + 1)
コード例 #6
0
    def test_grid_gaintable_to_screen(self):
        self.actualSetup()
        screen = import_image_from_fits(
            rascil_data_path('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, 1, 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,
                rascil_path('test_results/test_mpc_screen_gridded.fits'))
        if self.persist:
            export_image_to_fits(
                weights,
                rascil_path(
                    'test_results/test_mpc_screen_gridded_weights.fits'))
コード例 #7
0
    def test_expand_skymodel_voronoi(self):
        self.model = create_image(
            npixel=256,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame("stokesI"),
            frequency=self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre)
        beam = create_low_test_beam(self.model, 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.1)

        pb_gleam_components = apply_beam_to_skycomponent(
            gleam_components, beam)

        actual_components = filter_skycomponents_by_flux(pb_gleam_components,
                                                         flux_min=1.0)
        _, actual_components = remove_neighbouring_components(
            actual_components, 0.05)

        for imask, mask in enumerate(
                image_voronoi_iter(self.model, actual_components)):
            mask.data *= beam.data
            assert isinstance(mask, Image)
            assert mask.data.dtype == "float"
            assert numpy.sum(mask.data) > 1
            # import matplotlib.pyplot as plt
            # from rascil.processing_components.image.operations import show_image
            # show_image(mask)
            # plt.show(block=False)

        assert len(actual_components) == 9, len(actual_components)
        sm = SkyModel(image=self.model, components=actual_components)
        assert len(sm.components) == len(actual_components)

        scatter_sm = expand_skymodel_by_skycomponents(sm)
        assert len(scatter_sm) == len(actual_components) + 1
        assert len(scatter_sm[0].components) == 1
コード例 #8
0
ファイル: test_skycomponent.py プロジェクト: Yonhua/rascil
    def test_image_voronoi_iter(self):
        bright_components = create_low_test_skycomponents_from_gleam(
            flux_limit=1.0,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.5)
        model = create_image(npixel=512,
                             cellsize=0.001,
                             phasecentre=self.phasecentre,
                             frequency=self.frequency,
                             polarisation_frame=PolarisationFrame('stokesI'))
        model.data[...] = 1.0
        beam = create_low_test_beam(model, use_local=False)
        bright_components = apply_beam_to_skycomponent(bright_components, beam)
        bright_components = filter_skycomponents_by_flux(bright_components,
                                                         flux_min=2.0)

        for im in image_voronoi_iter(model, bright_components):
            assert numpy.sum(im.data) > 1
コード例 #9
0
ファイル: test_skycomponent.py プロジェクト: Yonhua/rascil
    def test_remove_neighbouring_components(self):
        all_components = create_low_test_skycomponents_from_gleam(
            flux_limit=3.0,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.5)

        model = create_image(npixel=512,
                             cellsize=0.001,
                             phasecentre=self.phasecentre,
                             frequency=self.frequency,
                             polarisation_frame=PolarisationFrame('stokesI'))
        beam = create_low_test_beam(model, use_local=False)
        all_components = apply_beam_to_skycomponent(all_components, beam)
        all_components = filter_skycomponents_by_flux(all_components,
                                                      flux_min=0.1)

        idx, comps = remove_neighbouring_components(all_components, 0.1)
        assert idx == [
            0, 1, 3, 8, 12, 13, 17, 22, 25, 26, 29, 32, 35, 38, 41, 42, 46, 47,
            50, 52, 53, 56, 57, 58, 61, 63, 66, 68, 70
        ], idx
        assert comps[0].name == 'GLEAM J215739-661155', comps[0].name
コード例 #10
0
    def test_create_gaintable_from_screen_troposphere(self):
        self.actualSetup("troposphere")
        screen = import_image_from_fits(
            rascil_data_path('models/test_mpc_screen.fits'))
        beam = create_test_image(cellsize=0.00015,
                                 phasecentre=self.vis.phasecentre,
                                 frequency=self.frequency)

        beam = create_low_test_beam(beam, use_local=False)

        s3_components = create_test_skycomponents_from_s3(
            flux_limit=0.3,
            phasecentre=self.phasecentre,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=1.5 * numpy.pi / 180.0)

        assert len(s3_components) > 0, "No S3 components selected"

        pb_s3_components = apply_beam_to_skycomponent(s3_components, beam)

        actual_components = filter_skycomponents_by_flux(pb_s3_components,
                                                         flux_max=10.0)

        assert len(
            actual_components) > 0, "No components after applying primary beam"

        gaintables = create_gaintable_from_screen(
            self.vis,
            actual_components,
            screen,
            height=3e3,
            type_atmosphere="troposphere")
        assert len(gaintables) == len(actual_components), len(gaintables)
        assert gaintables[0].gain.shape == (3, 63, 1, 1,
                                            1), gaintables[0].gain.shape
コード例 #11
0
ファイル: simulation_helpers.py プロジェクト: Yonhua/rascil
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 rascil.processing_components.simulation 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
コード例 #12
0
     cellsize=pb_cellsize,
     override_cellsize=False,
     phasecentre=phasecentre,
     frequency=frequency,
     nchan=nfreqwin,
     polarisation_frame=PolarisationFrame("stokesI"))
 pbmodel = rsexecute.compute(pbmodel, sync=True)
 # Use MID_GAUSS to filter the components since MID_GRASP is in local coordinates
 pb = create_pb(pbmodel,
                "MID_GAUSS",
                pointingcentre=phasecentre,
                use_local=False)
 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])
 print("%d components > %.3f Jy after application of primary beam" %
       (len(filtered_components), flux_limit))
 print("Strongest components is %g (Jy)" % max_flux)
 print("Total flux in components is %g (Jy)" % total_flux)
 original_components = [
     copy_skycomponent(c) for c in filtered_components
 ]
 plt.clf()
コード例 #13
0
def create_simulation_components(
        context,
        phasecentre,
        frequency,
        pbtype,
        offset_dir,
        flux_limit,
        pbradius,
        pb_npixel,
        pb_cellsize,
        show=False,
        fov=10,
        polarisation_frame=PolarisationFrame("stokesI"),
        filter_by_primary_beam=True,
        flux_max=10.0):
    """ Construct components for simulation
    
    :param context: singlesource or null or s3sky
    :param phasecentre: Centre of components
    :param frequency: Frequency
    :param pbtype: Type of primary beam
    :param offset_dir: Offset in ra, dec degrees
    :param flux_limit: Lower limit flux
    :param pbradius: Radius of components in radians
    :param pb_npixel: Number of pixels in the primary beam model
    :param pb_cellsize: Cellsize in primary beam model
    :param fov: FOV in degrees (used to select catalog)
    :param flux_max: Maximum flux in model before application of primary beam
    :param filter_by_primary_beam: Filter components by primary beam
    :param polarisation_frame:
    :param show:

    :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
        odirection = SkyCoord(
            ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) *
            units.deg,
            dec=(dec + offset[1]) * units.deg,
            frame='icrs',
            equinox='J2000')

        if polarisation_frame.type == "stokesIQUV":
            original_components = [
                Skycomponent(
                    flux=[[1.0, 0.0, 0.0, 0.0]],
                    direction=odirection,
                    frequency=frequency,
                    polarisation_frame=PolarisationFrame('stokesIQUV'))
            ]
        else:
            original_components = [
                Skycomponent(flux=[[1.0]],
                             direction=odirection,
                             frequency=frequency,
                             polarisation_frame=PolarisationFrame('stokesI'))
            ]

        offset_direction = odirection

    elif context == 'doublesource':

        original_components = []

        log.info(
            "create_simulation_components: Constructing double components")

        for sign_offset in [(-1, 0), (1, 0)]:
            offset = [HWHM_deg * sign_offset[0], HWHM_deg * sign_offset[1]]

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

            odirection = SkyCoord(
                ra=(ra + offset[0] / numpy.cos(numpy.pi * dec / 180.0)) *
                units.deg,
                dec=(dec + offset[1]) * units.deg,
                frame='icrs',
                equinox='J2000')
            if polarisation_frame.type == "stokesIQUV":
                original_components.append(
                    Skycomponent(
                        flux=[[1.0, 0.0, 0.0, 0.0]],
                        direction=odirection,
                        frequency=frequency,
                        polarisation_frame=PolarisationFrame('stokesIQUV')))
            else:
                original_components.append(
                    Skycomponent(
                        flux=[[1.0]],
                        direction=odirection,
                        frequency=frequency,
                        polarisation_frame=PolarisationFrame('stokesI')))

        for o in original_components:
            print(o)

        offset_direction = odirection

    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')

        if polarisation_frame.type == "stokesIQUV":
            original_components = [
                Skycomponent(
                    flux=[[1.0, 0.0, 0.0, 0.0]],
                    direction=offset_direction,
                    frequency=frequency,
                    polarisation_frame=PolarisationFrame('stokesIQUV'))
            ]
        else:
            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 rascil.processing_components.simulation import create_test_skycomponents_from_s3

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

        if filter_by_primary_beam:
            pbmodel = create_image(
                npixel=pb_npixel,
                cellsize=pb_cellsize,
                phasecentre=phasecentre,
                frequency=frequency,
                polarisation_frame=PolarisationFrame("stokesI"))
            stokesi_components = [
                copy_skycomponent(o) for o in original_components
            ]
            for s in stokesi_components:
                s.flux = numpy.array([[s.flux[0, 0]]])
                s.polarisation_frame = PolarisationFrame("stokesI")

            pb = create_pb(pbmodel,
                           "MID_GAUSS",
                           pointingcentre=phasecentre,
                           use_local=False)
            pb_applied_components = [
                copy_skycomponent(c) for c in stokesi_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 filtering with 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
コード例 #14
0
def create_low_test_skymodel_from_gleam(npixel=512,
                                        polarisation_frame=PolarisationFrame(
                                            "stokesI"),
                                        cellsize=0.000015,
                                        frequency=numpy.array([1e8]),
                                        channel_bandwidth=numpy.array([1e6]),
                                        phasecentre=None,
                                        kind='cubic',
                                        applybeam=True,
                                        flux_limit=0.1,
                                        flux_max=numpy.inf,
                                        flux_threshold=1.0,
                                        insert_method='Nearest',
                                        telescope='LOW') -> SkyModel:
    """Create LOW test skymodel from the GLEAM survey

    Stokes I is estimated from a cubic spline fit to the measured fluxes. The polarised flux is always zero.

    See http://www.mwatelescope.org/science/gleam-survey The catalog is available from Vizier.

    VIII/100   GaLactic and Extragalactic All-sky MWA survey  (Hurley-Walker+, 2016)

    GaLactic and Extragalactic All-sky Murchison Wide Field Array (GLEAM) survey. I: A low-frequency extragalactic
    catalogue. Hurley-Walker N., et al., Mon. Not. R. Astron. Soc., 464, 1146-1167 (2017), 2017MNRAS.464.1146H

    :param telescope:
    :param npixel: Number of pixels
    :param polarisation_frame: Polarisation frame (default PolarisationFrame("stokesI"))
    :param cellsize: cellsize in radians
    :param frequency:
    :param channel_bandwidth: Channel width (Hz)
    :param phasecentre: phasecentre (SkyCoord)
    :param kind: Kind of interpolation (see scipy.interpolate.interp1d) Default: cubic
    :param applybeam: Apply the primary beam?
    :param flux_limit: Weakest component
    :param flux_max: Maximum strength component to be included in components
    :param flux_threshold: Split between components (brighter) and image (weaker)
    :param insert_method: Nearest | PSWF | Lanczos
    :return:
    :return: SkyModel

    """
    check_data_directory()

    if phasecentre is None:
        phasecentre = SkyCoord(ra=+15.0 * u.deg,
                               dec=-35.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')

    radius = npixel * cellsize

    sc = create_low_test_skycomponents_from_gleam(
        flux_limit=flux_limit,
        polarisation_frame=polarisation_frame,
        frequency=frequency,
        phasecentre=phasecentre,
        kind=kind,
        radius=radius)

    sc = filter_skycomponents_by_flux(sc, flux_max=flux_max)
    if polarisation_frame is None:
        polarisation_frame = PolarisationFrame("stokesI")

    npol = polarisation_frame.npol
    nchan = len(frequency)
    shape = [nchan, npol, npixel, npixel]
    w = WCS(naxis=4)
    # The negation in the longitude is needed by definition of RA, DEC
    w.wcs.cdelt = [
        -cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0,
        channel_bandwidth[0]
    ]
    w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0]
    w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ']
    w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, frequency[0]]
    w.naxis = 4
    w.wcs.radesys = 'ICRS'
    w.wcs.equinox = 2000.0

    model = create_image_from_array(numpy.zeros(shape),
                                    w,
                                    polarisation_frame=polarisation_frame)

    if applybeam:
        beam = create_pb(model, telescope=telescope, use_local=False)
        sc = apply_beam_to_skycomponent(sc, beam)

    weaksc = filter_skycomponents_by_flux(sc, flux_max=flux_threshold)
    brightsc = filter_skycomponents_by_flux(sc, flux_min=flux_threshold)
    model = insert_skycomponent(model, weaksc, insert_method=insert_method)

    log.info(
        'create_low_test_skymodel_from_gleam: %d bright sources above flux threshold %.3f, %d weak sources below '
        % (len(brightsc), flux_threshold, len(weaksc)))

    return SkyModel(components=brightsc,
                    image=model,
                    mask=None,
                    gaintable=None)