def test_insert_skycomponent_lanczos(self):
        sc = create_skycomponent(
            direction=self.phasecentre,
            flux=numpy.array([[1.0]]),
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'))

        dphasecentre = SkyCoord(ra=+181.0 * u.deg,
                                dec=-58.0 * u.deg,
                                frame='icrs',
                                equinox=2000.0)
        sc = create_skycomponent(
            direction=dphasecentre,
            flux=numpy.array([[1.0]]),
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'))
        self.model.data *= 0.0
        insert_skycomponent(self.model, sc, insert_method='Lanczos')
        npixel = self.model.shape[3]
        rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int')
        assert rpix[0] == npixel // 2
        assert rpix[1] == npixel // 2
        # These test a regression but are not known a priori to be correct
        self.assertAlmostEqual(self.model.data[0, 0, 119, 150], 0.887186883218,
                               7)
        self.assertAlmostEqual(self.model.data[0, 0, 119, 151],
                               -0.145093950704, 7)
Exemple #2
0
 def ingest_visibility(self, freq=None, chan_width=None, times=None, reffrequency=None, add_errors=False,
                       block=True):
     if freq is None:
         freq = [1e8]
     if times is None:
         ntimes = 5
         times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)
     if chan_width is None:
         chan_width = [1e6]
     
     if reffrequency is None:
         reffrequency = [1e8]
     lowcore = create_named_configuration('LOWBD2-CORE')
     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=reffrequency, phasecentre=phasecentre,
                                          polarisation_frame=PolarisationFrame("stokesI"))
     flux = numpy.array([[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(flux=flux, frequency=frequency, direction=sc,
                                        polarisation_frame=PolarisationFrame("stokesI"))
             comps.append(comp)
     if block:
         predict_skycomponent_blockvisibility(vt, comps)
     else:
         predict_skycomponent_visibility(vt, comps)
     insert_skycomponent(model, comps)
     self.model = copy_image(model)
     self.empty_model = create_empty_image_like(model)
     export_image_to_fits(model, '%s/test_pipeline_bags_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)
     return vt
Exemple #3
0
    def ingest_visibility(self,
                          freq=1e8,
                          chan_width=1e6,
                          times=None,
                          reffrequency=None,
                          add_errors=False):
        if times is None:
            times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5)

        if reffrequency is None:
            reffrequency = [1e8]
        lowcore = create_named_configuration('LOWBD2-CORE')
        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')
        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=reffrequency,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"))
        flux = numpy.array([[100.0]])
        facets = 4

        rpix = model.wcs.wcs.crpix
        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=0)
                comp = create_skycomponent(
                    flux=flux,
                    frequency=frequency,
                    direction=sc,
                    polarisation_frame=PolarisationFrame("stokesI"))
                comps.append(comp)
        predict_skycomponent_visibility(vt, comps)
        insert_skycomponent(model, comps)
        self.model = copy_image(model)
        export_image_to_fits(model,
                             '%s/test_bags_model.fits' % (self.results_dir))
        return vt
 def test_insert_skycomponent_sinc(self):
     dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
     sc = create_skycomponent(direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
                              polarisation_frame=PolarisationFrame('stokesI'))
     self.model.data *= 0.0
     insert_skycomponent(self.model, sc, insert_method='Sinc')
     npixel = self.model.shape[3]
     rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int')
     assert rpix[0] == npixel // 2
     assert rpix[1] == npixel // 2
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 0.87684398703184396, 7)
     self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.2469311811046056, 7)
 def test_insert_skycomponent_lanczos_bandwidth(self):
     dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000')
     sc = create_skycomponent(direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
                              polarisation_frame=PolarisationFrame('stokesI'))
     self.model.data *= 0.0
     insert_skycomponent(self.model, sc, insert_method='Lanczos', bandwidth=0.5)
     npixel = self.model.shape[3]
     rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int')
     assert rpix[0] == npixel // 2
     assert rpix[1] == npixel // 2
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[0,0,151, 122], 0.24031092091707615, 7)
     self.assertAlmostEqual(self.model.data[0,0,152, 122], 0.18648989466050975, 7)
Exemple #6
0
 def test_insert_skycomponent_nearest(self):
     dphasecentre = SkyCoord(ra=+181.0 * u.deg,
                             dec=-58.0 * u.deg,
                             frame='icrs',
                             equinox='J2000')
     sc = create_skycomponent(
         direction=dphasecentre,
         flux=numpy.array([[1.0]]),
         frequency=self.frequency,
         polarisation_frame=PolarisationFrame('stokesI'))
     self.model.data *= 0.0
     insert_skycomponent(self.model, sc, insert_method='Nearest')
     # These test a regression but are not known a priori to be correct
     self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 1.0, 7)
     self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.0, 7)
Exemple #7
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
 def test_insert_skycomponent(self):
     sc = create_skycomponent(direction=self.phasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency,
                              polarisation_frame = PolarisationFrame('stokesI'))
     
     log.debug(self.model.wcs)
     log.debug(str(sc))
     # The actual phase centre of a numpy FFT is at nx //2, nx //2 (0 rel).
     self.model.data *= 0.0
     insert_skycomponent(self.model, sc)
     npixel = self.model.shape[3]
     rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int')
     assert rpix[0] == npixel // 2
     assert rpix[1] == npixel // 2
     assert self.model.data[0,0,rpix[1],rpix[0]] == 1.0
     self.vis = predict_2d(self.vis, self.model)
     assert self.vis.vis.imag.all() == 0.0
