def actualSetup(self, nsources=None, nvoronoi=None):

        n_workers = 8

        # Set up the observation: 10 minutes at transit, with 10s integration.
        # Skip 5/6 points to avoid outstation redundancy

        nfreqwin = 1
        ntimes = 3
        self.rmax = 2500.0
        dec = -40.0 * u.deg
        frequency = [1e8]
        channel_bandwidth = [0.1e8]
        times = numpy.linspace(-10.0, 10.0,
                               ntimes) * numpy.pi / (3600.0 * 12.0)

        phasecentre = SkyCoord(ra=+0.0 * u.deg,
                               dec=dec,
                               frame='icrs',
                               equinox='J2000')
        low = create_named_configuration('LOWBD2', rmax=self.rmax)

        centre = numpy.mean(low.xyz, axis=0)
        distance = numpy.hypot(low.xyz[:, 0] - centre[0],
                               low.xyz[:, 1] - centre[1],
                               low.xyz[:, 2] - centre[2])
        lowouter = low.data[distance > 1000.0][::6]
        lowcore = low.data[distance < 1000.0][::3]
        low.data = numpy.hstack((lowcore, lowouter))

        blockvis = create_blockvisibility(
            low,
            times,
            frequency=frequency,
            channel_bandwidth=channel_bandwidth,
            weight=1.0,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            zerow=True)

        vis = convert_blockvisibility_to_visibility(blockvis)
        advice = advise_wide_field(vis, guard_band_image=2.0, delA=0.02)

        cellsize = advice['cellsize']
        npixel = advice['npixels2']

        small_model = create_image_from_visibility(blockvis,
                                                   npixel=512,
                                                   frequency=frequency,
                                                   nchan=nfreqwin,
                                                   cellsize=cellsize,
                                                   phasecentre=phasecentre)

        vis.data['imaging_weight'][...] = vis.data['weight'][...]
        vis = weight_list_serial_workflow([vis], [small_model])[0]
        vis = taper_list_serial_workflow([vis], 3 * cellsize)[0]

        blockvis = convert_visibility_to_blockvisibility(vis)

        # ### Generate the model from the GLEAM catalog, including application of the primary beam.

        beam = create_image_from_visibility(blockvis,
                                            npixel=npixel,
                                            frequency=frequency,
                                            nchan=nfreqwin,
                                            cellsize=cellsize,
                                            phasecentre=phasecentre)
        beam = create_low_test_beam(beam, use_local=False)

        flux_limit = 0.5
        original_gleam_components = create_low_test_skycomponents_from_gleam(
            flux_limit=flux_limit,
            phasecentre=phasecentre,
            frequency=frequency,
            polarisation_frame=PolarisationFrame('stokesI'),
            radius=0.15)

        all_components = apply_beam_to_skycomponent(original_gleam_components,
                                                    beam)
        all_components = filter_skycomponents_by_flux(all_components,
                                                      flux_min=flux_limit)
        voronoi_components = filter_skycomponents_by_flux(all_components,
                                                          flux_min=1.5)

        def max_flux(elem):
            return numpy.max(elem.flux)

        voronoi_components = sorted(voronoi_components,
                                    key=max_flux,
                                    reverse=True)

        if nsources is not None:
            all_components = [all_components[0]]

        if nvoronoi is not None:
            voronoi_components = [voronoi_components[0]]

        self.screen = import_image_from_fits(
            arl_path('data/models/test_mpc_screen.fits'))
        all_gaintables = create_gaintable_from_screen(blockvis, all_components,
                                                      self.screen)

        gleam_skymodel_noniso = [
            SkyModel(components=[all_components[i]],
                     gaintable=all_gaintables[i])
            for i, sm in enumerate(all_components)
        ]

        # ### Now predict the visibility for each skymodel and apply the gaintable for that skymodel,
        # returning a list of visibilities, one for each skymodel. We then sum these to obtain
        # the total predicted visibility. All images and skycomponents in the same skymodel
        # get the same gaintable applied which means that in this case each skycomponent has a separate gaintable.

        self.all_skymodel_noniso_vis = convert_blockvisibility_to_visibility(
            blockvis)

        ngroup = n_workers
        future_vis = arlexecute.scatter(self.all_skymodel_noniso_vis)
        chunks = [
            gleam_skymodel_noniso[i:i + ngroup]
            for i in range(0, len(gleam_skymodel_noniso), ngroup)
        ]
        for chunk in chunks:
            result = predict_skymodel_list_arlexecute_workflow(future_vis,
                                                               chunk,
                                                               context='2d',
                                                               docal=True)
            work_vis = arlexecute.compute(result, sync=True)
            for w in work_vis:
                self.all_skymodel_noniso_vis.data['vis'] += w.data['vis']
            assert numpy.max(
                numpy.abs(self.all_skymodel_noniso_vis.data['vis'])) > 0.0

        self.all_skymodel_noniso_blockvis = convert_visibility_to_blockvisibility(
            self.all_skymodel_noniso_vis)

        # ### Remove weaker of components that are too close (0.02 rad)
        idx, voronoi_components = remove_neighbouring_components(
            voronoi_components, 0.02)

        model = create_image_from_visibility(blockvis,
                                             npixel=npixel,
                                             frequency=frequency,
                                             nchan=nfreqwin,
                                             cellsize=cellsize,
                                             phasecentre=phasecentre)

        # Use the gaintable for the brightest component as the starting gaintable
        all_gaintables[0].gain[...] = numpy.conjugate(
            all_gaintables[0].gain[...])
        all_gaintables[0].gain[...] = 1.0 + 0.0j
        self.theta_list = initialize_skymodel_voronoi(model,
                                                      voronoi_components,
                                                      all_gaintables[0])
