def test_mpccal_ICAL_onesource(self): self.actualSetup(nsources=1, nvoronoi=1) model = create_empty_image_like(self.theta_list[0].image) if rsexecute.using_dask: progress = None else: progress = self.progress future_vis = rsexecute.scatter(self.all_skymodel_noniso_vis) future_model = rsexecute.scatter(model) future_theta_list = rsexecute.scatter(self.theta_list) result = mpccal_skymodel_list_rsexecute_workflow(future_vis, future_model, future_theta_list, mpccal_progress=progress, nmajor=5, context='2d', algorithm='hogbom', scales=[0, 3, 10], fractional_threshold=0.15, threshold=0.05, gain=0.1, niter=1000, psf_support=256, deconvolve_facets=8, deconvolve_overlap=16, deconvolve_taper='tukey') (self.theta_list, residual) = rsexecute.compute(result, sync=True) combined_model = calculate_skymodel_equivalent_image(self.theta_list) psf_obs = invert_list_rsexecute_workflow([self.all_skymodel_noniso_vis], [model], context='2d', dopsf=True) result = restore_list_rsexecute_workflow([combined_model], psf_obs, [(residual, 0.0)]) result = rsexecute.compute(result, sync=True) if self.persist: export_image_to_fits(residual, rascil_path('test_results/test_mpccal_ical_onesource_residual.fits')) if self.persist: export_image_to_fits(result[0], rascil_path('test_results/test_mpccal_ical_onesource_restored.fits')) if self.persist: export_image_to_fits(combined_model, rascil_path('test_results/test_mpccal_ical_onesource_deconvolved.fits')) recovered_mpccal_components = find_skycomponents(result[0], fwhm=2, threshold=0.32, npixels=12) def max_flux(elem): return numpy.max(elem.flux) recovered_mpccal_components = sorted(recovered_mpccal_components, key=max_flux, reverse=True) assert recovered_mpccal_components[0].name == 'Segment 0', recovered_mpccal_components[0].name assert numpy.abs(recovered_mpccal_components[0].flux[0, 0] - 1.138095494391862) < 1e-6, \ recovered_mpccal_components[0].flux[0, 0] newscreen = create_empty_image_like(self.screen) gaintables = [th.gaintable for th in self.theta_list] newscreen, weights = grid_gaintable_to_screen(self.all_skymodel_noniso_blockvis, gaintables, newscreen) if self.persist: export_image_to_fits(newscreen, rascil_path('test_results/test_mpccal_ical_onesource_screen.fits')) if self.persist: export_image_to_fits(weights, rascil_path('test_results/test_mpccal_ical_onesource_screenweights.fits')) rsexecute.close()
def write_image(im, im_type="restored", index=0, axis='spw'): filename_root = \ "{results_directory}/{project:s}_{source:s}_{pipeline}_{im_type:s}_{axis}{index:d}".format( results_directory=results_directory, project=erp_params["configure"]["project"], source=erp_params["ingest"]["source"], im_type=im_type, pipeline=pipeline, axis=axis, index=index) log.info(qa_image(im, context=filename_root)) plt.clf() show_image(im, title=filename_root) plotfile = "{0}.png".format(filename_root) plt.savefig(plotfile) plt.show(block=False) filename = "{0}.fits".format(filename_root) export_image_to_fits(im, filename)
def progress(res, tl_list, gt_list, it, context='MPCCAL'): print('Iteration %d' % it) print( qa_image(res, context='%s residual image: iteration %d' % (context, it))) export_image_to_fits( res, rascil_path( "test_results/low-sims-mpc-%s-residual_iteration%d_rmax%.1f.fits" % (context, it, rmax))) show_image(res, title='%s residual image: iteration %d' % (context, it)) plt.show(block=block_plots) combined_model = calculate_skymodel_equivalent_image(tl_list) print( qa_image(combined_model, context='Combined model: iteration %d' % it)) export_image_to_fits( combined_model, rascil_path( "test_results/low-sims-mpc-%s-model_iteration%d_rmax%.1f.fits" % (context, it, rmax))) plt.clf() for i in range(len(tl_list)): plt.plot( numpy.angle(tl_list[i].gaintable.gain[:, :, 0, 0, 0]).flatten(), numpy.angle(gt_list[i]['T'].gain[:, :, 0, 0, 0]).flatten(), '.') plt.xlabel('Current phase') plt.ylabel('Update to phase') plt.title("%s iteration%d: Change in phase" % (context, it)) plt.savefig( rascil_path( "test_results/low-sims-mpc-%s-skymodel-phase-change_iteration%d.jpg" % (context, it))) plt.show(block=block_plots) return tl_list
m, threshold=0.01, fracthresh=0.01, window_shape='quarter', niter=100, gain=0.1, algorithm='hogbom-complex') r = restore_cube(c, p[0], resid) return r restored_list = [ rsexecute.execute(deconvolve)(dirty_list[c], psf_list[c], model_list[c]) for c in range(nchan) ] restored_cube = rsexecute.execute(image_gather_channels, nout=1)(restored_list) # Up to this point all we have is a graph. Now we compute it and get the # final restored cleaned cube. During the compute, Dask shows diagnostic pages # at http://127.0.0.1:8787 restored_cube = rsexecute.compute(restored_cube, sync=True) # Save the cube print("Processing took %.3f s" % (time.time() - start)) print(qa_image(restored_cube, context='CLEAN restored cube')) export_image_to_fits( restored_cube, '%s/dprepb_rsexecute_%s_clean_restored_cube.fits' % (results_dir, context)) rsexecute.close()
print(qa_image(residual, context='ICAL residual image')) print('ical finished') combined_model = calculate_skymodel_equivalent_image(ical_skymodel) print(qa_image(combined_model, context='ICAL combined model')) psf_obs = invert_list_rsexecute_workflow([future_vis], [future_model], context='2d', dopsf=True) result = restore_list_rsexecute_workflow([combined_model], psf_obs, [(residual, 0.0)]) result = rsexecute.compute(result, sync=True) ical_restored = result[0] export_image_to_fits( ical_restored, rascil_path('test_results/low-sims-mpc-ical-restored_%.1frmax.fits' % rmax)) ####################################################################################################### # Now set up the skymodels for MPCCAL. We find the brightest components in the ICAL image, remove # sources that are too close to another stronger source, and then use these to set up # a Voronoi tesselation to define the skymodel masks ical_components = find_skycomponents(ical_restored, fwhm=2, threshold=args.finding_threshold, npixels=12) for comp in all_components[:args.ninitial]: ical_components.append(comp) # ### Remove weaker of components that are too close (0.02 rad)
cellsize = 0.0005 npixel = 1024 pol_frame = PolarisationFrame("stokesI") model_list = [ rsexecute.execute(create_image_from_visibility)( v, npixel=npixel, cellsize=cellsize, polarisation_frame=pol_frame) for v in vis_list ] model_list = rsexecute.persist(model_list) imaging_context = 'ng' vis_slices = 1 dirty_list = invert_list_rsexecute_workflow( vis_list, template_model_imagelist=model_list, context=imaging_context, vis_slices=vis_slices) log.info('About to run invert_list_rsexecute_workflow') result = rsexecute.compute(dirty_list, sync=True) dirty, sumwt = result[centre] rsexecute.close() export_image_to_fits(dirty, '%s/ska-imaging_rsexecute_dirty.fits' % (results_dir)) exit(0)
if __name__ == '__main__': results_dir = rascil_path('test_results') bvt = create_blockvisibility_from_ms(rascil_path('data/vis/sim-2.ms'), start_chan=35, end_chan=39)[0] bvt.configuration.diameter[...] = 35.0 vt = convert_blockvisibility_to_visibility(bvt) vt = convert_visibility_to_stokes(vt) a2r = numpy.pi / (180.0 * 3600.0) model = create_image_from_visibility(vt, cellsize=20.0 * a2r, npixel=512, polarisation_frame=PolarisationFrame('stokesIQUV')) dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0] psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0] export_image_to_fits(dirty, '%s/rascil_imaging_sim_2_dirty.fits' % (results_dir)) export_image_to_fits(psf, '%s/rascil_imaging_sim_2_psf.fits' % (results_dir)) # Deconvolve using msclean comp, residual = deconvolve_cube(dirty, psf, niter=10000, threshold=0.001, fractional_threshold=0.001, algorithm='msclean', window_shape='quarter', gain=0.7, scales=[0, 3, 10, 30]) restored = restore_cube(comp, psf, residual) print(qa_image(restored)) export_image_to_fits(restored, '%s/rascil_imaging_sim_2_restored.fits' % (results_dir)) export_image_to_fits(residual, '%s/rascil_imaging_sim_2_residual.fits' % (results_dir))
else: psf_list = invert_list_rsexecute_workflow(future_bvis_list, future_psf_list, args.imaging_context, dopsf=True, verbosity=0, nthreads=nthreads, do_wstacking=not zerow) psf_list = rsexecute.compute(psf_list, sync=True) psf, sumwt = sum_invert_results(psf_list) print("PSF sumwt ", sumwt) print(qa_image(psf, context='PSF')) if export_images: export_image_to_fits(psf, 'PSF_rascil.fits') if show: show_image(psf, cm='gray_r', title='%s PSF' % basename, vmin=-0.01, vmax=0.1) plt.savefig('PSF_rascil.png') plt.show(block=False) del psf_list del future_psf_list if context == "s3sky": pb_list = [ rsexecute.execute(create_image_from_visibility)( bv,
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_imaging=True, flux_limit=0.3, nmajor=5, dft_threshold=1.0, use_serial_clean=True, write_fits=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 predict', time to execute GLEAM prediction graph 'time invert', time to make dirty image 'time invert graph', time to make dirty image graph '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 '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_rsexecute_workflow_workflowkflow :param nfreqwin: See simulate_list_list_rsexecute_workflow_workflowkflow :param ntimes: See simulate_list_list_rsexecute_workflow_workflowkflow :param rmax: See simulate_list_list_rsexecute_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 :return: results dictionary """ if use_dask: scheduler = os.getenv('RASCIL_DASK_SCHEDULER', None) if scheduler is not None: client = get_dask_client(n_workers=nworkers, memory_limit=memory * 1024 * 1024 * 1024, threads_per_worker=threads_per_worker) rsexecute.set_client(client=client) else: rsexecute.set_client(threads_per_worker=threads_per_worker, processes=threads_per_worker == 1, memory_limit=memory * 1024 * 1024 * 1024, n_workers=nworkers) print("Defined %d workers" % (nworkers)) else: rsexecute.set_client(use_dask=use_dask) results['nnodes'] = 1 def init_logging(): logging.basicConfig( filename='pipelines_rsexecute_timings.log', filemode='w', format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', datefmt='%H:%M:%S', level=logging.INFO) init_logging() log = logging.getLogger() # Initialise logging on the workers. This appears to only work using the process scheduler. rsexecute.run(init_logging) def lprint(*args): log.info(*args) print(*args) lprint("Starting pipelines_rsexecute_timings") 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") lprint("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['dft threshold'] = dft_threshold results['use_dask'] = use_dask lprint("At start, configuration is:") lprint(sort_dict(results)) # Parameters determining scale of simulation. frequency = numpy.linspace(1.0e8, 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 / 4.0, numpy.pi / 4.0, ntimes) phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-40.0 * u.deg, frame='icrs', equinox='J2000') lprint("****** Visibility creation ******") # Create the empty BlockVisibility's and persist these on the cluster tmp_bvis_list = simulate_list_rsexecute_workflow( 'LOWBD2', frequency=frequency, channel_bandwidth=channel_bandwidth, times=times, phasecentre=phasecentre, order=order, format='blockvis', rmax=rmax) tmp_vis_list = [ rsexecute.execute(convert_blockvisibility_to_visibility)(bv) for bv in tmp_bvis_list ] tmp_vis_list = rsexecute.client.compute(tmp_vis_list, sync=True) vis_list = rsexecute.gather(tmp_vis_list) import matplotlib.pyplot as plt plt.clf() plt.hist(vis_list[0].w, bins=100) plt.title('Histogram of w samples: rms=%.1f (wavelengths)' % numpy.std(vis_list[0].w)) plt.xlabel('W (wavelengths)') #plt.show() plt.clf() plt.hist(vis_list[0].uvdist, bins=100) plt.title('Histogram of uvdistance samples') plt.xlabel('UV Distance (wavelengths)') #plt.show() rsexecute.client.cancel(tmp_vis_list) future_vis_list = rsexecute.scatter(vis_list) # Find the best imaging parameters but don't bring the vis_list back here print("****** Finding wide field parameters ******") future_advice = [ rsexecute.execute(advise_wide_field)( v, guard_band_image=6.0, delA=0.1, facets=facets, wprojection_planes=wprojection_planes, oversampling_synthesised_beam=4.0) for v in future_vis_list ] future_advice = rsexecute.compute(future_advice) advice = rsexecute.client.gather(future_advice)[-1] rsexecute.client.cancel(future_advice) # Deconvolution via sub-images requires 2^n npixel = advice['npixels2'] results['npixel'] = npixel cellsize = advice['cellsize'] results['cellsize'] = cellsize lprint("Image will have %d by %d pixels, cellsize = %.6f rad" % (npixel, npixel, cellsize)) # Create an empty model image tmp_model_list = [ rsexecute.execute(create_image)( npixel=npixel, cellsize=cellsize, frequency=[frequency[f]], channel_bandwidth=[channel_bandwidth[f]], phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) for f, freq in enumerate(frequency) ] model_list = rsexecute.compute(tmp_model_list, sync=True) future_model_list = rsexecute.scatter(model_list) lprint("****** Setting up imaging parameters ******") # Now set up the imaging parameters template_model = create_image( npixel=npixel, cellsize=cellsize, frequency=[frequency[centre]], phasecentre=phasecentre, channel_bandwidth=[channel_bandwidth[centre]], polarisation_frame=PolarisationFrame("stokesI")) gcfcf = [create_pswf_convolutionfunction(template_model)] if context == 'timeslice': vis_slices = ntimes lprint("Using timeslice with %d slices" % vis_slices) elif context == '2d': vis_slices = 1 elif context == "wprojection": wstep = advice['wstep'] nw = advice['wprojection_planes'] vis_slices = 1 support = advice['nwpixels'] results['wprojection_planes'] = nw lprint("****** Starting W projection kernel creation ******") lprint("Using wprojection with %d planes with wstep %.1f wavelengths" % (nw, wstep)) lprint("Support of wprojection = %d pixels" % support) gcfcf = [ create_awterm_convolutionfunction(template_model, nw=nw, wstep=wstep, oversampling=4, support=support, use_aaf=True) ] lprint("Size of W projection gcf, cf = %.2E bytes" % get_size(gcfcf)) else: context = 'wstack' vis_slices = advice['vis_slices'] lprint("Using wstack with %d slices" % vis_slices) gcfcf = rsexecute.scatter(gcfcf, broadcast=True) results['vis_slices'] = vis_slices # Make a skymodel from gleam, with bright sources as components and weak sources in an image lprint("****** Starting GLEAM skymodel creation ******") future_skymodel_list = [ rsexecute.execute(create_low_test_skymodel_from_gleam)( npixel=npixel, cellsize=cellsize, frequency=[frequency[f]], phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI"), flux_limit=flux_limit, flux_threshold=dft_threshold, flux_max=5.0) for f, freq in enumerate(frequency) ] # We use predict_skymodel so that we can use skycomponents as well as images lprint("****** Starting GLEAM skymodel prediction ******") predicted_vis_list = [ predict_skymodel_list_rsexecute_workflow(future_vis_list[f], [future_skymodel_list[f]], context=context, vis_slices=vis_slices, facets=facets, gcfcf=gcfcf)[0] for f, freq in enumerate(frequency) ] # Corrupt the visibility for the GLEAM model lprint("****** Visibility corruption ******") tmp_corrupted_vis_list = corrupt_list_rsexecute_workflow( predicted_vis_list, phase_error=1.0, seed=seed) lprint("****** Weighting and tapering ******") tmp_corrupted_vis_list = weight_list_rsexecute_workflow( tmp_corrupted_vis_list, future_model_list) tmp_corrupted_vis_list = taper_list_rsexecute_workflow( tmp_corrupted_vis_list, 0.003 * 750.0 / rmax) tmp_corrupted_vis_list = rsexecute.compute(tmp_corrupted_vis_list, sync=True) corrupted_vis_list = rsexecute.gather(tmp_corrupted_vis_list) # rsexecute.client.cancel(predicted_vis_list) rsexecute.client.cancel(tmp_corrupted_vis_list) future_corrupted_vis_list = rsexecute.scatter(corrupted_vis_list) # At this point the only futures are of scatter'ed data so no repeated calculations should be # incurred. lprint("****** Starting dirty image calculation ******") start = time.time() dirty_list = invert_list_rsexecute_workflow( future_corrupted_vis_list, future_model_list, vis_slices=vis_slices, context=context, facets=facets, use_serial_invert=use_serial_imaging, gcfcf=gcfcf) results['size invert graph'] = get_size(dirty_list) lprint('Size of dirty graph is %.3E bytes' % (results['size invert graph'])) end = time.time() results['time invert graph'] = end - start lprint("Construction of invert graph took %.3f seconds" % (end - start)) start = time.time() dirty, sumwt = rsexecute.compute(dirty_list, sync=True)[centre] end = time.time() results['time invert'] = end - start lprint("Dirty image invert took %.3f seconds" % (end - start)) lprint("Maximum in dirty image is %f, sumwt is %s" % (numpy.max(numpy.abs(dirty.data)), str(sumwt))) qa = qa_image(dirty) results['dirty_max'] = qa.data['max'] results['dirty_min'] = qa.data['min'] if write_fits: export_image_to_fits( dirty, "pipelines_rsexecute_timings-%s-dirty.fits" % context) lprint("****** Starting prediction ******") start = time.time() tmp_vis_list = predict_list_rsexecute_workflow( future_corrupted_vis_list, future_model_list, vis_slices=vis_slices, context=context, facets=facets, use_serial_predict=use_serial_imaging, gcfcf=gcfcf) result = rsexecute.compute(tmp_vis_list, sync=True) # rsexecute.client.cancel(tmp_vis_list) end = time.time() results['time predict'] = end - start lprint("Predict took %.3f seconds" % (end - start)) # Create the ICAL pipeline to run major cycles, starting selfcal at cycle 1. A global solution across all # frequencies (i.e. Visibilities) is performed. print("Using subimage clean") deconvolve_facets = 8 deconvolve_overlap = 16 deconvolve_taper = 'tukey' lprint("****** Starting ICAL graph creation ******") controls = create_calibration_controls() controls['T']['first_selfcal'] = 1 controls['T']['timeslice'] = 'auto' start = time.time() ical_list = ical_list_rsexecute_workflow( future_corrupted_vis_list, model_imagelist=future_model_list, context=context, vis_slices=vis_slices, scales=[0, 3, 10], algorithm='mmclean', nmoment=3, niter=1000, fractional_threshold=0.1, threshold=0.01, nmajor=nmajor, gain=0.25, psf_support=64, deconvolve_facets=deconvolve_facets, deconvolve_overlap=deconvolve_overlap, deconvolve_taper=deconvolve_taper, timeslice='auto', global_solution=True, do_selfcal=True, calibration_context='T', controls=controls, use_serial_predict=use_serial_imaging, use_serial_invert=use_serial_imaging, use_serial_clean=use_serial_clean, gcfcf=gcfcf) results['size ICAL graph'] = get_size(ical_list) lprint('Size of ICAL graph is %.3E bytes' % results['size ICAL graph']) end = time.time() results['time ICAL graph'] = end - start lprint("Construction of ICAL graph took %.3f seconds" % (end - start)) print("Current objects on cluster: ") pp.pprint(rsexecute.client.who_has()) # # Execute the graph lprint("****** Executing ICAL graph ******") start = time.time() deconvolved, residual, restored, gaintables = rsexecute.compute(ical_list, sync=True) end = time.time() results['time ICAL'] = end - start lprint("ICAL graph execution took %.3f seconds" % (end - start)) qa = qa_image(deconvolved[centre]) results['deconvolved_max'] = qa.data['max'] results['deconvolved_min'] = qa.data['min'] deconvolved_cube = image_gather_channels(deconvolved) if write_fits: export_image_to_fits( deconvolved_cube, "pipelines_rsexecute_timings-%s-ical_deconvolved.fits" % context) qa = qa_image(residual[centre][0]) results['residual_max'] = qa.data['max'] results['residual_min'] = qa.data['min'] residual_cube = remove_sumwt(residual) residual_cube = image_gather_channels(residual_cube) if write_fits: export_image_to_fits( residual_cube, "pipelines_rsexecute_timings-%s-ical_residual.fits" % context) qa = qa_image(restored[centre]) results['restored_max'] = qa.data['max'] results['restored_min'] = qa.data['min'] restored_cube = image_gather_channels(restored) if write_fits: export_image_to_fits( restored_cube, "pipelines_rsexecute_timings-%s-ical_restored.fits" % context) # rsexecute.close() end_all = time.time() results['time overall'] = end_all - start_all lprint("At end, results are:") results = sort_dict(results) lprint(results) return results
nmajor=5, gain=0.25, deconvolve_facets=1, deconvolve_overlap=0, restore_facets=8, timeslice='auto', psf_support=128, global_solution=False, calibration_context='T', do_selfcal=True) log.info('About to run ICAL workflow') result = rsexecute.compute(ical_list, sync=True) rsexecute.close() deconvolved = result[0][centre] residual = result[1][centre] restored = result[2][centre] print(qa_image(deconvolved, context='Clean image')) export_image_to_fits( deconvolved, '%s/ska-ical_rsexecute_deconvolved.fits' % (results_dir)) print(qa_image(restored, context='Restored clean image')) export_image_to_fits(restored, '%s/ska-ical_rsexecute_restored.fits' % (results_dir)) print(qa_image(residual[0], context='Residual clean image')) export_image_to_fits(residual[0], '%s/ska-ical_rsexecute_residual.fits' % (results_dir))
for vis in future_vis_list ] bvis_list = rsexecute.compute(bvis_list, sync=True) future_bvis_list = rsexecute.scatter(bvis_list) del bvis_list print("Inverting to get PSF") psf_list = invert_list_rsexecute_workflow(future_vis_list, future_psf_list, args.imaging_context, dopsf=True) psf_list = rsexecute.compute(psf_list, sync=True) psf, sumwt = sum_invert_results(psf_list) print("PSF sumwt ", sumwt) if export_images: export_image_to_fits(psf, 'PSF_rascil.fits') if show: show_image(psf, cm='gray_r', title='%s PSF' % basename, vmin=-0.01, vmax=0.1) plt.savefig('PSF_rascil.png') plt.show(block=False) del psf_list del future_psf_list # ### Calculate the voltage pattern without errors vp_list = [ rsexecute.execute(create_image_from_visibility)( bv,
phasecentre=vt.phasecentre) # Predict the visibility for the Image vt = predict_2d(vt, m31image, context='2d') # Make the dirty image and point spread function model = create_image_from_visibility(vt, cellsize=cellsize, npixel=512) dirty, sumwt = invert_2d(vt, model, context='2d') psf, sumwt = invert_2d(vt, model, context='2d', dopsf=True) 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)) export_image_to_fits(dirty, '%s/imaging_dirty.fits' % (results_dir)) export_image_to_fits(psf, '%s/imaging_psf.fits' % (results_dir)) # Deconvolve using clean comp, residual = deconvolve_cube(dirty, psf, niter=10000, threshold=0.001, fractional_threshold=0.001, window_shape='quarter', gain=0.7, scales=[0, 3, 10, 30]) restored = restore_cube(comp, psf, residual) print("Max, min in restored image = %.6f, %.6f, sumwt = %f" % (restored.data.max(), restored.data.min(), sumwt))
vis_list = rsexecute.compute(vis_list, sync=True) future_vis_list = rsexecute.scatter(vis_list) del vis_list bvis_list = [rsexecute.execute(convert_visibility_to_blockvisibility)(vis) for vis in future_vis_list] bvis_list = rsexecute.compute(bvis_list, sync=True) future_bvis_list = rsexecute.scatter(bvis_list) del bvis_list print("Inverting to get PSF") psf_list = invert_list_rsexecute_workflow(future_vis_list, future_psf_list, '2d', dopsf=True) psf_list = rsexecute.compute(psf_list, sync=True) psf, sumwt = sum_invert_results(psf_list) print("PSF sumwt ", sumwt) if export_images: export_image_to_fits(psf, 'PSF_arl.fits') if show: show_image(psf, cm='gray_r', title='%s PSF' % basename, vmin=-0.01, vmax=0.1) plt.savefig('PSF_arl.png') plt.show(block=False) del psf_list del future_psf_list # ### Calculate the voltage pattern without errors vp_list = [rsexecute.execute(create_image_from_visibility)(bv, npixel=pb_npixel, frequency=frequency, nchan=nfreqwin, cellsize=pb_cellsize, phasecentre=phasecentre, override_cellsize=False) for bv in future_bvis_list] print("Constructing voltage pattern") vp_list = [rsexecute.execute(create_vp)(vp, pbtype, pointingcentre=phasecentre, use_local=not use_radec) for vp in vp_list]
if context == 'wprojection' or context == 'wprojectwstack': gcfcf_list = [ rsexecute.execute(create_awterm_convolutionfunction)( m, nw=nwplanes, wstep=wstep, oversampling=args.oversampling, support=support, maxsupport=512) for m in model_list ] gcfcf_list = rsexecute.persist(gcfcf_list) gcfcf = rsexecute.compute(gcfcf_list[0], sync=True) cf = convert_convolutionfunction_to_image(gcfcf[1]) cf.data = numpy.real(cf.data) export_image_to_fits(cf, "cf.fits") else: gcfcf_list = None #################################################################################################################### rsexecute.init_statistics() if mode == 'pipeline': log.info("\nRunning pipeline") cip_result = continuum_imaging_list_rsexecute_workflow( vis_list, model_list, context=actual_context, vis_slices=vis_slices, use_serial_invert=use_serial_invert,