コード例 #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_low_test_beam(self):
        im = create_test_image(
            canonical=True,
            cellsize=0.002,
            frequency=numpy.array([1e8 - 5e7, 1e8, 1e8 + 5e7]),
            channel_bandwidth=numpy.array([5e7, 5e7, 5e7]),
            polarisation_frame=PolarisationFrame("stokesIQUV"),
            phasecentre=self.phasecentre)
        bm = create_low_test_beam(model=im)
        if self.persist:
            export_image_to_fits(
                bm, '%s/test_test_support_low_beam.fits' % (self.dir))

        assert bm.data.shape[0] == 3
        assert bm.data.shape[1] == 4
        assert bm.data.shape[2] == im.data.shape[2]
        assert bm.data.shape[3] == im.data.shape[3]
        # Check to see if the beam scales as expected
        for i in [30, 40]:
            assert numpy.max(
                numpy.abs(bm.data[0, 0, 128, 128 - 2 * i] -
                          bm.data[1, 0, 128, 128 - i])) < 0.02
            assert numpy.max(
                numpy.abs(bm.data[0, 0, 128, 128 - 3 * i] -
                          bm.data[2, 0, 128, 128 - i])) < 0.02
            assert numpy.max(
                numpy.abs(bm.data[0, 0, 128 - 2 * i, 128] -
                          bm.data[1, 0, 128 - i, 128])) < 0.02
            assert numpy.max(
                numpy.abs(bm.data[0, 0, 128 - 3 * i, 128] -
                          bm.data[2, 0, 128 - i, 128])) < 0.02
コード例 #3
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
コード例 #4
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
コード例 #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
 def setUp(self):
     from rascil.data_models.parameters import rascil_path
     self.dir = rascil_path('test_results')
     self.persist = os.getenv("RASCIL_PERSIST", False)
     self.niter = 1000
     self.lowcore = create_named_configuration('LOWBD2-CORE')
     self.nchan = 5
     self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7)
     self.frequency = numpy.linspace(0.9e8, 1.1e8, self.nchan)
     self.channel_bandwidth = numpy.array(self.nchan * [self.frequency[1] - self.frequency[0]])
     self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')
     self.vis = create_visibility(self.lowcore, self.times, self.frequency, self.channel_bandwidth,
                                  phasecentre=self.phasecentre, weight=1.0,
                                  polarisation_frame=PolarisationFrame('stokesI'), zerow=True)
     self.vis.data['vis'] *= 0.0
     
     # Create model
     self.test_model = create_low_test_image_from_gleam(npixel=512, cellsize=0.001,
                                                        phasecentre=self.vis.phasecentre,
                                                        frequency=self.frequency,
                                                        channel_bandwidth=self.channel_bandwidth,
                                                        flux_limit=1.0)
     beam = create_low_test_beam(self.test_model)
     if self.persist: export_image_to_fits(beam, "%s/test_deconvolve_mmclean_beam.fits" % self.dir)
     self.test_model.data *= beam.data
     if self.persist: export_image_to_fits(self.test_model, "%s/test_deconvolve_mmclean_model.fits" % self.dir)
     self.vis = predict_2d(self.vis, self.test_model)
     assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
     self.model = create_image_from_visibility(self.vis, npixel=512, cellsize=0.001,
                                               polarisation_frame=PolarisationFrame('stokesI'))
     self.dirty, sumwt = invert_2d(self.vis, self.model)
     self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True)
     if self.persist: export_image_to_fits(self.dirty, "%s/test_deconvolve_mmclean-dirty.fits" % self.dir)
     if self.persist: export_image_to_fits(self.psf, "%s/test_deconvolve_mmclean-psf.fits" % self.dir)
     window = numpy.ones(shape=self.model.shape, dtype=numpy.bool)
     window[..., 129:384, 129:384] = True
     self.innerquarter = create_image_from_array(window, self.model.wcs, polarisation_frame=PolarisationFrame('stokesI'))
コード例 #10
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
コード例 #11
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