def test_insert_skycomponent_lanczos(self):
     self.model.data *= 0.0
     insert_skycomponent(self.model, self.sc, insert_method='Lanczos')
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[2, 0, 151, 122],
                            0.87781267543090036, 7)
     self.assertAlmostEqual(self.model.data[2, 0, 152, 122],
                            0.23817562762032077, 7)
 def test_insert_skycomponent_sinc(self):
     self.model.data *= 0.0
     insert_skycomponent(self.model, self.sc, insert_method='Sinc')
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[2, 0, 151, 122],
                            0.87684398703184396, 7)
     self.assertAlmostEqual(self.model.data[2, 0, 152, 122],
                            0.2469311811046056, 7)
 def test_insert_skycomponent_lanczos_bandwidth(self):
     self.model.data *= 0.0
     insert_skycomponent(self.model,
                         self.sc,
                         insert_method='Lanczos',
                         bandwidth=0.5)
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[2, 0, 151, 122],
                            0.24031092091707615, 7)
     self.assertAlmostEqual(self.model.data[2, 0, 152, 122],
                            0.18648989466050975, 7)
 def test_insert_skycomponent_sinc_bandwidth(self):
     self.model.data *= 0.0
     insert_skycomponent(self.model,
                         self.sc,
                         insert_method='Sinc',
                         bandwidth=0.5)
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[2, 0, 151, 122],
                            0.25133066186805758, 7)
     self.assertAlmostEqual(self.model.data[2, 0, 152, 122],
                            0.19685222464041874, 7)
