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'))
    def test_insert_skycomponent_dft(self):
        self.sc = create_skycomponent(direction=self.phasecentre, flux=self.sc.flux,
                                    frequency=self.component_frequency,
                                    polarisation_frame=PolarisationFrame('stokesI'))

        self.vis.data['vis'][...] = 0.0
        self.vis = predict_skycomponent_visibility(self.vis, self.sc)
        im, sumwt = invert_2d(self.vis, self.model)
        export_image_to_fits(im, '%s/test_skycomponent_dft.fits' % self.dir)
        assert numpy.max(numpy.abs(self.vis.vis.imag)) < 1e-3
Esempio n. 3
0
 def test_copy(self):
     fluxes = numpy.linspace(0, 1.0, 10)
     sc = [
         create_skycomponent(
             direction=self.phasecentre,
             flux=numpy.array([[f]]),
             frequency=self.frequency,
             polarisation_frame=PolarisationFrame('stokesI'))
         for f in fluxes
     ]
     assert len(sc) == len(fluxes)
Esempio n. 4
0
 def test_create(self):
     fluxes = numpy.linspace(0, 1.0, 11)
     sc = [
         create_skycomponent(
             direction=self.phasecentre,
             flux=numpy.array([[f]]),
             frequency=self.frequency,
             polarisation_frame=PolarisationFrame('stokesI'))
         for f in fluxes
     ]
     sm = SkyModel(image=self.model, components=sc, mask=self.mask)
     assert len(sm.components) == 11
Esempio n. 5
0
def create_unittest_components(model,
                               flux,
                               applypb=False,
                               telescope='LOW',
                               npixel=None,
                               scale=1.0,
                               single=False,
                               symmetric=False):
    # Fill the visibility with exactly computed point sources.

    if npixel == None:
        _, _, _, npixel = model.data.shape
    spacing_pixels = int(scale * npixel) // 4
    log.info('Spacing in pixels = %s' % spacing_pixels)

    if not symmetric:
        centers = [(0.2, 1.1)]
    else:
        centers = list()

    if not single:
        centers.append([0.0, 0.0])

        for x in numpy.linspace(-1.2, 1.2, 7):
            if abs(x) > 1e-15:
                centers.append([x, x])
                centers.append([x, -x])
    model_pol = model.polarisation_frame
    # Make the list of components
    rpix = model.wcs.wcs.crpix
    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(model.wcs.wcs.cdelt[0]))), \
            int(round(rpix[1] + iy * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[1])))
        sc = pixel_to_skycoord(p[0], p[1], model.wcs, origin=1)
        log.info("Component at (%f, %f) [0-rel] %s" % (p[0], p[1], str(sc)))

        # Channel images
        comp = create_skycomponent(direction=sc,
                                   flux=flux,
                                   frequency=model.frequency,
                                   polarisation_frame=model_pol)
        components.append(comp)

    if applypb:
        beam = create_pb(model, telescope=telescope)
        components = apply_beam_to_skycomponent(components, beam)

    return components
Esempio n. 6
0
    def test_filter(self):
        fluxes = numpy.linspace(0, 1.0, 11)
        sc = [
            create_skycomponent(
                direction=self.phasecentre,
                flux=numpy.array([[f]]),
                frequency=self.frequency,
                polarisation_frame=PolarisationFrame('stokesI'))
            for f in fluxes
        ]

        sm = partition_skymodel_by_flux(sc, self.model, flux_threshold=0.31)
        assert len(sm.components) == 7, len(sm.components)
Esempio n. 7
0
 def test_copy(self):
     fluxes = numpy.linspace(0, 1.0, 11)
     sc = [create_skycomponent(direction=self.phasecentre, flux=numpy.array([[f]]), frequency=self.frequency,
                               polarisation_frame=PolarisationFrame('stokesI')) for f in fluxes]
     sm = SkyModel(image=self.model, components=sc, mask=self.mask)
     sm_copy = copy_skymodel(sm)
     assert len(sm.components) == len(sm_copy.components)
     sm_fluxes = numpy.array([c.flux[0,0] for c in sm.components])
     sm_copy_fluxes = numpy.array([c.flux[0,0] for c in sm_copy.components])
     
     assert numpy.max(numpy.abs(sm_fluxes - sm_copy_fluxes)) < 1e-7
     
     assert numpy.abs(numpy.max(sm.mask.data - 1.0)) < 1e-7
     assert numpy.abs(numpy.min(sm.mask.data - 0.0)) < 1e-7
 def test_copy(self):
     self.components = create_low_test_skycomponents_from_gleam(
         flux_limit=0.1,
         phasecentre=self.phasecentre,
         frequency=self.frequency,
         polarisation_frame=PolarisationFrame('stokesI'),
         radius=0.5)
     fluxes = numpy.linspace(0, 1.0, 10)
     sc = [
         create_skycomponent(
             direction=self.phasecentre,
             flux=numpy.array([[f]]),
             frequency=self.frequency,
             polarisation_frame=PolarisationFrame('stokesI'))
         for f in fluxes
     ]
     assert len(sc) == len(fluxes)
