def test_scatter_gather_facet_overlap_taper(self):
 
     m31original = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
     assert numpy.max(numpy.abs(m31original.data)), "Original is empty"
 
     for taper in ['linear', None]:
         for nraster, overlap in [(1, 0), (4, 8), (8, 8), (8, 16)]:
             m31model = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
             image_list = image_scatter_facets(m31model, facets=nraster, overlap=overlap, taper=taper)
             for patch in image_list:
                 assert patch.data.shape[3] == (2 * overlap + m31model.data.shape[3] // nraster), \
                     "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[3],
                                                                                 (2 * overlap + m31model.data.shape[3] //
                                                                                  nraster))
                 assert patch.data.shape[2] == (2 * overlap + m31model.data.shape[2] // nraster), \
                     "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[2],
                                                                                 (2 * overlap + m31model.data.shape[2] //
                                                                                  nraster))
             m31reconstructed = create_empty_image_like(m31model)
             m31reconstructed = image_gather_facets(image_list, m31reconstructed, facets=nraster, overlap=overlap,
                                                    taper=taper)
             flat = image_gather_facets(image_list, m31reconstructed, facets=nraster, overlap=overlap,
                                        taper=taper, return_flat=True)
             export_image_to_fits(m31reconstructed,
                                  "%s/test_image_gather_scatter_%dnraster_%doverlap_%s_reconstructed.fits" %
                                  (self.dir, nraster, overlap, taper))
             export_image_to_fits(flat,
                                  "%s/test_image_gather_scatter_%dnraster_%doverlap_%s_flat.fits" %
                                  (self.dir, nraster, overlap, taper))
 
             assert numpy.max(numpy.abs(flat.data)), "Flat is empty for %d" % nraster
             assert numpy.max(numpy.abs(m31reconstructed.data)), "Raster is empty for %d" % nraster
Exemple #2
0
 def test_raster_exception(self):
 
     m31original = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
     assert numpy.max(numpy.abs(m31original.data)), "Original is empty"
 
     for nraster, overlap in [(1, 1e6), (2, 128), (1e6, 127)]:
         
         with self.assertRaises(AssertionError) as context:
             m31model = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
             for patch in image_raster_iter(m31model, facets=nraster, overlap=overlap):
                 patch.data *= 2.0
Exemple #3
0
 def test_raster_overlap(self):
 
     m31original = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
     assert numpy.max(numpy.abs(m31original.data)), "Original is empty"
     flat = create_empty_image_like(m31original)
 
     for nraster, overlap in [(1, 0),  (1, 16), (4, 8), (4, 16), (8, 8), (16, 4), (9, 5)]:
         m31model = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
         for patch, flat_patch in zip(image_raster_iter(m31model, facets=nraster, overlap=overlap),
                                      image_raster_iter(flat, facets=nraster, overlap=overlap)):
             patch.data *= 2.0
             flat_patch.data[...] += 1.0
     
         assert numpy.max(numpy.abs(m31model.data)), "Raster is empty for %d" % nraster
    def test_readwriteimage(self):
        im = create_test_image()
        export_image_to_hdf5(im, '%s/test_image.hdf' % self.dir)
        newim = import_image_from_hdf5('%s/test_image.hdf' % self.dir)

        assert newim.data.shape == im.data.shape
        assert numpy.max(numpy.abs(im.data - newim.data)) < 1e-15
    def test_polarisation_frame_from_wcs(self):
        assert self.m31image.polarisation_frame == PolarisationFrame("stokesI")
        stokes = create_test_image(
            cellsize=0.0001,
            polarisation_frame=PolarisationFrame("stokesIQUV"))
        wcs = stokes.wcs.deepcopy()
        shape = stokes.shape
        assert polarisation_frame_from_wcs(
            wcs, shape) == PolarisationFrame("stokesIQUV")

        wcs = stokes.wcs.deepcopy().sub(['stokes'])
        wcs.wcs.crpix[0] = 1.0
        wcs.wcs.crval[0] = -1.0
        wcs.wcs.cdelt[0] = -1.0
        assert polarisation_frame_from_wcs(
            wcs, shape) == PolarisationFrame('circular')

        wcs.wcs.crpix[0] = 1.0
        wcs.wcs.crval[0] = -5.0
        wcs.wcs.cdelt[0] = -1.0
        assert polarisation_frame_from_wcs(
            wcs, shape) == PolarisationFrame('linear')

        wcs.wcs.crpix[0] = 1.0
        wcs.wcs.crval[0] = -1.0
        wcs.wcs.cdelt[0] = -1.0
        assert polarisation_frame_from_wcs(
            wcs, shape) == PolarisationFrame('circular')

        with self.assertRaises(ValueError):
            wcs.wcs.crpix[0] = 1.0
            wcs.wcs.crval[0] = -100.0
            wcs.wcs.cdelt[0] = -1.0
            polarisation_frame_from_wcs(wcs, shape)