Esempio n. 5
0
    def actualSetUp(self, freqwin=1, block=True, dopol=False):

        self.npixel = 512
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        self.vis = list()
        self.ntimes = 5
        self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0

        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 freqwin > 1:
            self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
            self.channelwidth = numpy.array(
                freqwin * [self.frequency[1] - self.frequency[0]])
            flux = numpy.array(
                [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
        else:
            self.frequency = numpy.array([1e8])
            self.channelwidth = numpy.array([1e6])
            flux = numpy.array([f])

        self.phasecentre = SkyCoord(ra=+180.0 * u.deg,
                                    dec=-60.0 * u.deg,
                                    frame='icrs',
                                    equinox='J2000')
        self.bvis = ingest_unittest_visibility(self.low,
                                               self.frequency,
                                               self.channelwidth,
                                               self.times,
                                               self.vis_pol,
                                               self.phasecentre,
                                               block=block)

        self.vis = convert_blockvisibility_to_visibility(self.bvis)

        self.model = create_unittest_model(self.vis,
                                           self.image_pol,
                                           npixel=self.npixel,
                                           nchan=freqwin)

        self.components = create_unittest_components(self.model, flux)

        self.model = insert_skycomponent(self.model, self.components)

        self.bvis = predict_skycomponent_visibility(self.bvis, self.components)
    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
Esempio n. 7
0
 def actualSetUp(self, freqwin=1, block=False, dospectral=True, dopol=False, zerow=False):
     
     self.npixel = 512
     self.low = create_named_configuration('LOWBD2', rmax=750.0)
     self.freqwin = freqwin
     self.vis = list()
     self.ntimes = 5
     self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0
     
     if freqwin > 1:
         self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
         self.channelwidth = numpy.array(freqwin * [self.frequency[1] - self.frequency[0]])
     else:
         self.frequency = numpy.array([1e8])
         self.channelwidth = numpy.array([1e6])
     
     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 * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
     else:
         flux = numpy.array([f])
     
     self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     self.vis = ingest_unittest_visibility(self.low,
                                           [self.frequency],
                                           [self.channelwidth],
                                           self.times,
                                           self.vis_pol,
                                           self.phasecentre, block=block,
                                           zerow=zerow)
     
     self.model = create_unittest_model(self.vis, self.image_pol, npixel=self.npixel)
     
     self.components = create_unittest_components(self.model, flux)
     
     self.model = insert_skycomponent(self.model, self.components)
     
     self.vis = predict_skycomponent_visibility(self.vis, self.components)
     
     # Calculate the model convolved with a Gaussian.
     
     self.cmodel = smooth_image(self.model)
     export_image_to_fits(self.model, '%s/test_imaging_model.fits' % self.dir)
     export_image_to_fits(self.cmodel, '%s/test_imaging_cmodel.fits' % self.dir)
Esempio n. 8
0
 def actualSetUp(self, zerow=True):
     self.doplot = False
     self.npixel = 256
     self.cellsize = 0.0009
     self.low = create_named_configuration('LOWBD2', rmax=750.0)
     self.freqwin = 1
     self.vis_list = list()
     self.ntimes = 3
     self.times = numpy.linspace(-2.0, +2.0, self.ntimes) * numpy.pi / 12.0
     
     if self.freqwin == 1:
         self.frequency = numpy.array([1e8])
         self.channelwidth = numpy.array([4e7])
     else:
         self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
         self.channelwidth = numpy.array(self.freqwin * [self.frequency[1] - self.frequency[0]])
     
     self.vis_pol = PolarisationFrame('linear')
     self.image_pol = PolarisationFrame('stokesIQUV')
     
     f = numpy.array([100.0, 20.0, -10.0, 1.0])
     
     flux = numpy.array([f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency])
     
     self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     self.vis = ingest_unittest_visibility(self.low,
                                           self.frequency,
                                           self.channelwidth,
                                           self.times,
                                           self.vis_pol,
                                           self.phasecentre,
                                           block=False,
                                           zerow=zerow)
     
     self.model = create_unittest_model(self.vis, self.image_pol, cellsize=self.cellsize,
                                        npixel=self.npixel, nchan=self.freqwin)
     self.components = create_unittest_components(self.model, flux, applypb=False,
                                                  scale=0.5, single=False, symmetric=True)
     self.model = insert_skycomponent(self.model, self.components)
     self.vis = predict_skycomponent_visibility(self.vis, self.components)
     
     # Calculate the model convolved with a Gaussian.
     self.cmodel = smooth_image(self.model)
     if self.persist:
         export_image_to_fits(self.model, '%s/test_gridding_model.fits' % self.dir)
         export_image_to_fits(self.cmodel, '%s/test_gridding_cmodel.fits' % self.dir)
     pb = create_pb_generic(self.model, diameter=35.0, blockage=0.0)
     self.cmodel.data *= pb.data
     if self.persist:
         export_image_to_fits(self.cmodel, '%s/test_gridding_cmodel_pb.fits' % self.dir)
     self.peak = numpy.unravel_index(numpy.argmax(numpy.abs(self.cmodel.data)), self.cmodel.shape)
def create_low_test_image_from_gleam(npixel=512, polarisation_frame=PolarisationFrame("stokesI"), cellsize=0.000015,
                                     frequency=numpy.array([1e8]), channel_bandwidth=numpy.array([1e6]),
                                     phasecentre=None, kind='cubic', applybeam=False, flux_limit=0.1,
                                     radius=None, insert_method='Nearest') -> Image:
    """Create LOW test image from the GLEAM survey

    Stokes I is estimated from a cubic spline fit to the measured fluxes. The polarised flux is always zero.
    
    See http://www.mwatelescope.org/science/gleam-survey The catalog is available from Vizier.
    
    VIII/100   GaLactic and Extragalactic All-sky MWA survey  (Hurley-Walker+, 2016)

    GaLactic and Extragalactic All-sky Murchison Wide Field Array (GLEAM) survey. I: A low-frequency extragalactic
    catalogue. Hurley-Walker N., et al., Mon. Not. R. Astron. Soc., 464, 1146-1167 (2017), 2017MNRAS.464.1146H

    :param npixel: Number of pixels
    :param polarisation_frame: Polarisation frame (default PolarisationFrame("stokesI"))
    :param cellsize: cellsize in radians
    :param frequency:
    :param channel_bandwidth: Channel width (Hz)
    :param phasecentre: phasecentre (SkyCoord)
    :param kind: Kind of interpolation (see scipy.interpolate.interp1d) Default: linear
    :return: Image
    
    """
    
    if phasecentre is None:
        phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000')
    
    if radius is None:
        radius = npixel * cellsize / numpy.sqrt(2.0)
    
    sc = create_low_test_skycomponents_from_gleam(flux_limit=flux_limit, polarisation_frame=polarisation_frame,
                                                  frequency=frequency, phasecentre=phasecentre,
                                                  kind=kind, radius=radius)
    if polarisation_frame is None:
        polarisation_frame = PolarisationFrame("stokesI")
    
    npol = polarisation_frame.npol
    nchan = len(frequency)
    shape = [nchan, npol, npixel, npixel]
    w = WCS(naxis=4)
    # The negation in the longitude is needed by definition of RA, DEC
    w.wcs.cdelt = [-cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0, channel_bandwidth[0]]
    w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0]
    w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ']
    w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, frequency[0]]
    w.naxis = 4
    w.wcs.radesys = 'ICRS'
    w.wcs.equinox = 2000.0
    
    model = create_image_from_array(numpy.zeros(shape), w, polarisation_frame=polarisation_frame)
    
    model = insert_skycomponent(model, sc, insert_method=insert_method)
    if applybeam:
        beam = create_low_test_beam(model)
        model.data[...] *= beam.data[...]
    
    log.info(qa_image(model, context='create_low_test_image_from_gleam'))
    
    return model
 def test_insert_skycomponent_nearest(self):
     self.model.data *= 0.0
     insert_skycomponent(self.model, self.sc, insert_method='Nearest')
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[2, 0, 151, 122], 1.0, 7)
     self.assertAlmostEqual(self.model.data[2, 0, 152, 122], 0.0, 7)
