def test_residual_image_bag(self): context = 'wstack' vis_slices = {'wstack': 101} dirty_bag = invert_bag(self.vis_bag, self.empty_model_bag, dopsf=False, context=context, normalize=True, vis_slices=vis_slices[context]) psf_bag = invert_bag(self.vis_bag, self.empty_model_bag, dopsf=True, context=context, normalize=True, vis_slices=vis_slices[context]) dirty_bag = reify(dirty_bag) psf_bag = reify(psf_bag) model_bag = deconvolve_bag(dirty_bag, psf_bag, self.empty_model_bag, niter=1000, gain=0.1, algorithm='msclean', threshold=0.01, window_shape=None) residual_bag = residual_image_bag(self.vis_bag, model_bag, context=context, vis_slices=vis_slices[context]) final = residual_bag.compute()[0]['image'][0] export_image_to_fits( final, '%s/test_bags_%s_residual.fits' % (self.dir, context)) qa = qa_image(final, context=context) assert qa.data['max'] < 15.0, str(qa)
def test_residual_image_bag(self): context = 'wstack' vis_slices = {'2d': None, 'timeslice': 'auto', 'wstack': 101} dirty_bag = invert_bag(self.vis_bag, self.model, dopsf=False, context=context, normalize=True, vis_slices=vis_slices[context]) psf_bag = invert_bag(self.vis_bag, self.model, dopsf=True, context=context, normalize=True, vis_slices=vis_slices[context]) model_bag = deconvolve_bag(dirty_bag, psf_bag, niter=1000, gain=0.1, algorithm='msclean', threshold=0.01, window_shape=None) residual_bag = residual_image_bag(self.vis_bag, model_bag, context=context, vis_slices=vis_slices[context]) final = list(residual_bag)[0][0] export_image_to_fits( final, '%s/test_bag_%s_residual.fits' % (self.results_dir, context)) qa = qa_image(final, context=context) assert qa.data['max'] < 15.0, str(qa)
def test_residual_image_bag_model(self): cvis_bag = self.vis_bag.map(coalesce_visibility) context = 'wstack' vis_slices = {'2d': None, 'timeslice': 'auto', 'wstack': 101} residual_bag = residual_image_bag(cvis_bag, self.model_bag, context=context, vis_slices=vis_slices[context]) final = list(residual_bag)[0][0] export_image_to_fits(final, '%s/test_bag_%s_residual_image_bag.fits' % (self.results_dir, context)) qa = qa_image(final, context=context) assert qa.data['max'] < 2.3, str(qa)
def test_residual_image_bag_model(self): context = 'wstack' vis_slices = {'wstack': 101} residual_bag = residual_image_bag(self.vis_bag, self.model_bag, context=context, vis_slices=vis_slices[context]) final = residual_bag.compute()[0]['image'][0] export_image_to_fits( final, '%s/test_bags_%s_residual_image_bag.fits' % (self.dir, context)) qa = qa_image(final, context=context) assert qa.data['max'] < 2.3, str(qa)
def test_restore_bag(self): peaks = {'wstack': 98.8113067286} vis_slices = {'wstack': 101} context = 'wstack' dirty_bag = invert_bag(self.vis_bag, self.model_bag, dopsf=False, context=context, normalize=True, vis_slices=vis_slices[context]) psf_bag = invert_bag(self.vis_bag, self.model_bag, dopsf=True, context=context, normalize=True, vis_slices=vis_slices[context]) dirty_bag = reify(dirty_bag) psf_bag = reify(psf_bag) model_bag = deconvolve_bag(dirty_bag, psf_bag, self.empty_model_bag, niter=1000, gain=0.7, algorithm='msclean', threshold=0.01, window_shape=None) model_bag = reify(model_bag) res_image_bag = residual_image_bag(self.vis_bag, model_bag, context=context, vis_slices=vis_slices[context]) res_image_bag = reify(res_image_bag) residual = res_image_bag.compute()[0]['image'][0] export_image_to_fits( residual, '%s/test_bags_%s_residual.fits' % (self.dir, context)) final_bag = restore_bag(model_bag, psf_bag, res_image_bag) final = final_bag.compute()[0] qa = qa_image(final, context=context) export_image_to_fits( final, '%s/test_bags_%s_restored.fits' % (self.dir, context)) assert numpy.abs(qa.data['max'] - peaks[context]) < 0.1, str(qa)
def test_restore_bag(self): cvis_bag = self.vis_bag.map(coalesce_visibility) peaks = {'timeslice': 103.55068395, 'wstack': 98.790503433} vis_slices = {'2d': None, 'timeslice': 'auto', 'wstack': 101} for context in ['timeslice', 'wstack']: dirty_bag = invert_bag(self.vis_bag, self.model_bag, dopsf=False, context=context, normalize=True, vis_slices=vis_slices[context]) psf_bag = invert_bag(self.vis_bag, self.model_bag, dopsf=True, context=context, normalize=True, vis_slices=vis_slices[context]) model_bag = deconvolve_bag(dirty_bag, psf_bag, self.empty_model_bag, niter=1000, gain=0.7, algorithm='msclean', threshold=0.01, window_shape=None) residual_bag = residual_image_bag(cvis_bag, model_bag, context=context, vis_slices=vis_slices[context]) residual = list(residual_bag)[0][0] export_image_to_fits(residual, '%s/test_bag_%s_residual.fits' % (self.results_dir, context)) final_bag = restore_bag(model_bag, psf_bag, residual_bag) final = list(final_bag)[0] qa = qa_image(final, context=context) export_image_to_fits(final, '%s/test_bag_%s_restored.fits' % (self.results_dir, context)) assert numpy.abs(qa.data['max'] - peaks[context]) < 1.0e-2, str(qa)
def ical_pipeline_bag(block_vis_bag, model_bag, context='2d', first_selfcal=None, **kwargs) -> bag: """Create bag for ICAL pipeline :param vis_bag: :param model_bag: :param context: Imaging context :param first_selfcal: First cycle for phase only selfcal :param kwargs: Parameters for functions in bags :return: """ assert isinstance(block_vis_bag, bag.Bag), block_vis_bag assert isinstance(model_bag, bag.Bag), model_bag vis_bag = block_vis_bag.map(map_record, convert_blockvisibility_to_visibility) psf_bag = invert_bag(vis_bag, model_bag, context=context, dopsf=True, **kwargs) psf_bag = reify(psf_bag) # Make the predicted visibilities, selfcalibrate against it correcting the gains, then # form the residual visibility, then make the residual image model_vis_bag = reify( predict_bag(vis_bag, model_bag, context=context, **kwargs)) if first_selfcal is not None and first_selfcal == 0: vis_bag = reify( selfcal_record(block_vis_bag, model_vis_bag=model_vis_bag, **kwargs)) res_vis_bag = reify(residual_vis_bag(vis_bag, model_vis_bag)) res_bag = invert_bag(res_vis_bag, model_bag, context=context, dopsf=False, **kwargs) res_bag = reify(res_bag) deconvolve_model_bag = reify( deconvolve_bag(res_bag, psf_bag, model_bag, **kwargs)) nmajor = get_parameter(kwargs, "nmajor", 5) if nmajor > 1: for cycle in range(nmajor): model_vis_bag = reify( predict_bag(vis_bag, deconvolve_model_bag, context=context, **kwargs)) if first_selfcal is not None and cycle >= first_selfcal: vis_bag = reify( selfcal_record(block_vis_bag, model_vis_bag=model_vis_bag, **kwargs)) res_vis_bag = reify(residual_vis_bag(vis_bag, model_vis_bag)) res_bag = invert_bag(res_vis_bag, model_bag, context=context, dopsf=False, **kwargs) res_bag = reify(res_bag) deconvolve_model_bag = reify( deconvolve_bag(res_bag, psf_bag, deconvolve_model_bag, **kwargs)) res_bag = residual_image_bag(vis_bag, deconvolve_model_bag, context=context, **kwargs) res_bag = reify(res_bag) deconvolve_model_bag = reify(deconvolve_model_bag) rest_bag = restore_bag(deconvolve_model_bag, psf_bag, res_bag, **kwargs) rest_bag = reify(rest_bag) return bag.from_sequence([deconvolve_model_bag, res_bag, rest_bag])