def deconvolve_subimage(dirty, psf, model): assert isinstance(dirty, Image) assert isinstance(psf, Image) assert isinstance(model, Image) comp = deconvolve_cube(dirty, psf, **kwargs) comp[0].data += model.data return comp[0]
def make_cube_and_deconvolve(dirty, psf, model): dirty_cube = image_gather_channels(remove_sumwt(dirty), subimages=nchan) psf_cube = image_gather_channels(remove_sumwt(psf), subimages=nchan) model_cube = image_gather_channels(model, subimages=nchan) result = deconvolve_cube(dirty_cube, psf_cube, **kwargs) result[0].data += model_cube.data return image_scatter_channels(result[0], nchan)
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_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_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_msmfsclean_linear_noscales(self): self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=self.niter, gain=0.1, algorithm='msmfsclean', scales=[0], threshold=0.01, nmoments=2, findpeak='ARL', fractional_threshold=0.01, window=self.innerquarter) export_image_to_fits(self.comp, "%s/test_deconvolve_msmfsclean_linear_noscales-comp.fits" % self.dir) export_image_to_fits(self.residual, "%s/test_deconvolve_msmfsclean_linear_noscales-residual.fits" % self.dir) self.cmodel = restore_cube(self.comp, self.psf, self.residual) export_image_to_fits(self.cmodel, "%s/test_deconvolve_msmfsclean_linear_noscales-clean.fits" % self.dir) assert numpy.max(self.residual.data) < 3.0
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 deconvolve_by_facet_kernel(ixs, **kwargs): print(ixs) (dirty, psf), model = ixs id = dirty.facet_id assert isinstance(dirty, Image) assert isinstance(psf, Image) assert isinstance(model, Image) comp = deconvolve_cube(dirty, psf, **kwargs) comp[0].data += model.data comp[0].facet_id = id return comp[0]
def solve_image(vis: Visibility, model: Image, components=None, predict=predict_2d, invert=invert_2d, **kwargs) -> (Visibility, Image, Image): """Solve for image using deconvolve_cube and specified predict, invert This is the same as a majorcycle/minorcycle algorithm. The components are removed prior to deconvolution. See also arguments for predict, invert, deconvolve_cube functions.2d :param vis: :param model: Model image :param predict: Predict function e.g. predict_2d, predict_wstack :param invert: Invert function e.g. invert_2d, invert_wstack :return: Visibility, model """ nmajor = get_parameter(kwargs, 'nmajor', 5) log.info("solve_image: Performing %d major cycles" % nmajor) # The model is added to each major cycle and then the visibilities are # calculated from the full model vispred = copy_visibility(vis) visres = copy_visibility(vis) vispred = predict(vispred, model, **kwargs) if components is not None: vispred = predict_skycomponent_visibility(vispred, components) visres.data['vis'] = vis.data['vis'] - vispred.data['vis'] dirty, sumwt = invert(visres, model, **kwargs) psf, sumwt = invert(visres, model, dopsf=True, **kwargs) thresh = get_parameter(kwargs, "threshold", 0.0) for i in range(nmajor): log.info("solve_image: Start of major cycle %d" % i) cc, res = deconvolve_cube(dirty, psf, **kwargs) res = None model.data += cc.data vispred = predict(vispred, model, **kwargs) visres.data['vis'] = vis.data['vis'] - vispred.data['vis'] dirty, sumwt = invert(visres, model, **kwargs) if numpy.abs(dirty.data).max() < 1.1 * thresh: log.info("Reached stopping threshold %.6f Jy" % thresh) break log.info("solve_image: End of major cycle") log.info("solve_image: End of major cycles") return visres, model, dirty
def create_deconvolve_graph(sc, dirty_graph, psf_graph, model_graph, **kwargs): def make_cube(img_graph, nchan, has_sumwt=True, ret_idx=False): imgs = img_graph.collect() l = [Image() for i in range(nchan)] idx = [() for i in range(nchan)] for tup in imgs: if has_sumwt: l[tup[0][2]] = tup[1][0] else: l[tup[0][2]] = tup[1] if ret_idx: idx[tup[0][2]] = tup[0] if ret_idx: return l, idx else: return l nchan = get_parameter(kwargs, "nchan", 1) algorithm = get_parameter(kwargs, "algorithm", "mmclean") if algorithm == "mmclean" and nchan > 1: im, idx = make_cube(dirty_graph, nchan, ret_idx=True) dirty_cube = image_gather_channels(im, subimages=nchan) psf_cube = image_gather_channels(make_cube(psf_graph, nchan), subimages=nchan) model_cube = image_gather_channels(make_cube(model_graph, nchan, has_sumwt=False), subimages=nchan) result = deconvolve_cube(dirty_cube, psf_cube, **kwargs) result[0].data += model_cube.data ret_img = [] pl = result[0].polarisation_frame nchan, npol, ny, nx = result[0].shape for i in range(nchan): wcs = result[0].wcs.deepcopy() wcs.wcs.crpix[3] -= i ret_img.append( create_image_from_array( result[0].data[i, ...].reshape(1, npol, ny, nx), wcs, pl)) return sc.parallelize([i for i in range(nchan) ]).map(lambda ix: (idx[ix], ret_img[ix])) else: return deconvolve_handle(dirty_graph, psf_graph, model_graph, **kwargs)
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 deconvolve_kernel(ixs, **kwargs): (dirty, psf), model = ixs result = deconvolve_cube(dirty[0], psf[0], **kwargs) result[0].data += model.data return result[0]
def deconvolve_subimage(dirty, psf, **kwargs): assert isinstance(dirty, Image) assert isinstance(psf, Image) result = deconvolve_cube(dirty, psf, **kwargs) return result[0]
def deconvolve_subimage(dirty, psf): assert isinstance(dirty, Image) assert isinstance(psf, Image) comp = deconvolve_cube(dirty, psf, **kwargs) return comp[0]
def deconvolve(dp_zip, **kwargs): # The dirty and psf are actually (Image, weight) tuples. result = deconvolve_cube(dp_zip[0][0], dp_zip[1][0], **kwargs) return result[0]
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
def deconvolve(dirty, psf, model, **kwargs): result = deconvolve_cube(dirty, psf, **kwargs) result[0].data += model.data return result[0]
def deconvolve_facet(dirty, psf, **kwargs): assert type(dirty) == Image assert type(psf) == Image result = deconvolve_cube(dirty, psf, **kwargs) return result[0]