Esempio n. 11
0
def create_low_test_skymodel_from_gleam(npixel=512,
                                        polarisation_frame=PolarisationFrame(
                                            "stokesI"),
                                        cellsize=0.000015,
                                        frequency=numpy.array([1e8]),
                                        channel_bandwidth=numpy.array([1e6]),
                                        phasecentre=None,
                                        kind='cubic',
                                        applybeam=True,
                                        flux_limit=0.1,
                                        flux_max=numpy.inf,
                                        flux_threshold=1.0,
                                        insert_method='Nearest',
                                        telescope='LOW') -> SkyModel:
    """Create LOW test skymodel from the GLEAM survey

    Stokes I is estimated from a cubic spline fit to the measured fluxes. The polarised flux is always zero.

    See http://www.mwatelescope.org/science/gleam-survey The catalog is available from Vizier.

    VIII/100   GaLactic and Extragalactic All-sky MWA survey  (Hurley-Walker+, 2016)

    GaLactic and Extragalactic All-sky Murchison Wide Field Array (GLEAM) survey. I: A low-frequency extragalactic
    catalogue. Hurley-Walker N., et al., Mon. Not. R. Astron. Soc., 464, 1146-1167 (2017), 2017MNRAS.464.1146H

    :param telescope:
    :param npixel: Number of pixels
    :param polarisation_frame: Polarisation frame (default PolarisationFrame("stokesI"))
    :param cellsize: cellsize in radians
    :param frequency:
    :param channel_bandwidth: Channel width (Hz)
    :param phasecentre: phasecentre (SkyCoord)
    :param kind: Kind of interpolation (see scipy.interpolate.interp1d) Default: cubic
    :param applybeam: Apply the primary beam?
    :param flux_limit: Weakest component
    :param flux_max: Maximum strength component to be included in components
    :param flux_threshold: Split between components (brighter) and image (weaker)
    :param insert_method: Nearest | PSWF | Lanczos
    :return:
    :return: SkyModel

    """

    if phasecentre is None:
        phasecentre = SkyCoord(ra=+15.0 * u.deg,
                               dec=-35.0 * u.deg,
                               frame='icrs',
                               equinox='J2000')

    radius = npixel * cellsize

    sc = create_low_test_skycomponents_from_gleam(
        flux_limit=flux_limit,
        polarisation_frame=polarisation_frame,
        frequency=frequency,
        phasecentre=phasecentre,
        kind=kind,
        radius=radius)

    sc = filter_skycomponents_by_flux(sc, flux_max=flux_max)
    if polarisation_frame is None:
        polarisation_frame = PolarisationFrame("stokesI")

    npol = polarisation_frame.npol
    nchan = len(frequency)
    shape = [nchan, npol, npixel, npixel]
    w = WCS(naxis=4)
    # The negation in the longitude is needed by definition of RA, DEC
    w.wcs.cdelt = [
        -cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0,
        channel_bandwidth[0]
    ]
    w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0]
    w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ']
    w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, frequency[0]]
    w.naxis = 4
    w.wcs.radesys = 'ICRS'
    w.wcs.equinox = 2000.0

    model = create_image_from_array(numpy.zeros(shape),
                                    w,
                                    polarisation_frame=polarisation_frame)

    if applybeam:
        beam = create_pb(model, telescope=telescope)
        sc = apply_beam_to_skycomponent(sc, beam)

    weaksc = filter_skycomponents_by_flux(sc, flux_max=flux_threshold)
    brightsc = filter_skycomponents_by_flux(sc, flux_min=flux_threshold)
    model = insert_skycomponent(model, weaksc, insert_method=insert_method)

    log.info(
        'create_low_test_skymodel_from_gleam: %d bright sources above flux threshold %.3f, %d weak sources below '
        % (len(brightsc), flux_threshold, len(weaksc)))

    return SkyModel(components=brightsc,
                    image=model,
                    mask=None,
                    gaintable=None)
    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