Example #1
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)
Example #2
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)
Example #3
0
 def actualSetUp(self, add_errors=False, freqwin=1, block=False, dospectral=True, dopol=False, zerow=False):
     
     arlexecute.set_client(use_dask=False)
     
     self.npixel = 256
     self.low = create_named_configuration('LOWBD2', rmax=750.0)
     self.freqwin = freqwin
     self.vis_list = 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([0.8e8])
         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_list = [arlexecute.execute(ingest_unittest_visibility)(self.low,
                                                                     [self.frequency[freqwin]],
                                                                     [self.channelwidth[freqwin]],
                                                                     self.times,
                                                                     self.vis_pol,
                                                                     self.phasecentre, block=block,
                                                                     zerow=zerow)
                      for freqwin, _ in enumerate(self.frequency)]
     
     self.model_list = [arlexecute.execute(create_unittest_model, nout=freqwin)(self.vis_list[freqwin],
                                                                                 self.image_pol,
                                                                                 npixel=self.npixel)
                         for freqwin, _ in enumerate(self.frequency)]
     
     self.components_list = [arlexecute.execute(create_unittest_components)(self.model_list[freqwin],
                                                                             flux[freqwin, :][numpy.newaxis, :])
                              for freqwin, _ in enumerate(self.frequency)]
     
     self.model_list = [arlexecute.execute(insert_skycomponent, nout=1)(self.model_list[freqwin],
                                                                         self.components_list[freqwin])
                         for freqwin, _ in enumerate(self.frequency)]
     
     self.vis_list = [arlexecute.execute(predict_skycomponent_visibility)(self.vis_list[freqwin],
                                                                          self.components_list[freqwin])
                      for freqwin, _ in enumerate(self.frequency)]
     
     # Calculate the model convolved with a Gaussian.
     self.model = arlexecute.compute(self.model_list[0], sync=True)
     
     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)
     
     if add_errors and block:
         self.vis_list = [arlexecute.execute(insert_unittest_errors)(self.vis_list[i])
                          for i, _ in enumerate(self.frequency)]
     
     self.vis = arlexecute.compute(self.vis_list[0], sync=True)
     
     self.components = arlexecute.compute(self.components_list[0], sync=True)
Example #4
0
 def test_smooth_image(self):
     smooth = smooth_image(self.m31image)
     assert numpy.max(smooth.data) > numpy.max(self.m31image.data)
