Esempio n. 1
0
    def test_apply_primary_beam_imageplane(self):
        self.createVis()
        telescope = 'MID'
        lflux = numpy.array([[100.0, 1.0, -10.0, +60.0]])
        cflux = numpy.array([[100.0, 60.0, -10.0, +1.0]])
        apply_pb = True
        for flux, vpol in ((lflux, PolarisationFrame("linear")),
                           (cflux, PolarisationFrame("circular"))):
            # print("Testing {0}".format(vpol.type))
            # print("Original flux = {}".format(flux))
            bvis = create_blockvisibility(
                self.config,
                self.times,
                self.frequency,
                channel_bandwidth=self.channel_bandwidth,
                phasecentre=self.phasecentre,
                weight=1.0,
                polarisation_frame=vpol,
                zerow=True)

            component_centre = SkyCoord(ra=+15.5 * u.deg,
                                        dec=-35.0 * u.deg,
                                        frame='icrs',
                                        equinox='J2000')
            component = create_skycomponent(
                direction=component_centre,
                flux=flux,
                frequency=self.frequency,
                polarisation_frame=PolarisationFrame("stokesIQUV"))
            model = create_image_from_visibility(
                bvis,
                cellsize=self.cellsize,
                npixel=self.npixel,
                override_cellsize=False,
                polarisation_frame=PolarisationFrame("stokesIQUV"))
            pb = create_pb(model, telescope=telescope, use_local=False)
            if apply_pb:
                pbcomp = apply_beam_to_skycomponent(component, pb)
                # print("After application of primary beam {}".format(str(pbcomp.flux)))
            else:
                pbcomp = copy_skycomponent(component)
            bvis = dft_skycomponent_visibility(bvis, pbcomp)
            iquv_image = idft_visibility_skycomponent(bvis, component)[0]
 def test_dft_idft_stokesiquv_visibility(self):
     for vpol in [
             PolarisationFrame("linear"),
             PolarisationFrame("circular")
     ]:
         self.vis = create_visibility(
             self.lowcore,
             self.times,
             self.frequency,
             channel_bandwidth=self.channel_bandwidth,
             phasecentre=self.phasecentre,
             weight=1.0,
             polarisation_frame=PolarisationFrame("stokesIQUV"))
         self.vismodel = dft_skycomponent_visibility(self.vis, self.comp)
         rcomp, weights = idft_visibility_skycomponent(
             self.vismodel, self.comp)
         assert_allclose(self.comp.flux,
                         numpy.real(rcomp[0].flux),
                         rtol=1e-11)
Esempio n. 3
0
    def test_apply_voltage_pattern_image_pointsource(self):
        self.createVis(rmax=1e3)
        telescope = 'MID_FEKO_B2'
        vpol = PolarisationFrame("linear")
        self.times = numpy.linspace(-4, +4, 8) * numpy.pi / 12.0
        bvis = create_blockvisibility(self.config,
                                      self.times,
                                      self.frequency,
                                      channel_bandwidth=self.channel_bandwidth,
                                      phasecentre=self.phasecentre,
                                      weight=1.0,
                                      polarisation_frame=vpol,
                                      zerow=True)
        cellsize = advise_wide_field(bvis)['cellsize']

        pbmodel = create_image_from_visibility(
            bvis,
            cellsize=self.cellsize,
            npixel=self.npixel,
            override_cellsize=False,
            polarisation_frame=PolarisationFrame("stokesIQUV"))
        vpbeam = create_vp(pbmodel, telescope=telescope, use_local=False)
        vpbeam.wcs.wcs.ctype[0] = 'RA---SIN'
        vpbeam.wcs.wcs.ctype[1] = 'DEC--SIN'
        vpbeam.wcs.wcs.crval[0] = pbmodel.wcs.wcs.crval[0]
        vpbeam.wcs.wcs.crval[1] = pbmodel.wcs.wcs.crval[1]

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

        for comp in s3_components:
            comp.polarisation_frame = PolarisationFrame('stokesIQUV')
            comp.flux = numpy.array([[comp.flux[0, 0], 0.0, 0.0, 0.0]])

        s3_components = filter_skycomponents_by_flux(s3_components, 0.0, 10.0)

        from rascil.processing_components.image import show_image
        import matplotlib.pyplot as plt
        plt.clf()
        show_image(vpbeam, components=s3_components)
        plt.show(block=False)

        vpcomp = apply_voltage_pattern_to_skycomponent(s3_components, vpbeam)
        bvis.data['vis'][...] = 0.0 + 0.0j
        bvis = dft_skycomponent_visibility(bvis, vpcomp)

        rec_comp = idft_visibility_skycomponent(bvis, vpcomp)[0]

        stokes_comp = list()
        for comp in rec_comp:
            stokes_comp.append(
                convert_pol_frame(comp.flux[0], PolarisationFrame("linear"),
                                  PolarisationFrame("stokesIQUV")))

        stokesI = numpy.abs(
            numpy.array([comp_flux[0] for comp_flux in stokes_comp]).real)
        stokesQ = numpy.abs(
            numpy.array([comp_flux[1] for comp_flux in stokes_comp]).real)
        stokesU = numpy.abs(
            numpy.array([comp_flux[2] for comp_flux in stokes_comp]).real)
        stokesV = numpy.abs(
            numpy.array([comp_flux[3] for comp_flux in stokes_comp]).real)
        plt.clf()
        plt.loglog(stokesI, stokesQ, '.', label='Q')
        plt.loglog(stokesI, stokesU, '.', label='U')
        plt.loglog(stokesI, stokesV, '.', label='V')
        plt.xlabel("Stokes Flux I (Jy)")
        plt.ylabel("Flux (Jy)")
        plt.legend()
        plt.savefig('%s/test_primary_beams_pol_rsexecute_stokes_errors.png' %
                    self.dir)
        plt.show(block=False)

        split_times = False
        if split_times:
            bvis_list = list()
            for rows in vis_timeslice_iter(bvis, vis_slices=8):
                bvis_list.append(create_visibility_from_rows(bvis, rows))
        else:
            bvis_list = [bvis]

        bvis_list = rsexecute.scatter(bvis_list)

        model_list = \
            [rsexecute.execute(create_image_from_visibility, nout=1)(bv, cellsize=cellsize, npixel=4096,
                                                                     phasecentre=self.phasecentre,
                                                                     override_cellsize=False,
                                                                     polarisation_frame=PolarisationFrame("stokesIQUV"))
             for bv in bvis_list]

        model_list = rsexecute.persist(model_list)
        bvis_list = weight_list_rsexecute_workflow(bvis_list, model_list)

        continuum_imaging_list = \
            continuum_imaging_list_rsexecute_workflow(bvis_list, model_list,
                                                      context='2d',
                                                      algorithm='hogbom',
                                                      facets=1,
                                                      niter=1000,
                                                      fractional_threshold=0.1,
                                                      threshold=1e-4,
                                                      nmajor=5, gain=0.1,
                                                      deconvolve_facets=4,
                                                      deconvolve_overlap=32,
                                                      deconvolve_taper='tukey',
                                                      psf_support=64,
                                                      restore_facets=4, psfwidth=1.0)
        clean, residual, restored = rsexecute.compute(continuum_imaging_list,
                                                      sync=True)
        centre = 0
        if self.persist:
            export_image_to_fits(
                clean[centre],
                '%s/test_primary_beams_pol_rsexecute_clean.fits' % self.dir)
            export_image_to_fits(
                residual[centre][0],
                '%s/test_primary_beams_pol_rsexecute_residual.fits' % self.dir)
            export_image_to_fits(
                restored[centre],
                '%s/test_primary_beams_pol_rsexecute_restored.fits' % self.dir)

        plt.clf()
        show_image(restored[centre])
        plt.show(block=False)

        qa = qa_image(restored[centre])
        assert numpy.abs(qa.data['max'] - 0.9953017707113947) < 1.0e-7, str(qa)
        assert numpy.abs(qa.data['min'] +
                         0.0036396480874570846) < 1.0e-7, str(qa)