Exemple #6
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_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
Exemple #7
0
    def test_create_vis_iter_with_model(self):
        model = create_test_image(canonical=True,
                                  cellsize=0.001,
                                  frequency=self.frequency,
                                  phasecentre=self.phasecentre)
        comp = Skycomponent(direction=self.phasecentre,
                            frequency=self.frequency,
                            flux=self.flux,
                            polarisation_frame=PolarisationFrame('stokesI'))
        vis_iter = create_blockvisibility_iterator(
            self.config,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'),
            integration_time=30.0,
            number_integrations=3,
            model=model,
            components=comp)

        fullvis = None
        totalnvis = 0
        for i, vis in enumerate(vis_iter):
            assert vis.phasecentre == self.phasecentre
            assert vis.nvis
            if i == 0:
                fullvis = vis
                totalnvis = vis.nvis
            else:
                fullvis = append_visibility(fullvis, vis)
                totalnvis += vis.nvis

        assert fullvis.nvis == totalnvis
Exemple #8
0
 def test_channelise(self):
     m31cube = create_test_image(polarisation_frame=PolarisationFrame('stokesI'),
                                     frequency=numpy.linspace(1e8,1.1e8, 128))
     
     for subimages in [128, 16, 8, 2, 1]:
         for slab in image_channel_iter(m31cube, subimages=subimages):
             assert slab.data.shape[0] == 128 // subimages
    def setUp(self):

        from data_models.parameters import arl_path
        self.dir = arl_path('test_results')

        self.m31image = create_test_image(cellsize=0.0001)
        self.cellsize = 180.0 * 0.0001 / numpy.pi
Exemple #10
0
    def setUp(self):
        from data_models.parameters import arl_path
        self.lowcore = create_named_configuration('LOWBD2', rmax=300.0)
        self.dir = arl_path('test_results')
        self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7)
        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e6])
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_blockvisibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.vis.data['vis'] *= 0.0

        # Create model
        self.model = create_test_image(cellsize=0.0015,
                                       phasecentre=self.vis.phasecentre,
                                       frequency=self.frequency)
        self.model.data[self.model.data > 1.0] = 1.0
 def test_gather_channel(self):
     for nchan in [128, 16]:
         m31cube = create_test_image(polarisation_frame=PolarisationFrame('stokesI'),
                                     frequency=numpy.linspace(1e8, 1.1e8, nchan))
         image_list = image_scatter_channels(m31cube, subimages=nchan)
         m31cuberec = image_gather_channels(image_list, None, subimages=nchan)
         assert m31cube.shape == m31cuberec.shape
         diff = m31cube.data - m31cuberec.data
         assert numpy.max(numpy.abs(diff)) == 0.0, "Scatter gather failed for %d" % nchan
Exemple #12
0
 def test_create_test_image(self):
     im = create_test_image(canonical=False)
     assert len(im.data.shape) == 2
     im = create_test_image(canonical=True)
     assert len(im.data.shape) == 4
     im = create_test_image(canonical=True,
                            frequency=numpy.array([1e8]),
                            polarisation_frame=PolarisationFrame('stokesI'))
     assert len(im.data.shape) == 4
     assert im.data.shape[0] == 1
     assert im.data.shape[1] == 1
     im = create_test_image(
         canonical=True,
         frequency=numpy.array([1e8]),
         polarisation_frame=PolarisationFrame('stokesIQUV'))
     assert len(im.data.shape) == 4
     assert im.data.shape[0] == 1
     assert im.data.shape[1] == 4
    def test_readwriteskymodel(self):
        im = create_test_image()
        sm = SkyModel(components=[self.comp], images=[im, im])
        export_skymodel_to_hdf5(sm, '%s/test_skymodel.hdf' % self.dir)
        newsm = import_skymodel_from_hdf5('%s/test_skymodel.hdf' % self.dir)

        assert newsm.components[0].flux.shape == self.comp.flux.shape
        assert newsm.images[0].data.shape == im.data.shape
        assert numpy.max(numpy.abs(newsm.images[0].data - im.data)) < 1e-15
