def test_readwriteskymodel_no_image(self):
        vis = create_blockvisibility(
            self.midcore,
            self.times,
            self.frequency,
            channel_bandwidth=self.channel_bandwidth,
            phasecentre=self.phasecentre,
            polarisation_frame=PolarisationFrame("linear"),
            weight=1.0)
        gt = create_gaintable_from_blockvisibility(vis, timeslice='auto')
        gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1)
        sm = SkyModel(components=[self.comp], gaintable=gt)

        config = {
            "buffer": {
                "directory": self.dir
            },
            "skymodel": {
                "name": "test_bufferskymodel.hdf",
                "data_model": "SkyModel"
            }
        }
        bdm = BufferSkyModel(config["buffer"], config["skymodel"], sm)
        bdm.sync()
        new_bdm = BufferSkyModel(config["buffer"], config["skymodel"])
        new_bdm.sync()
        newsm = bdm.memory_data_model

        assert newsm.components[0].flux.shape == self.comp.flux.shape
        assert newsm.gaintable.data.shape == gt.data.shape
 def output_skymodel(model_list, comp_list):
     if conf['create_skymodel']["fill_image"]:
         skymodel = SkyModel(images=model_list, components=[])
     else:
         skymodel = SkyModel(images=[], components=comp_list)
     
     return BufferSkyModel(conf["buffer"], conf["outputs"]["skymodel"], skymodel).sync()
    def test_readwriteimage_assertion(self):
        im = create_test_image()

        with self.assertRaises(AssertionError):
            config = {
                "buffer": {
                    "directory": self.dir
                },
                "image": {
                    "name": "test_bufferskyimage.hdf",
                    "data_model": "Image"
                }
            }
            bdm = BufferImage(config["buffer"], config["image"], im)
            bdm.sync()
            new_bdm = BufferSkyModel(config["buffer"], config["image"])
            new_bdm.sync()
            newim = bdm.memory_data_model
 def output_images(result):
     BufferSkyModel(conf["buffer"], conf['outputs']['skymodel'], SkyModel(images=result[0])).sync()
 
     deconvolved = image_gather_channels(result[0])
     residual = image_gather_channels(remove_sumwt(result[1]))
     restored = image_gather_channels(result[2])
 
     BufferImage(conf["buffer"], conf['outputs']['deconvolved'], deconvolved).sync()
     BufferImage(conf["buffer"], conf['outputs']['residual'], residual).sync()
     BufferImage(conf["buffer"], conf['outputs']['restored'], restored).sync()
 
     return result
def predict_vislist_wrapper(conf):
    """Wrapper for prediction

    :param conf: Configuration from JSON file
    :return:
    """
    vis_list = BufferBlockVisibility(conf["buffer"], conf['inputs']['vis_list']).memory_data_model
    skymodel = BufferSkyModel(conf["buffer"], conf["inputs"]["skymodel"]).memory_data_model
    
    flux_limit = conf['primary_beam']['flux_limit']
    
    if conf["primary_beam"]["apply"]:
        def apply_pb_image(vt, model):
            telescope = vt.configuration.name
            pb = create_pb(model, telescope)
            model.data *= pb.data
            return model
        
        def apply_pb_comp(vt, model, comp):
            telescope = vt.configuration.name
            pb = create_pb(model, telescope)
            return apply_beam_to_skycomponent(comp, pb, flux_limit)
        
        image_list = [arlexecute.execute(apply_pb_image, nout=1)(v, skymodel.images[i]) for i, v in enumerate(vis_list)]
        if len(skymodel.components) > 1:
            component_list = [arlexecute.execute(apply_pb_comp, nout=1)(v, skymodel.images[i], skymodel.components)
                              for i, v in enumerate(vis_list)]
        else:
            component_list = []
    else:
        image_list = [skymodel.images[0] for v in vis_list]
        component_list = skymodel.components
    
    future_vis_list = arlexecute.scatter(vis_list)
    predicted_vis_list = [arlexecute.execute(predict_skycomponent_visibility)(v, component_list)
                          for v in future_vis_list]
    predicted_vis_list = predict_workflow(predicted_vis_list, image_list,
                                           context=conf['imaging']['context'],
                                           vis_slices=conf['imaging']['vis_slices'])
    
    def output_vislist(v):
        bdm = BufferBlockVisibility(conf["buffer"], conf["outputs"]["vis_list"], v)
        bdm.sync()
    
    return arlexecute.execute(output_vislist)(predicted_vis_list)
    def test_readwriteskymodel(self):
        im = create_test_image()
        sm = SkyModel(components=[self.comp], images=[im, im])

        config = {
            "buffer": {
                "directory": self.dir
            },
            "skymodel": {
                "name": "test_bufferskymodel.hdf",
                "data_model": "SkyModel"
            }
        }
        bdm = BufferSkyModel(config["buffer"], config["skymodel"], sm)
        bdm.sync()
        new_bdm = BufferSkyModel(config["buffer"], config["skymodel"])
        new_bdm.sync()
        newsm = bdm.memory_data_model

        assert newsm.components[0].flux.shape == self.comp.flux.shape
        assert newsm.images[0].data.shape == im.data.shape
        assert numpy.max(numpy.abs(newsm.images[0].data - im.data)) < 1e-15