Exemple #9
0
 def ingest_visibility(self, freq=1e8, chan_width=1e6, times=None, reffrequency=None, add_errors=False):
     if times is None:
         times = [0.0]
     if reffrequency is None:
         reffrequency = [1e8]
     lowcore = create_named_configuration('LOWBD2-CORE')
     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')
     # Observe at zenith to ensure that timeslicing works well. We test that elsewhere.
     phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000')
     vt = create_blockvisibility(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=reffrequency,
                                          polarisation_frame=PolarisationFrame("stokesI"))
     flux = numpy.array([[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)
             comps.append(create_skycomponent(flux=flux, frequency=vt.frequency, direction=sc,
                                              polarisation_frame=PolarisationFrame("stokesI")))
     predict_skycomponent_blockvisibility(vt, comps)
     insert_skycomponent(model, comps)
     self.actualmodel = copy_image(model)
     export_image_to_fits(model, '%s/test_imaging_model.fits' % (self.results_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)
     return vt
    def test_insert_skycomponent(self):
        sc = create_skycomponent(
            direction=self.phasecentre,
            flux=numpy.array([[1.0]]),
            frequency=self.frequency,
            polarisation_frame=PolarisationFrame('stokesI'))

        self.model.data *= 0.0
        insert_skycomponent(self.model, 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[0, 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 arl.imaging.base
        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 self.vis.vis.imag.all() == 0.0
Exemple #11
0
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',
                                     nchan=16) -> 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,
        nchan=nchan)
    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 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, time=None, frequency=None):
        self.lowcore = create_named_configuration('LOWBD2-CORE')
        self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7)

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

        if frequency is None:
            self.frequency = numpy.array([1e8])
            self.channel_bandwidth = numpy.array([1e7])
        else:
            self.frequency = frequency
            if len(self.frequency) < 1:
                self.channel_bandwidth = numpy.full_like(
                    self.frequency, self.frequency[1] - self.frequency[0])
            else:
                self.channel_bandwidth = numpy.array([1e6])

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

        # Create model
        self.model = create_image_from_visibility(
            self.componentvis,
            npixel=256,
            cellsize=0.001,
            nchan=1,
            polarisation_frame=PolarisationFrame('stokesI'))

        # Fill the visibility with exactly computed point sources. These are chosen to lie
        # on grid points.
        spacing_pixels = 32
        log.info('Spacing in pixels = %s' % spacing_pixels)

        centers = [-2.5, -0.5, 0.5, 2.5]

        # Make the list of components
        rpix = self.model.wcs.wcs.crpix - 1
        self.components = []
        for iy in centers:
            for ix in centers:
                if ix >= iy:
                    # 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=0)
                    log.info("Component at (%f, %f) [0-rel] %s" %
                             (p[0], p[1], str(sc)))

                    f = (100.0 + 1.0 * ix + iy * 10.0)
                    # Channel images
                    flux = numpy.array([[f]])
                    comp = create_skycomponent(
                        flux=flux,
                        frequency=[numpy.average(self.frequency)],
                        direction=sc,
                        polarisation_frame=PolarisationFrame('stokesI'))
                    self.components.append(comp)

        # Predict the visibility from the components exactly. We always do this for each spectral channel
        self.componentvis.data['vis'] *= 0.0
        predict_skycomponent_visibility(self.componentvis, self.components)
        insert_skycomponent(self.model, self.components)

        # Calculate the model convolved with a Gaussian.
        norm = 2.0 * numpy.pi
        self.cmodel = copy_image(self.model)
        self.cmodel.data[0, 0, :, :] = norm * convolve(
            self.model.data[0, 0, :, :],
            Gaussian2DKernel(1.0),
            normalize_kernel=False)
        export_image_to_fits(self.model, '%s/test_model.fits' % self.dir)
        export_image_to_fits(self.cmodel, '%s/test_cmodel.fits' % self.dir)
Exemple #14
0
    def actualSetUp(self,
                    add_errors=False,
                    freqwin=1,
                    block=False,
                    dospectral=True,
                    dopol=False):
        self.low = create_named_configuration('LOWBD2', rmax=750.0)
        self.freqwin = freqwin
        self.vis_graph_list = list()
        self.ntimes = 5
        self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0
        self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin)
        if freqwin > 1:
            self.channelwidth = numpy.array(
                freqwin * [self.frequency[1] - self.frequency[0]])
        else:
            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.componentvis = ingest_unittest_visibility(self.low,
                                                       self.frequency,
                                                       self.channelwidth,
                                                       self.times,
                                                       self.vis_pol,
                                                       self.phasecentre,
                                                       block=block)

        self.model = create_unittest_model(self.componentvis,
                                           self.image_pol,
                                           npixel=self.params['npixel'])

        self.components = create_unittest_components(self.model, flux)
        self.model = insert_skycomponent(self.model, self.components)
        self.componentvis.data['vis'][...] = 0.0
        self.componentvis = predict_skycomponent_visibility(
            self.componentvis, self.components)

        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)

        if add_errors:
            self.componentvis = insert_unittest_errors(self.componentvis)