Ejemplo n.º 2
0
    lowcore = create_configuration('MUSER')
    # lowcore = create_named_configuration('MUSER')
    # arlexecute.set_client(use_dask=True)
    arlexecute.set_client(use_dask=True, threads_per_worker=1, memory_limit=32 * 1024 * 1024 * 1024, n_workers=8,
                          local_dir=dask_dir)
    times = numpy.array([-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0]) * (numpy.pi / 12.0)
    frequency = numpy.array([4e8])
    channel_bandwidth = numpy.array([25e6])
    reffrequency = numpy.max(frequency)
    phasecentre = SkyCoord(ra=+5 * u.deg, dec=20 * 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'))

    advice = advise_wide_field(vt, wprojection_planes=1)

    vt.data['vis'] *= 0.0
    npixel=256

    model = create_image_from_visibility(vt, npixel=npixel, cellsize=6.8e-5, nchan=1,
                                        polarisation_frame=PolarisationFrame('stokesI'))
    centre = model.wcs.wcs.crpix-1
    spacing_pixels = npixel // 8
    log.info('Spacing in pixels = %s' % spacing_pixels)
    spacing = model.wcs.wcs.cdelt * spacing_pixels
    locations = [-3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5]

    original_comps = []
    # We calculate the source positions in pixels and then calculate the
    # world coordinates to put in the skycomponent description
Ejemplo n.º 3
0
    lowouter = low.data[distance > 1000.0][::6]
    lowcore = low.data[distance < 1000.0][::3]
    low.data = numpy.hstack((lowcore, lowouter))

    block_vis = create_blockvisibility(
        low,
        times,
        frequency=frequency,
        channel_bandwidth=channel_bandwidth,
        weight=1.0,
        phasecentre=phasecentre,
        polarisation_frame=PolarisationFrame("stokesI"),
        zerow=True)

    vis = convert_blockvisibility_to_visibility(block_vis)
    advice = advise_wide_field(vis, guard_band_image=2.0, delA=0.02)

    cellsize = advice['cellsize']
    vis_slices = advice['vis_slices']
    npixel = advice['npixels2']

    small_model = create_image_from_visibility(block_vis,
                                               npixel=512,
                                               frequency=frequency,
                                               nchan=nfreqwin,
                                               cellsize=cellsize,
                                               phasecentre=phasecentre)

    vis.data['imaging_weight'][...] = vis.data['weight'][...]
    vis = weight_list_serial_workflow([vis], [small_model])[0]
    vis = taper_list_serial_workflow([vis], 3 * cellsize)[0]
        rmax=rmax,
        format='blockvis')