Esempio n. 9
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_arlexecute = arlexecute.execute(create_test_image)(
            frequency=self.frequency,
            phasecentre=self.phasecentre,
            cellsize=0.001,
            polarisation_frame=PolarisationFrame('stokesI'))
    def test_insert_skycomponent_FFT(self):
        
        self.model.data *= 0.0
        self.sc = create_skycomponent(direction=self.phasecentre, flux=self.sc.flux,
                                    frequency=self.component_frequency,
                                    polarisation_frame=PolarisationFrame('stokesI'))

        insert_skycomponent(self.model, self.sc)
        npixel = self.model.shape[3]
        # WCS is 1-relative
        rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int') - 1
        assert rpix[0] == npixel // 2
        assert rpix[1] == npixel // 2
        # The phase centre is at rpix[0], rpix[1] in 0-relative pixels
        assert self.model.data[2, 0, rpix[1], rpix[0]] == 1.0
        # If we predict the visibility, then the imaginary part must be zero. This is determined entirely
        # by shift_vis_to_image in libs.imaging.base
        self.vis.data['vis'][...] = 0.0
        self.vis = predict_2d(self.vis, self.model)
        # The actual phase centre of a numpy FFT is at nx //2, nx //2 (0 rel).
        assert numpy.max(numpy.abs(self.vis.vis.imag)) <1e-3
    def test_create_gaintable_from_pointingtable_circlecut(self):
        self.sidelobe = SkyCoord(ra=+15.0 * u.deg,
                                 dec=-49.4 * u.deg,
                                 frame='icrs',
                                 equinox='J2000')
        comp = create_skycomponent(
            direction=self.sidelobe,
            flux=[[1.0]],
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'))

        telescopes = ['MID', 'MID_GAUSS', 'MID_GRASP']
        for telescope in telescopes:
            pt = create_pointingtable_from_blockvisibility(self.vis)
            pt = simulate_pointingtable(pt,
                                        pointing_error=0.0,
                                        global_pointing_error=[0.0, 0.0])
            vp = create_vp(self.model, telescope)
            gt = simulate_gaintable_from_pointingtable(self.vis, [comp], pt,
                                                       vp)
            if self.doplot:
                import matplotlib.pyplot as plt
                plt.clf()
                plt.plot(gt[0].time,
                         numpy.real(1.0 / gt[0].gain[:, 0, 0, 0, 0]),
                         '.',
                         label='Real')
                plt.plot(gt[0].time,
                         numpy.imag(1.0 / gt[0].gain[:, 0, 0, 0, 0]),
                         '.',
                         label='Imaginary')
                plt.legend()
                plt.xlabel('Time (s)')
                plt.ylabel('Gain')
                plt.title('test_create_gaintable_from_pointingtable_%s' %
                          telescope)
                plt.show()
            assert gt[0].gain.shape == (self.ntimes, self.nants, 1, 1,
                                        1), gt[0].gain.shape
    def ingest_visibility(self,
                          freq=None,
                          chan_width=None,
                          times=None,
                          add_errors=False,
                          block=True,
                          bandpass=False):
        if freq is None:
            freq = [1e8]
        if chan_width is None:
            chan_width = [1e6]
        if times is None:
            times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5)

        lowcore = create_named_configuration('LOWBD2', rmax=750.0)
        frequency = numpy.array(freq)
        channel_bandwidth = numpy.array(chan_width)

        phasecentre = SkyCoord(ra=+180.0 * u.deg,
                               dec=-60.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')
        if block:
            vt = create_blockvisibility(
                lowcore,
                times,
                frequency,
                channel_bandwidth=channel_bandwidth,
                weight=1.0,
                phasecentre=phasecentre,
                polarisation_frame=PolarisationFrame("stokesI"))
        else:
            vt = create_visibility(
                lowcore,
                times,
                frequency,
                channel_bandwidth=channel_bandwidth,
                weight=1.0,
                phasecentre=phasecentre,
                polarisation_frame=PolarisationFrame("stokesI"))
        cellsize = 0.001
        model = create_image_from_visibility(
            vt,
            npixel=self.npixel,
            cellsize=cellsize,
            npol=1,
            frequency=frequency,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"))
        nchan = len(self.frequency)
        flux = numpy.array(nchan * [[100.0]])
        facets = 4

        rpix = model.wcs.wcs.crpix - 1.0
        spacing_pixels = self.npixel // facets
        centers = [-1.5, -0.5, 0.5, 1.5]
        comps = list()
        for iy in centers:
            for ix in centers:
                p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[0]))), \
                    int(round(rpix[1] + iy * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[1])))
                sc = pixel_to_skycoord(p[0], p[1], model.wcs, origin=1)
                comp = create_skycomponent(
                    direction=sc,
                    flux=flux,
                    frequency=frequency,
                    polarisation_frame=PolarisationFrame("stokesI"))
                comps.append(comp)
        if block:
            predict_skycomponent_visibility(vt, comps)
        else:
            predict_skycomponent_visibility(vt, comps)
        insert_skycomponent(model, comps)
        self.comps = comps
        self.model = copy_image(model)
        self.empty_model = create_empty_image_like(model)
        export_image_to_fits(
            model, '%s/test_pipeline_functions_model.fits' % (self.dir))

        if add_errors:
            # These will be the same for all calls
            numpy.random.seed(180555)
            gt = create_gaintable_from_blockvisibility(vt)
            gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.0)
            vt = apply_gaintable(vt, gt)

            if bandpass:
                bgt = create_gaintable_from_blockvisibility(vt, timeslice=1e5)
                bgt = simulate_gaintable(bgt,
                                         phase_error=0.01,
                                         amplitude_error=0.01,
                                         smooth_channels=4)
                vt = apply_gaintable(vt, bgt)

        return vt