def test_deconvolve_msmfsclean_no_taylor(self): self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=self.niter, gain=0.1, algorithm='msmfsclean', scales=[0, 3, 10], threshold=0.01, nmoments=1, findpeak='ARL', fractional_threshold=0.01, window=self.innerquarter) export_image_to_fits( self.comp, "%s/test_deconvolve_msmfsclean_notaylor-comp.fits" % (self.dir)) export_image_to_fits( self.residual, "%s/test_deconvolve_msmfsclean_notaylor-residual.fits" % (self.dir)) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits( self.cmodel, "%s/test_deconvolve_msmfsclean_notaylor-clean.fits" % (self.dir)) assert numpy.max(self.residual.data) < 1.4
def test_deconvolve_and_restore_cube_hogbom(self): self.bigmodel.data *= 0.0 visres, model, residual = solve_image(self.vis, self.bigmodel, niter=1000, nmajor=5, threshold=0.01, psf_support=200, window='quarter', fractional_threshold=0.1, gain=0.1, algorithm='hogbom') export_image_to_fits( model, '%s/test_solve_skycomponent_hogbom_solution.fits' % (self.dir)) export_image_to_fits( residual, '%s/test_solve_skycomponent_hogbom_residual.fits' % (self.dir)) psf, sumwt = invert_2d(self.vis, model, dopsf=True) export_image_to_fits( psf, '%s/test_solve_skycomponent_hogbom_psf.fits' % (self.dir)) restored = restore_cube(model=model, psf=psf, residual=residual) export_image_to_fits( restored, '%s/test_solve_skycomponent_hogbom_restored.fits' % (self.dir)) assert numpy.max(numpy.abs(residual.data)) < 0.5
def test_deconvolve_mmclean_quadratic_psf(self): self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=self.niter, gain=0.1, algorithm='mmclean', scales=[0, 3, 10], threshold=0.01, nmoments=2, findpeak='ARL', fractional_threshold=0.01, window=self.innerquarter, psf_support=32) export_image_to_fits( self.comp, "%s/test_deconvolve_mmclean_quadratic_psf-comp.fits" % self.dir) export_image_to_fits( self.residual, "%s/test_deconvolve_mmclean_quadratic_psf-residual.fits" % self.dir) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits( self.cmodel, "%s/test_deconvolve_mmclean_quadratic_psf-clean.fits" % self.dir) assert numpy.max(self.residual.data) < 3.0
def test_deconvolve_hogbom_inner_quarter(self): self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, window='quarter', niter=10000, gain=0.1, algorithm='hogbom', threshold=0.01) export_image_to_fits(self.residual, "%s/test_deconvolve_hogbom_innerquarter-residual.fits" % (self.dir)) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits(self.cmodel, "%s/test_deconvolve_hogbom_innerquarter-clean.fits" % (self.dir)) assert numpy.max(self.residual.data) < 1.1
def test_deconvolve_hogbom_subpsf(self): self.comp, self.residual = deconvolve_cube(self.dirty, psf=self.psf, psf_support=200, window='quarter', niter=10000, gain=0.1, algorithm='hogbom', threshold=0.01) export_image_to_fits(self.residual, "%s/test_deconvolve_hogbom_subpsf-residual.fits" % (self.dir)) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits(self.cmodel, "%s/test_deconvolve_hogbom_subpsf-clean.fits" % (self.dir)) assert numpy.max(self.residual.data[..., 56:456, 56:456]) < 1.1
def test_deconvolve_msclean_1scale(self): self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=10000, gain=0.1, algorithm='msclean', scales=[0], threshold=0.01) export_image_to_fits(self.comp, "%s/test_deconvolve_msclean_1scale-comp.fits" % (self.dir)) export_image_to_fits(self.residual, "%s/test_deconvolve_msclean_1scale-residual.fits" % (self.dir)) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits(self.cmodel, "%s/test_deconvolve_msclean_1scale-clean.fits" % (self.dir)) assert numpy.max(self.residual.data) < 0.7
def test_deconvolve_msclean_inner_quarter(self): self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, window='quarter', niter=1000, gain=0.7, algorithm='msclean', scales=[0, 3, 10, 30], threshold=0.01) export_image_to_fits(self.comp, "%s/test_deconvolve_msclean_innerquarter-comp.fits" % (self.dir)) export_image_to_fits(self.residual, "%s/test_deconvolve_msclean_innerquarter-residual.fits" % (self.dir)) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits(self.cmodel, "%s/test_deconvolve_msclean_innerquarter-clean.fits" % (self.dir)) assert numpy.max(self.residual.data) < 0.5
def test_deconvolve_msclean_subpsf(self): self.comp, self.residual = deconvolve_cube(self.dirty, psf=self.psf, psf_support=200, window=self.innerquarter, niter=1000, gain=0.7, algorithm='msclean', scales=[0, 3, 10, 30], threshold=0.01) export_image_to_fits(self.comp, "%s/test_deconvolve_msclean_subpsf-comp.fits" % (self.dir)) export_image_to_fits(self.residual, "%s/test_deconvolve_msclean_subpsf-residual.fits" % (self.dir)) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits(self.cmodel, "%s/test_deconvolve_msclean_subpsf-clean.fits" % (self.dir)) assert numpy.max(self.residual.data[..., 56:456, 56:456]) < 1.0
def main(): dirty = load(2) psf = load(1) comp, residual = deconvolve_cube(dirty, psf, niter=1000, threshold=0.001, fracthresh=0.01, window='quarter', gain=0.7, scales=[0, 3, 10, 30]) restored = restore_cube(comp, psf, residual) fig = show_image(comp) plt.title('Solution') fig.savefig('%s_Sol.png' % sys.argv[5]) fig = show_image(residual) plt.title('Residual') fig.savefig('%s_Residual.png' % sys.argv[6]) fig = show_image(restored) plt.title('Restored') fig.savefig('%s_Restored.png' % sys.argv[7]) dump(3, comp) dump(4, residual)
def test_deconvolve_and_restore_cube_mmclean(self): self.bigmodel.data *= 0.0 visres, model, residual = solve_image(self.vis, self.bigmodel, nmajor=3, niter=1000, threshold=0.01, gain=0.7, window='quarter', scales=[0, 3, 10, 30], fractional_threshold=0.1, algorithm='mfsmsclean', nmoments=3) export_image_to_fits( model, '%s/test_solve_image_mmclean_solution.fits' % (self.dir)) export_image_to_fits( residual, '%s/test_solve_image_mmclean_residual.fits' % (self.dir)) psf, sumwt = invert_2d(self.vis, model, dopsf=True) export_image_to_fits( psf, '%s/test_solve_image_mmclean_psf.fits' % (self.dir)) restored = restore_cube(model=model, psf=psf, residual=residual) export_image_to_fits( restored, '%s/test_solve_image_mmclean_restored.fits' % (self.dir)) assert numpy.max(numpy.abs(residual.data)) < 1.2
def restore_kernel(ixs, **kwargs): (model, psf), residual = ixs return restore_cube(model, psf[0], residual[0], **kwargs)
def restore(cpr_zip, **kwargs): # The comp is just an Image, while the dirty and psf are actually (Image, weight) tuples. return restore_cube(cpr_zip[0], cpr_zip[1][0], cpr_zip[2][0], **kwargs)
def ical(block_vis: BlockVisibility, model: Image, components=None, context='2d', controls=None, **kwargs): """ Post observation image, deconvolve, and self-calibrate :param vis: :param model: Model image :param components: Initial components :param context: Imaging context :param controls: Calibration controls dictionary :return: model, residual, restored """ nmajor = get_parameter(kwargs, 'nmajor', 5) log.info("ical: Performing %d major cycles" % nmajor) do_selfcal = get_parameter(kwargs, "do_selfcal", False) if controls is None: controls = create_calibration_controls(**kwargs) # The model is added to each major cycle and then the visibilities are # calculated from the full model vis = convert_blockvisibility_to_visibility(block_vis) block_vispred = copy_visibility(block_vis, zero=True) vispred = convert_blockvisibility_to_visibility(block_vispred) vispred.data['vis'][...] = 0.0 visres = copy_visibility(vispred) vispred = predict_function(vispred, model, context=context, **kwargs) if components is not None: vispred = predict_skycomponent_visibility(vispred, components) if do_selfcal: vis, gaintables = calibrate_function(vis, vispred, 'TGB', controls, iteration=-1) visres.data['vis'] = vis.data['vis'] - vispred.data['vis'] dirty, sumwt = invert_function(visres, model, context=context, **kwargs) log.info("Maximum in residual image is %.6f" % (numpy.max(numpy.abs(dirty.data)))) psf, sumwt = invert_function(visres, model, dopsf=True, context=context, **kwargs) thresh = get_parameter(kwargs, "threshold", 0.0) for i in range(nmajor): log.info("ical: Start of major cycle %d of %d" % (i, nmajor)) cc, res = deconvolve_cube(dirty, psf, **kwargs) model.data += cc.data vispred.data['vis'][...] = 0.0 vispred = predict_function(vispred, model, context=context, **kwargs) if do_selfcal: vis, gaintables = calibrate_function(vis, vispred, 'TGB', controls, iteration=i) visres.data['vis'] = vis.data['vis'] - vispred.data['vis'] dirty, sumwt = invert_function(visres, model, context=context, **kwargs) log.info("Maximum in residual image is %s" % (numpy.max(numpy.abs(dirty.data)))) if numpy.abs(dirty.data).max() < 1.1 * thresh: log.info("ical: Reached stopping threshold %.6f Jy" % thresh) break log.info("ical: End of major cycle") log.info("ical: End of major cycles") restored = restore_cube(model, psf, dirty, **kwargs) return model, dirty, restored
vis = convert_to_stokes(vis, POLDEF) # Image I, Q, U, V, per channel: dirty, psf = wstack(vis, npixel_advice, cell_advice, channel, RESULTS_DIR) # Deconvolve (using complex Hogbom clean): comp, residual = deconvolve_cube_complex(dirty, psf, niter=10000, threshold=0.001, \ fracthresh=0.001, window_shape='', gain=0.1, \ algorithm='hogbom-complex') # Convert resolution (FWHM in arcmin) to a psfwidth (standard deviation in pixels): clean_res = (((FORCE_RESOLUTION / 2.35482004503) / 60.0) * np.pi / 180.0) / cell_advice # Create the restored image: restored = restore_cube(comp, psf, residual, psfwidth=clean_res) # Save the images to disk: if SAVE_RESIDUAL_IMAGES: export_image_to_fits( comp, '%s/imaging_comp_WStack-%s.fits' % (RESULTS_DIR, channel)) export_image_to_fits( residual, '%s/imaging_residual_WStack-%s.fits' % (RESULTS_DIR, channel)) export_image_to_fits( restored, '%s/imaging_clean_WStack-%s.fits' % (RESULTS_DIR, channel)) # Rotation Measure (RM) Synthesis # ------------------------------------------------------ # Load in the FITS images: IMAGECUBE, FREQUENCY, WEIGHTS = load_im_data(RESULTS_DIR)