Example #5
0
def trial_case(results,
               seed=180555,
               context='wstack',
               nworkers=8,
               threads_per_worker=1,
               memory=8,
               processes=True,
               order='frequency',
               nfreqwin=7,
               ntimes=3,
               rmax=750.0,
               facets=1,
               wprojection_planes=1,
               use_dask=True,
               use_serial=False):
    """ Single trial for performance-timings
    
    Simulates visibilities from GLEAM including phase errors
    Makes dirty image and PSF
    Runs ICAL pipeline
    
    The results are in a dictionary:
    
    'context': input - a string describing concisely the purpose of the test
    'time overall',  overall execution time (s)
    'time create gleam', time to create GLEAM prediction graph
    'time predict', time to execute GLEAM prediction graph
    'time corrupt', time to corrupt data_models
    'time invert', time to make dirty image
    'time psf invert', time to make PSF
    'time ICAL graph', time to create ICAL graph
    'time ICAL', time to execute ICAL graph
    'context', type of imaging e.g. 'wstack'
    'nworkers', number of workers to create
    'threads_per_worker',
    'nnodes', Number of nodes,
    'processes', 'order', Ordering of data_models
    'nfreqwin', Number of frequency windows in simulation
    'ntimes', Number of hour angles in simulation
    'rmax', Maximum radius of stations used in simulation (m)
    'facets', Number of facets in deconvolution and imaging
    'wprojection_planes', Number of wprojection planes
    'vis_slices', Number of visibility slices (per Visibbility)
    'npixel', Number of pixels in image
    'cellsize', Cellsize in radians
    'seed', Random number seed
    'dirty_max', Maximum in dirty image
    'dirty_min', Minimum in dirty image
    'psf_max',
    'psf_min',
    'restored_max',
    'restored_min',
    'deconvolved_max',
    'deconvolved_min',
    'residual_max',
    'residual_min',
    'git_info', GIT hash (not definitive since local mods are possible)
    
    :param results: Initial state
    :param seed: Random number seed (used in gain simulations)
    :param context: imaging context
    :param context: Type of context: '2d'|'timeslice'|'wstack'
    :param nworkers: Number of dask workers to use
    :param threads_per_worker: Number of threads per worker
    :param processes: Use processes instead of threads 'processes'|'threads'
    :param order: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param nfreqwin: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param ntimes: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param rmax: See simulate_list_list_arlexecute_workflow_workflowkflow
    :param facets: Number of facets to use
    :param wprojection_planes: Number of wprojection planes to use
    :param use_dask: Use dask or immediate evaluation
    :param kwargs:
    :return: results dictionary
    """

    numpy.random.seed(seed)
    results['seed'] = seed

    start_all = time.time()

    results['context'] = context
    results['hostname'] = socket.gethostname()
    results['git_hash'] = git_hash()
    results['epoch'] = time.strftime("%Y-%m-%d %H:%M:%S")

    zerow = False
    print("Context is %s" % context)

    results['nworkers'] = nworkers
    results['threads_per_worker'] = threads_per_worker
    results['processes'] = processes
    results['memory'] = memory
    results['order'] = order
    results['nfreqwin'] = nfreqwin
    results['ntimes'] = ntimes
    results['rmax'] = rmax
    results['facets'] = facets
    results['wprojection_planes'] = wprojection_planes

    results['use_dask'] = use_dask

    print("At start, configuration is {0!r}".format(results))

    # Parameters determining scale
    frequency = numpy.linspace(0.8e8, 1.2e8, nfreqwin)
    centre = nfreqwin // 2
    if nfreqwin > 1:
        channel_bandwidth = numpy.array(nfreqwin *
                                        [frequency[1] - frequency[0]])
    else:
        channel_bandwidth = numpy.array([1e6])
    times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes)

    phasecentre = SkyCoord(ra=+30.0 * u.deg,
                           dec=-60.0 * u.deg,
                           frame='icrs',
                           equinox='J2000')

    if use_dask:
        client = get_dask_Client(threads_per_worker=threads_per_worker,
                                 memory_limit=memory * 1024 * 1024 * 1024,
                                 n_workers=nworkers)
        arlexecute.set_client(client)
        nodes = findNodes(arlexecute.client)
        unodes = list(numpy.unique(nodes))
        results['nnodes'] = len(unodes)
        print("Defined %d workers on %d nodes" % (nworkers, results['nnodes']))
        print("Workers are: %s" % str(nodes))
    else:
        arlexecute.set_client(use_dask=use_dask)
        results['nnodes'] = 1
        unodes = None

    vis_list = simulate_list_arlexecute_workflow(
        'LOWBD2',
        frequency=frequency,
        channel_bandwidth=channel_bandwidth,
        times=times,
        phasecentre=phasecentre,
        order=order,
        format='blockvis',
        rmax=rmax)

    print("****** Visibility creation ******")
    vis_list = arlexecute.persist(vis_list)

    # Find the best imaging parameters but don't bring the vis_list back here
    def get_wf(bv):
        v = convert_blockvisibility_to_visibility(bv)
        return advise_wide_field(v,
                                 guard_band_image=6.0,
                                 delA=0.02,
                                 facets=facets,
                                 wprojection_planes=wprojection_planes,
                                 oversampling_synthesised_beam=4.0)

    wprojection_planes = 1
    advice = arlexecute.compute(arlexecute.execute(get_wf)(vis_list[0]),
                                sync=True)

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

    if context == 'timeslice':
        vis_slices = ntimes
        print("Using timeslice with %d slices" % vis_slices)
    elif context == '2d':
        vis_slices = 1
    else:
        context = 'wstack'
        vis_slices = 5 * advice['vis_slices']
        print("Using wstack with %d slices" % vis_slices)

    results['vis_slices'] = vis_slices
    results['cellsize'] = cellsize
    results['npixel'] = npixel

    gleam_model_list = [
        arlexecute.execute(create_low_test_image_from_gleam)(
            npixel=npixel,
            frequency=[frequency[f]],
            channel_bandwidth=[channel_bandwidth[f]],
            cellsize=cellsize,
            phasecentre=phasecentre,
            polarisation_frame=PolarisationFrame("stokesI"),
            flux_limit=0.3,
            applybeam=True) for f, freq in enumerate(frequency)
    ]

    start = time.time()
    print("****** Starting GLEAM model creation ******")
    gleam_model_list = arlexecute.compute(gleam_model_list, sync=True)
    cmodel = smooth_image(gleam_model_list[centre])
    export_image_to_fits(cmodel,
                         "pipelines-timings-arlexecute-gleam_cmodel.fits")
    end = time.time()
    results['time create gleam'] = end - start
    print("Creating GLEAM model took %.2f seconds" % (end - start))

    gleam_model_list = arlexecute.scatter(gleam_model_list)
    vis_list = predict_list_arlexecute_workflow(vis_list,
                                                gleam_model_list,
                                                vis_slices=vis_slices,
                                                context=context)
    start = time.time()
    print("****** Starting GLEAM model visibility prediction ******")
    vis_list = arlexecute.compute(vis_list, sync=True)

    end = time.time()
    results['time predict'] = end - start
    print("GLEAM model Visibility prediction took %.2f seconds" %
          (end - start))

    # Corrupt the visibility for the GLEAM model
    print("****** Visibility corruption ******")
    vis_list = corrupt_list_arlexecute_workflow(vis_list, phase_error=1.0)
    start = time.time()
    vis_list = arlexecute.compute(vis_list, sync=True)

    vis_list = arlexecute.scatter(vis_list)

    end = time.time()
    results['time corrupt'] = end - start
    print("Visibility corruption took %.2f seconds" % (end - start))

    # Create an empty model image
    model_list = [
        arlexecute.execute(create_image_from_visibility)(
            vis_list[f],
            npixel=npixel,
            cellsize=cellsize,
            frequency=[frequency[f]],
            channel_bandwidth=[channel_bandwidth[f]],
            polarisation_frame=PolarisationFrame("stokesI"))
        for f, freq in enumerate(frequency)
    ]
    model_list = arlexecute.compute(model_list, sync=True)
    model_list = arlexecute.scatter(model_list)

    psf_list = invert_list_arlexecute_workflow(vis_list,
                                               model_list,
                                               vis_slices=vis_slices,
                                               context=context,
                                               facets=facets,
                                               dopsf=True)
    start = time.time()
    print("****** Starting PSF calculation ******")
    psf, sumwt = arlexecute.compute(psf_list, sync=True)[centre]
    end = time.time()
    results['time psf invert'] = end - start
    print("PSF invert took %.2f seconds" % (end - start))

    results['psf_max'] = qa_image(psf).data['max']
    results['psf_min'] = qa_image(psf).data['min']

    dirty_list = invert_list_arlexecute_workflow(vis_list,
                                                 model_list,
                                                 vis_slices=vis_slices,
                                                 context=context,
                                                 facets=facets)
    start = time.time()
    print("****** Starting dirty image calculation ******")
    dirty, sumwt = arlexecute.compute(dirty_list, sync=True)[centre]
    end = time.time()
    results['time invert'] = end - start
    print("Dirty image invert took %.2f seconds" % (end - start))
    print("Maximum in dirty image is ", numpy.max(numpy.abs(dirty.data)),
          ", sumwt is ", sumwt)
    qa = qa_image(dirty)
    results['dirty_max'] = qa.data['max']
    results['dirty_min'] = qa.data['min']

    # Create the ICAL pipeline to run 5 major cycles, starting selfcal at cycle 1. A global solution across all
    # frequencies (i.e. Visibilities) is performed.
    start = time.time()
    print("****** Starting ICAL ******")

    controls = create_calibration_controls()

    controls['T']['first_selfcal'] = 1
    controls['G']['first_selfcal'] = 3
    controls['B']['first_selfcal'] = 4

    controls['T']['timescale'] = 'auto'
    controls['G']['timescale'] = 'auto'
    controls['B']['timescale'] = 1e5

    if nfreqwin > 6:
        nmoment = 3
        algorithm = 'mmclean'
    elif nfreqwin > 2:
        nmoment = 2
        algorithm = 'mmclean'
    else:
        nmoment = 1
        algorithm = 'msclean'

    start = time.time()
    ical_list = ical_list_arlexecute_workflow(vis_list,
                                              model_imagelist=model_list,
                                              context='wstack',
                                              calibration_context='TG',
                                              controls=controls,
                                              scales=[0, 3, 10],
                                              algorithm=algorithm,
                                              nmoment=nmoment,
                                              niter=1000,
                                              fractional_threshold=0.1,
                                              threshold=0.1,
                                              nmajor=5,
                                              gain=0.25,
                                              vis_slices=vis_slices,
                                              timeslice='auto',
                                              global_solution=False,
                                              psf_support=64,
                                              do_selfcal=True)

    end = time.time()
    results['time ICAL graph'] = end - start
    print("Construction of ICAL graph took %.2f seconds" % (end - start))

    # Execute the graph
    start = time.time()
    result = arlexecute.compute(ical_list, sync=True)
    deconvolved, residual, restored = result
    end = time.time()

    results['time ICAL'] = end - start
    print("ICAL graph execution took %.2f seconds" % (end - start))
    qa = qa_image(deconvolved[centre])
    results['deconvolved_max'] = qa.data['max']
    results['deconvolved_min'] = qa.data['min']
    export_image_to_fits(deconvolved[centre],
                         "pipelines-timings-arlexecute-ical_deconvolved.fits")

    qa = qa_image(residual[centre][0])
    results['residual_max'] = qa.data['max']
    results['residual_min'] = qa.data['min']
    export_image_to_fits(residual[centre][0],
                         "pipelines-timings-arlexecute-ical_residual.fits")

    qa = qa_image(restored[centre])
    results['restored_max'] = qa.data['max']
    results['restored_min'] = qa.data['min']
    export_image_to_fits(restored[centre],
                         "pipelines-timings-arlexecute-ical_restored.fits")
    #
    arlexecute.close()

    end_all = time.time()
    results['time overall'] = end_all - start_all

    print("At end, results are {0!r}".format(results))

    return results