Exemple #14
0
 def test_raster(self):
     
     m31original = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
     assert numpy.max(numpy.abs(m31original.data)), "Original is empty"
     
     for nraster in [1, 2, 4, 8, 9]:
         m31model = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
         for patch in image_raster_iter(m31model, facets=nraster):
             assert patch.data.shape[3] == (m31model.data.shape[3] // nraster), \
                 "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[3],
                                                                             (m31model.data.shape[3] // nraster))
             assert patch.data.shape[2] == (m31model.data.shape[2] // nraster), \
                 "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[2],
                                                                             (m31model.data.shape[2] // nraster))
             patch.data *= 2.0
         
         diff = m31model.data - 2.0 * m31original.data
         assert numpy.max(numpy.abs(m31model.data)), "Raster is empty for %d" % nraster
         assert numpy.max(numpy.abs(diff)) == 0.0, "Raster set failed for %d" % nraster
 def test_fftim(self):
     self.m31image = create_test_image(cellsize=0.001,
                                       frequency=[1e8],
                                       canonical=True)
     m31_fft = fft_image(self.m31image)
     m31_fft_ifft = fft_image(m31_fft, self.m31image)
     numpy.testing.assert_array_almost_equal(self.m31image.data,
                                             m31_fft_ifft.data.real, 12)
     m31_fft.data = numpy.abs(m31_fft.data)
     export_image_to_fits(m31_fft,
                          fitsfile='%s/test_m31_fft.fits' % (self.dir))
 def test_create_w_term_image(self):
     m31image = create_test_image(cellsize=0.001)
     im = create_w_term_like(m31image, w=20000.0, remove_shift=True)
     im.data = im.data.real
     for x in [64, 64 + 128]:
         for y in [64, 64 + 128]:
             self.assertAlmostEqual(im.data[0, 0, y, x],
                                    0.84946344276442431, 7)
     export_image_to_fits(im, '%s/test_wterm.fits' % self.dir)
     assert im.data.shape == (1, 1, 256, 256)
     self.assertAlmostEqual(numpy.max(im.data.real), 1.0, 7)
 def test_convert_image_to_kernel(self):
     m31image = create_test_image(cellsize=0.001,
                                  frequency=[1e8],
                                  canonical=True)
     screen = create_w_term_like(m31image, w=20000.0, remove_shift=True)
     screen_fft = fft_image(screen)
     converted = convert_image_to_kernel(screen_fft, 8, 8)
     assert converted.shape == (1, 1, 8, 8, 8, 8)
     with self.assertRaises(AssertionError):
         converted = convert_image_to_kernel(m31image, 15, 1)
     with self.assertRaises(AssertionError):
         converted = convert_image_to_kernel(m31image, 15, 1000)
    def test_scatter_gather_facet(self):
        
        m31original = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
        assert numpy.max(numpy.abs(m31original.data)), "Original is empty"
        
        for nraster in [1, 4, 8]:
            m31model = create_test_image(polarisation_frame=PolarisationFrame('stokesI'))
            image_list = image_scatter_facets(m31model, facets=nraster)
            for patch in image_list:
                assert patch.data.shape[3] == (m31model.data.shape[3] // nraster), \
                    "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[3],
                                                                                (m31model.data.shape[3] // nraster))
                assert patch.data.shape[2] == (m31model.data.shape[2] // nraster), \
                    "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[2],
                                                                                (m31model.data.shape[2] // nraster))
                patch.data[...] = 1.0
            m31reconstructed = create_empty_image_like(m31model)
            m31reconstructed = image_gather_facets(image_list, m31reconstructed, facets=nraster)
            flat = image_gather_facets(image_list, m31reconstructed, facets=nraster, return_flat=True)

            assert numpy.max(numpy.abs(flat.data)), "Flat is empty for %d" % nraster
            assert numpy.max(numpy.abs(m31reconstructed.data)), "Raster is empty for %d" % nraster
    def test_pad_image(self):
        m31image = create_test_image(cellsize=0.001,
                                     frequency=[1e8],
                                     canonical=True)
        padded = pad_image(m31image, [1, 1, 1024, 1024])
        assert padded.shape == (1, 1, 1024, 1024)

        padded = pad_image(m31image, [3, 4, 2048, 2048])
        assert padded.shape == (3, 4, 2048, 2048)

        with self.assertRaises(ValueError):
            padded = pad_image(m31image, [1, 1, 100, 100])

        with self.assertRaises(IndexError):
            padded = pad_image(m31image, [1, 1])
 def test_fftim_factors(self):
     for i in [3, 5, 7]:
         npixel = 256 * i
         m31image = create_test_image(cellsize=0.001,
                                      frequency=[1e8],
                                      canonical=True)
         padded = pad_image(m31image, [1, 1, npixel, npixel])
         assert padded.shape == (1, 1, npixel, npixel)
         padded_fft = fft_image(padded)
         padded_fft_ifft = fft_image(padded_fft, m31image)
         numpy.testing.assert_array_almost_equal(padded.data,
                                                 padded_fft_ifft.data.real,
                                                 12)
         padded_fft.data = numpy.abs(padded_fft.data)
         export_image_to_fits(padded_fft,
                              fitsfile='%s/test_m31_fft_%d.fits' %
                              (self.dir, npixel))
    def test_stokes_conversion(self):
        assert self.m31image.polarisation_frame == PolarisationFrame("stokesI")
        stokes = create_test_image(
            cellsize=0.0001,
            polarisation_frame=PolarisationFrame("stokesIQUV"))
        assert stokes.polarisation_frame == PolarisationFrame("stokesIQUV")

        for pol_name in ['circular', 'linear']:
            polarisation_frame = PolarisationFrame(pol_name)
            polimage = convert_stokes_to_polimage(
                stokes, polarisation_frame=polarisation_frame)
            assert polimage.polarisation_frame == polarisation_frame
            polarisation_frame_from_wcs(polimage.wcs, polimage.shape)
            rstokes = convert_polimage_to_stokes(polimage)
            assert polimage.data.dtype == 'complex'
            assert rstokes.data.dtype == 'complex'
            numpy.testing.assert_array_almost_equal(stokes.data,
                                                    rstokes.data.real, 12)
Exemple #22
0
    def setUp(self):

        arlexecute.set_client(use_dask=False)

        from data_models.parameters import arl_path
        self.dir = arl_path('test_results')
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = numpy.linspace(-3, +3, 13) * (numpy.pi / 12.0)

        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e7])

        # Define the component and give it some polarisation and spectral behaviour
        f = numpy.array([100.0])
        self.flux = numpy.array([f])

        self.phasecentre = SkyCoord(ra=+15.0 * u.deg,
                                    dec=-35.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.compabsdirection = SkyCoord(ra=17.0 * u.deg,
                                         dec=-36.5 * u.deg,
                                         frame='icrs',
                                         equinox='J2000')

        self.comp = create_skycomponent(
            direction=self.compabsdirection,
            flux=self.flux,
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.image = create_test_image(
            frequency=self.frequency,
            phasecentre=self.phasecentre,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.image.data[self.image.data < 0.0] = 0.0

        self.image_graph = arlexecute.execute(create_test_image)(
            frequency=self.frequency,
            phasecentre=self.phasecentre,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame('stokesI'))
    def setUp(self):
        from data_models.parameters import arl_path
        self.dir = arl_path('test_results')
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)
        self.frequency = numpy.array([1e8])
        self.channel_bandwidth = numpy.array([1e6])
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=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_test_image(cellsize=0.001,
                                            phasecentre=self.vis.phasecentre,
                                            frequency=self.frequency)
        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)
        window = numpy.zeros(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'))
    def setUp(self):
        from data_models.parameters import arl_path
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.dir = arl_path('test_results')
        self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)
        self.nchan = 8
        self.frequency = numpy.linspace(0.8e8, 1.2e8, self.nchan)
        self.channel_bandwidth = numpy.array(
            self.nchan * [self.frequency[1] - self.frequency[0]])
        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.vis = create_visibility(
            self.lowcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            weight=1.0,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.vis.data['vis'] *= 0.0

        # Create model
        self.model = create_test_image(cellsize=0.0015,
                                       phasecentre=self.vis.phasecentre,
                                       frequency=self.frequency)
        self.model.data[self.model.data > 1.0] = 1.0
        self.vis = predict_2d(self.vis, self.model)
        assert numpy.max(numpy.abs(self.vis.vis)) > 0.0
        export_image_to_fits(self.model,
                             '%s/test_solve_image_mm_model.fits' % (self.dir))
        self.bigmodel = create_image_from_visibility(self.vis,
                                                     cellsize=0.0015,
                                                     npixel=512,
                                                     frequency=self.frequency)
Exemple #25
0
 def test_null(self):
     m31cube = create_test_image(polarisation_frame=PolarisationFrame('stokesI'),
                                 frequency=numpy.linspace(1e8, 1.1e8, 128))
 
     for i, im in enumerate(image_null_iter(m31cube)):
         assert i<1, "Null iterator returns more than one value"
Exemple #26
0
    # Set up MPI
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    facets = 8
    assert facets * facets % size == 0

    # Create test image
    frequency = numpy.array([1e8])
    phasecentre = SkyCoord(ra=+15.0 * u.deg,
                           dec=-35.0 * u.deg,
                           frame='icrs',
                           equinox='J2000')
    model = create_test_image(frequency=frequency,
                              phasecentre=phasecentre,
                              cellsize=0.001,
                              polarisation_frame=PolarisationFrame('stokesI'))

    # Rank 0 scatters the test image
    if rank == 0:
        subimages = image_scatter_facets(model, facets=facets)
        subimages = numpy.array_split(subimages, size)
    else:
        subimages = list()

    sublist = comm.scatter(subimages, root=0)

    root_images = imagerooter(sublist)

    roots = comm.gather(root_images, root=0)