예제 #1
0
def reppre_ifft_kernel(ix, data_extract_lsm, dep_image, insert_method,
                       applybeam):
    frequency = dep_image["frequency"]
    comps = []
    for i in data_extract_lsm.value:
        if i[0][2] == ix[2]:
            comps = i[1]

    wcs = dep_image["wcs"]
    shape = dep_image["shape"]
    polarisation_frame = dep_image["polarisation_frame"]
    model = create_image_from_array(np.zeros(shape),
                                    wcs,
                                    polarisation_frame=polarisation_frame)

    model = insert_skycomponent(model, comps, insert_method=insert_method)

    if applybeam:
        beam = create_low_test_beam(model)
        model.data = model.data * beam

    result = model
    label = "Reprojection Predict + IFFT (14645.6 MB, 2.56 Tflop) "
    # print(label + str(result))
    return result
예제 #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)
        export_image_to_fits(bm, '%s/test_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 setUp(self):
     self.dir = './test_results'
     os.makedirs(self.dir, exist_ok=True)
     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'))
     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)
     beam = create_low_test_beam(self.test_model)
     export_image_to_fits(beam, "%s/test_deconvolve_msmfsclean_beam.fits" % self.dir)
     self.test_model.data *= beam.data
     export_image_to_fits(self.test_model, "%s/test_deconvolve_msmfsclean_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)
     export_image_to_fits(self.dirty, "%s/test_deconvolve_msmfsclean_dirty.fits" % self.dir)
     export_image_to_fits(self.psf, "%s/test_deconvolve_msmfsclean_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)
예제 #4
0
 def calculate_gleam_model(vis):
     model = create_low_test_image_from_gleam(
         npixel=npixel,
         frequency=frequency,
         channel_bandwidth=channel_bandwidth,
         cellsize=cellsize,
         phasecentre=vis.phasecentre)
     beam = create_low_test_beam(model)
     model.data *= beam.data
     return model
 def test_create_low_test_skycomponents_from_gleam_apply_beam(self):
     sc = create_low_test_skycomponents_from_gleam(flux_limit=10.0,
                                                   polarisation_frame=PolarisationFrame("stokesI"),
                                                   frequency=self.frequency, kind='cubic')
     assert len(sc) > 1
     assert sc[190].name == 'GLEAM J172031-005845'
     #        self.assertAlmostEqual(sc[190].flux[0,0], 301.4964434927922, 7)
     im = create_test_image(canonical=True, cellsize=0.002,
                            frequency=self.frequency,
                            channel_bandwidth=self.channel_bandwidth,
                            polarisation_frame=PolarisationFrame("stokesI"),
                            phasecentre=self.phasecentre)
     bm = create_low_test_beam(model=im)
     sc = apply_beam_to_skycomponent(sc, bm)
     assert len(sc) > 1, "No components inside image"
    def test_peel_skycomponent_blockvisibility(self):
        df = 1e6
        frequency = numpy.array([1e8 - df, 1e8, 1e8 + df])
        channel_bandwidth = numpy.array([df, df, df])

        # Define the component and give it some spectral behaviour
        f = numpy.array([100.0, 20.0, -10.0, 1.0])
        flux = numpy.array([f, 0.8 * f, 0.6 * f])
        phasecentre = SkyCoord(0 * u.deg, -60.0 * u.deg)

        config = create_named_configuration('LOWBD2-CORE')
        peeldirection = SkyCoord(+15 * u.deg, -60.0 * u.deg)
        times = numpy.linspace(-3.0, 3.0, 7) * numpy.pi / 12.0

        # Make the visibility
        vis = create_blockvisibility(
            config,
            times,
            frequency,
            phasecentre=phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('linear'),
            channel_bandwidth=channel_bandwidth)
        vis.data['vis'][...] = 0.0

        # First add in the source to be peeled.
        peel = Skycomponent(direction=peeldirection,
                            frequency=frequency,
                            flux=flux,
                            polarisation_frame=PolarisationFrame("stokesIQUV"))
        vis = predict_skycomponent_visibility(vis, peel)

        # Make a gaintable and apply it to the visibility of the peeling source
        gt = create_gaintable_from_blockvisibility(vis, timeslice='auto')
        gt = simulate_gaintable(gt,
                                phase_error=0.01,
                                amplitude_error=0.01,
                                timeslice='auto')
        gt.data['gain'] *= 0.3
        vis = apply_gaintable(vis, gt, timeslice='auto')

        # Now create a plausible field using the GLEAM sources
        model = create_image_from_visibility(
            vis,
            cellsize=0.001,
            frequency=frequency,
            polarisation_frame=PolarisationFrame('stokesIQUV'))

        bm = create_low_test_beam(model=model)
        sc = create_low_test_skycomponents_from_gleam(
            flux_limit=1.0,
            polarisation_frame=PolarisationFrame("stokesIQUV"),
            frequency=frequency,
            kind='cubic',
            phasecentre=phasecentre,
            radius=0.1)
        sc = apply_beam_to_skycomponent(sc, bm)
        # Add in the visibility due to these sources
        vis = predict_skycomponent_visibility(vis, sc)
        assert numpy.max(numpy.abs(vis.vis)) > 0.0

        # Now we can peel
        vis, peel_gts = peel_skycomponent_blockvisibility(vis, peel)

        assert len(peel_gts) == 1
        residual = numpy.max(peel_gts[0].residual)
        assert residual < 0.7, "Peak residual %.6f too large" % (residual)

        im, sumwt = invert_timeslice(vis, model, timeslice='auto')
        qa = qa_image(im)

        assert numpy.abs(qa.data['max'] - 14.2) < 1.0, str(qa)
    def actualSetUp(self, time=None, dospectral=False, dopol=False):
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5)

        if time is not None:
            self.times = time
        log.info("Times are %s" % self.times)

        if dospectral:
            self.nchan = 3
            self.frequency = numpy.array([0.9e8, 1e8, 1.1e8])
            self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7])
        else:
            self.frequency = numpy.array([1e8])
            self.channel_bandwidth = numpy.array([1e7])

        if dopol:
            self.vis_pol = PolarisationFrame('linear')
            self.image_pol = PolarisationFrame('stokesIQUV')
            f = numpy.array([100.0, 20.0, -10.0, 1.0])
        else:
            self.vis_pol = PolarisationFrame('stokesI')
            self.image_pol = PolarisationFrame('stokesI')
            f = numpy.array([100.0])

        if dospectral:
            flux = numpy.array([f, 0.8 * f, 0.6 * f])
        else:
            flux = numpy.array([f])

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.componentvis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=self.vis_pol)
        self.uvw = self.componentvis.data['uvw']
        self.componentvis.data['vis'][...] = 0.0

        # Create model
        self.model = create_image_from_visibility(
            self.componentvis,
            npixel=self.params['npixel'],
            cellsize=0.0005,
            nchan=len(self.frequency),
            polarisation_frame=self.image_pol)

        # Fill the visibility with exactly computed point sources.
        spacing_pixels = 512 // 8
        log.info('Spacing in pixels = %s' % spacing_pixels)

        centers = [(x, x) for x in numpy.linspace(-1.4, +1.4, 9)]

        for x in numpy.linspace(-1.4, +1.4, 9):
            centers.append((-x, x))

        centers.append((0.5, 1.1))
        centers.append((1e-7, 1e-7))

        # Make the list of components
        rpix = self.model.wcs.wcs.crpix
        self.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(self.model.wcs.wcs.cdelt[0]))), \
                int(round(rpix[1] + iy * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[1])))
            sc = pixel_to_skycoord(p[0], p[1], self.model.wcs, origin=1)
            log.info("Component at (%f, %f) [0-rel] %s" %
                     (p[0], p[1], str(sc)))

            if ix != 0 and iy != 0:
                # Channel images
                comp = create_skycomponent(flux=flux,
                                           frequency=self.frequency,
                                           direction=sc,
                                           polarisation_frame=self.image_pol)
                self.components.append(comp)

        # Predict the visibility from the components exactly
        self.componentvis.data['vis'] *= 0.0
        self.beam = create_low_test_beam(self.model)

        self.components = apply_beam_to_skycomponent(self.components,
                                                     self.beam)
        self.componentvis = predict_skycomponent_visibility(
            self.componentvis, self.components)
        self.model = insert_skycomponent(self.model, self.components)

        # Calculate the model convolved with a Gaussian.
        self.cmodel = smooth_image(self.model)
        export_image_to_fits(self.model,
                             '%s/test_imaging_functions_model.fits' % self.dir)
        export_image_to_fits(
            self.cmodel, '%s/test_imaging_functions_cmodel.fits' % self.dir)
 def actualSetup(self, sky_pol_frame='stokesI', data_pol_frame='stokesI', f=None, vnchan=1, doiso=True,
                 ntimes=1, flux_limit=18.0):
     
     nfreqwin = vnchan
     ntimes = ntimes
     rmax = 300.0
     npixel = 1024
     cellsize = 0.001
     frequency = numpy.linspace(0.8e8, 1.2e8, nfreqwin)
     if nfreqwin > 1:
         channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]])
     else:
         channel_bandwidth = [0.4e8]
     times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)
     
     phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')
     
     lowcore = create_named_configuration('LOWBD2', rmax=rmax)
     
     block_vis = create_blockvisibility(lowcore, times, frequency=frequency, channel_bandwidth=channel_bandwidth,
                                        weight=1.0, phasecentre=phasecentre,
                                        polarisation_frame=PolarisationFrame("stokesI"))
     
     block_vis.data['uvw'][..., 2] = 0.0
     self.beam = create_image_from_visibility(block_vis, npixel=npixel, frequency=[numpy.average(frequency)],
                                              nchan=nfreqwin,
                                              channel_bandwidth=[numpy.sum(channel_bandwidth)], cellsize=cellsize,
                                              phasecentre=phasecentre)
     
     self.components = create_low_test_skycomponents_from_gleam(flux_limit=flux_limit, phasecentre=phasecentre,
                                                                frequency=frequency,
                                                                polarisation_frame=PolarisationFrame('stokesI'),
                                                                radius=npixel * cellsize)
     self.beam = create_low_test_beam(self.beam)
     self.components = apply_beam_to_skycomponent(self.components, self.beam, flux_limit=flux_limit / 100.0)
     print("Number of components %d" % len(self.components))
     
     self.vis = copy_visibility(block_vis, zero=True)
     gt = create_gaintable_from_blockvisibility(block_vis, timeslice='auto')
     for i, sc in enumerate(self.components):
         if sc.flux[0, 0] > 10:
             sc.flux[...] /= 10.0
         print('Component %d, flux = %s' % (i, str(sc.flux[0, 0])))
         component_vis = copy_visibility(block_vis, zero=True)
         gt = simulate_gaintable(gt, amplitude_error=0.0, phase_error=0.1, seed=None)
         component_vis = predict_skycomponent_visibility(component_vis, sc)
         component_vis = apply_gaintable(component_vis, gt)
         self.vis.data['vis'][...] += component_vis.data['vis'][...]
     
     # Do an isoplanatic selfcal
     self.model_vis = copy_visibility(self.vis, zero=True)
     self.model_vis = predict_skycomponent_visibility(self.model_vis, self.components)
     if doiso:
         gt = solve_gaintable(self.vis, self.model_vis, phase_only=True, timeslice='auto')
         self.vis = apply_gaintable(self.vis, gt, inverse=True)
     
     self.model_vis = convert_blockvisibility_to_visibility(self.model_vis)
     self.model_vis, _, _ = weight_visibility(self.model_vis, self.beam)
     self.dirty_model, sumwt = invert_function(self.model_vis, self.beam, context='2d')
     export_image_to_fits(self.dirty_model, "%s/test_sagecal-model_dirty.fits" % self.dir)
     
     lvis = convert_blockvisibility_to_visibility(self.vis)
     lvis, _, _ = weight_visibility(lvis, self.beam)
     dirty, sumwt = invert_function(lvis, self.beam, context='2d')
     print(qa_image(dirty))
     export_image_to_fits(dirty, "%s/test_sagecal-initial_dirty.fits" % self.dir)