Esempio n. 4
0
    def test_apply_voltage_pattern_dft(self):
        self.createVis()
        nfailures = 0
        telescope = 'MID_FEKO_B2'
        for flux in (numpy.array([[100.0, 0.0, 0.0, 0.0]]),
                     numpy.array([[100.0, 100.0, 0.0, 0.0]]),
                     numpy.array([[100.0, 0.0, 100.0, 0.0]]),
                     numpy.array([[100.0, 0.0, 0.0, 100.0]]),
                     numpy.array([[100.0, 1.0, -10.0, +60.0]])):
            vpol = PolarisationFrame("linear")
            try:
                bvis = create_blockvisibility(
                    self.config,
                    self.times,
                    self.frequency,
                    channel_bandwidth=self.channel_bandwidth,
                    phasecentre=self.phasecentre,
                    weight=1.0,
                    polarisation_frame=vpol)

                component_centre = SkyCoord(ra=+16.0 * u.deg,
                                            dec=-35.0 * u.deg,
                                            frame='icrs',
                                            equinox='J2000')
                component = create_skycomponent(
                    direction=component_centre,
                    flux=flux,
                    frequency=self.frequency,
                    polarisation_frame=PolarisationFrame("stokesIQUV"))
                model = create_image_from_visibility(
                    bvis,
                    cellsize=self.cellsize,
                    npixel=self.npixel,
                    override_cellsize=False,
                    polarisation_frame=PolarisationFrame("stokesIQUV"))
                vpbeam = create_vp(model, telescope=telescope, use_local=False)
                vpbeam.wcs.wcs.ctype[0] = 'RA---SIN'
                vpbeam.wcs.wcs.ctype[1] = 'DEC--SIN'
                vpbeam.wcs.wcs.crval[0] = model.wcs.wcs.crval[0]
                vpbeam.wcs.wcs.crval[1] = model.wcs.wcs.crval[1]
                assert component.polarisation_frame == PolarisationFrame(
                    "stokesIQUV")
                vpcomp = apply_voltage_pattern_to_skycomponent(
                    component, vpbeam)
                assert vpcomp.polarisation_frame == vpbeam.polarisation_frame
                bvis = dft_skycomponent_visibility(bvis, vpcomp)
                vpcomp = idft_visibility_skycomponent(bvis, vpcomp)[0][0]
                assert vpcomp.polarisation_frame == bvis.polarisation_frame
                inv_vpcomp = apply_voltage_pattern_to_skycomponent(
                    vpcomp, vpbeam, inverse=True)
                assert vpcomp.polarisation_frame == PolarisationFrame(
                    "stokesIQUV")
                # print("After application of primary beam {}".format(str(vpcomp.flux)))
                # print("After correction of primary beam {}".format(str(inv_vpcomp.flux)))
                # print("{0} {1} succeeded".format(vpol, str(flux)))
                assert_array_almost_equal(flux, numpy.real(inv_vpcomp.flux), 9)
            except AssertionError as e:
                print(e)
                print("{0} {1} failed".format(vpol, str(flux)))
                nfailures += 1
        assert nfailures == 0, "{} tests failed".format(nfailures)