else:
    bvis_list = list()

vis_list = [convert_blockvisibility_to_visibility(bv) for bv in bvis_list]
log.debug('%d: %d elements in vis_list' % (rank, len(vis_list)))
#log.handlers[0].flush()
#print(vis_list

# In[4]:

if rank == 0:
    wprojection_planes = 1
    advice_low = advise_wide_field(vis_list[0],
                                   guard_band_image=8.0,
                                   delA=0.02,
                                   wprojection_planes=wprojection_planes)

    advice_high = advise_wide_field(vis_list[-1],
                                    guard_band_image=8.0,
                                    delA=0.02,
                                    wprojection_planes=wprojection_planes)

    vis_slices = advice_low['vis_slices']
    npixel = advice_high['npixels2']
    cellsize = min(advice_low['cellsize'], advice_high['cellsize'])

else:
    vis_slices = 0
    npixel = 0
    cellsize = 0
Ejemplo n.º 5
0
    def test_export_ms(self):
        if run_ms_tests == False:
            return

        msoutfile = arl_path("data/vis/Test_output.ms")

        from astropy.coordinates import SkyCoord
        from astropy import units as u

        from wrappers.serial.image.operations import show_image, export_image_to_fits
        from wrappers.serial.simulation.configurations import create_named_configuration
        from wrappers.serial.simulation.testing_support import create_test_image
        from wrappers.serial.imaging.base import create_image_from_visibility
        from wrappers.serial.imaging.base import advise_wide_field

        from workflows.serial.imaging.imaging_serial import invert_list_serial_workflow, predict_list_serial_workflow

        from data_models.polarisation import PolarisationFrame

        lowr3 = create_named_configuration('LOWBD2', rmax=750.0)

        times = numpy.zeros([1])
        frequency = numpy.array([1e8])
        channelbandwidth = numpy.array([1e6])
        phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000')

        bvis = create_blockvisibility(lowr3, times, frequency, phasecentre=phasecentre,
                                               weight=1.0, polarisation_frame=PolarisationFrame('stokesI'),
                                               channel_bandwidth=channelbandwidth)

        vt = convert_blockvisibility_to_visibility(bvis)

        advice = advise_wide_field(vt, guard_band_image=3.0, delA=0.1, facets=1, wprojection_planes=1,
                                   oversampling_synthesised_beam=4.0)
        cellsize = advice['cellsize']


        m31image = create_test_image(frequency=frequency, cellsize=cellsize)
        nchan, npol, ny, nx = m31image.data.shape
        m31image.wcs.wcs.crval[0] = vt.phasecentre.ra.deg
        m31image.wcs.wcs.crval[1] = vt.phasecentre.dec.deg
        m31image.wcs.wcs.crpix[0] = float(nx // 2)
        m31image.wcs.wcs.crpix[1] = float(ny // 2)
        vt = predict_list_serial_workflow([vt], [m31image], context='2d')[0]
        # uvdist = numpy.sqrt(vt.data['uvw'][:, 0] ** 2 + vt.data['uvw'][:, 1] ** 2)
        #
        # model = create_image_from_visibility(vt, cellsize=cellsize, npixel=512)
        # dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0]
        # psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0]
        #
        # show_image(dirty)
        # print("Max, min in dirty image = %.6f, %.6f, sumwt = %f" % (dirty.data.max(), dirty.data.min(), sumwt))
        #
        # print("Max, min in PSF         = %.6f, %.6f, sumwt = %f" % (psf.data.max(), psf.data.min(), sumwt))
        # results_dir="/Users/f.wang"
        # export_image_to_fits(dirty, '%s/imaging_dirty.fits' % (results_dir))
        # export_image_to_fits(psf, '%s/imaging_psf.fits' % (results_dir))

        v = convert_visibility_to_blockvisibility(vt)
        vis_list=[]
        vis_list.append(v)
        export_blockvisility_to_ms(msoutfile, vis_list,source_name='M31')