예제 #1
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

        self.mask = create_test_image(cellsize=0.0015,
                                      phasecentre=self.vis.phasecentre,
                                      frequency=self.frequency)
        self.mask.data[self.mask.data > 0.1] = 1.0
        self.mask.data[self.mask.data <= 0.1] = 0.0
    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
예제 #3
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, -1), (-1, 0), (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
예제 #4
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_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)
                if self.persist:
                    export_image_to_fits(
                        m31reconstructed,
                        "%s/test_image_gather_scatter_%dnraster_%doverlap_%s_reconstructed.fits"
                        % (self.dir, nraster, overlap, taper))
                if self.persist:
                    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
    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"
예제 #7
0
    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)
예제 #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 test_readwriteskymodel(self):
        vis = create_blockvisibility(
            self.midcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            polarisation_frame=PolarisationFrame("linear"),
            weight=1.0)
        gt = create_gaintable_from_blockvisibility(vis, timeslice='auto')
        gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1)
        im = create_test_image()
        sm = SkyModel(components=[self.comp], image=im, gaintable=gt)

        config = {
            "buffer": {
                "directory": self.dir
            },
            "skymodel": {
                "name": "test_bufferskymodel.hdf",
                "data_model": "SkyModel"
            }
        }
        bdm = BufferSkyModel(config["buffer"], config["skymodel"], sm)
        bdm.sync()
        new_bdm = BufferSkyModel(config["buffer"], config["skymodel"])
        new_bdm.sync()
        newsm = bdm.memory_data_model

        assert newsm.components[0].flux.shape == self.comp.flux.shape
        assert newsm.image.data.shape == im.data.shape
        assert newsm.gaintable.data.shape == gt.data.shape
        assert numpy.max(numpy.abs(newsm.image.data - im.data)) < 1e-15
예제 #10
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_workflow = arlexecute.execute(create_test_image)(frequency=self.frequency,
                                                              phasecentre=self.phasecentre,
                                                              cellsize=0.001,
                                                              polarisation_frame=PolarisationFrame('stokesI'))
예제 #11
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, bvis in enumerate(vis_iter):
            assert bvis.phasecentre == self.phasecentre
            assert bvis.nvis
            if i == 0:
                fullvis = bvis
                totalnvis = bvis.nvis
            else:
                fullvis = append_visibility(fullvis, bvis)
                totalnvis += bvis.nvis

        assert fullvis.nvis == totalnvis
예제 #12
0
    def test_create_gaintable_from_screen(self):
        screen = import_image_from_fits(
            arl_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)

        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
    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
예제 #14
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
예제 #15
0
    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
    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 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.image_frequency = numpy.linspace(0.9e8, 1.1e8, 5)
     self.component_frequency = numpy.linspace(0.8e8, 1.2e8, 7)
     self.channel_bandwidth = numpy.array(5*[1e7])
     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.image_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.model = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.image_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
     
     dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
     flux = [[numpy.power(f/1e8, -0.7)] for f in self.component_frequency]
     self.sc = create_skycomponent(direction=dphasecentre, flux=flux,
                                 frequency=self.component_frequency,
                                 polarisation_frame=PolarisationFrame('stokesI'))
예제 #18
0
    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)
예제 #19
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
예제 #20
0
 def test_readwriteconvolutionfunction(self):
     im = create_test_image()
     cf = create_convolutionfunction_from_image(im)
     export_convolutionfunction_to_hdf5(cf, '%s/test_data_model_helpers_convolutionfunction.hdf' % self.dir)
     newcf = import_convolutionfunction_from_hdf5('%s/test_data_model_helpers_convolutionfunction.hdf' % self.dir)
 
     assert newcf.data.shape == cf.data.shape
     assert numpy.max(numpy.abs(cf.data - newcf.data)) < 1e-15
예제 #21
0
 def test_readwritegriddata(self):
     im = create_test_image()
     gd = create_griddata_from_image(im)
     export_griddata_to_hdf5(gd, '%s/test_data_model_helpers_griddata.hdf' % self.dir)
     newgd = import_griddata_from_hdf5('%s/test_data_model_helpers_griddata.hdf' % self.dir)
 
     assert newgd.data.shape == gd.data.shape
     assert numpy.max(numpy.abs(gd.data - newgd.data)) < 1e-15
    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
예제 #23
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
예제 #24
0
    def test_create_pointingtable(self):
        beam = create_test_image(cellsize=0.0015,
                                 phasecentre=self.vis.phasecentre,
                                 frequency=self.frequency)

        for telescope in ['MID', 'LOW', 'ASKAP']:
            vp = create_vp(beam, telescope)
            pt = create_pointingtable_from_blockvisibility(self.vis, vp)
            pt = simulate_pointingtable(pt, 0.1, static_pointing_error=0.01)
            assert pt.pointing.shape == (3, 63, 1, 1, 2), pt.pointing.shape
예제 #25
0
 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)
예제 #27
0
 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_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
예제 #29
0
    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])
예제 #30
0
 def test_readwriteskymodel(self):
     self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency,
                                       channel_bandwidth=self.channel_bandwidth,
                                       phasecentre=self.phasecentre,
                                       polarisation_frame=PolarisationFrame("linear"),
                                       weight=1.0)
     im = create_test_image()
     gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto')
     sm = SkyModel(components=[self.comp], image=im, gaintable=gt)
     export_skymodel_to_hdf5(sm, '%s/test_data_model_helpers_skymodel.hdf' % self.dir)
     newsm = import_skymodel_from_hdf5('%s/test_data_model_helpers_skymodel.hdf' % self.dir)
 
     assert newsm.components[0].flux.shape == self.comp.flux.shape
     assert newsm.image.data.shape == im.data.shape
     assert numpy.max(numpy.abs(newsm.image.data - im.data)) < 1e-15