workflows/arlexecute/pipelines/pipeline_mpccal_arlexecute.py
def mpccal_skymodel_list_arlexecute_workflow(visobs, model, theta_list, nmajor=10, context='2d',
                                             mpccal_progress=None, **kwargs):
    """Run MPC pipeline
    
    This runs the Model Partition Calibration algorithm. See SDP Memo 97 for more details,
    and see workflows/scripts/pipelines/mpccal_arlexecute_pipeline.py for an example of the application
    
    :param visobs: Visibility (not a list!)
    :param model: Model image
    :param theta_list: List of SkyModels i.e. theta in memo 97.
    :param nmajor: Number of major cycles
    :param context: Imaging context
    :param mpccal_progress: Function to display progress
    :return: Delayed tuple (theta_list, residual)
    """
    psf_obs = invert_list_arlexecute_workflow([visobs], [model], context=context, dopsf=True)

    result = arlexecute.execute((theta_list, model))
    
    for iteration in range(nmajor):
        # The E step of decoupling the data models
        vdatamodel_list = predict_skymodel_list_arlexecute_workflow(visobs, theta_list, context=context,
                                                                    docal=True, **kwargs)
        vdatamodel_list = crosssubtract_datamodels_skymodel_list_arlexecute_workflow(visobs, vdatamodel_list)
        
        # The M step: 1 - Update the models by deconvolving the residual image. The residual image must be calculated
        # from a difference of the dirty images from the data model, and the dirty images
        dirty_all_conv = convolve_skymodel_list_arlexecute_workflow(visobs, theta_list, context=context,
                                                                    docal=True, **kwargs)
        dirty_all_cal = invert_skymodel_list_arlexecute_workflow(vdatamodel_list, theta_list, context=context,
                                                                 docal=True, **kwargs)
        
        def diff_dirty(dcal, dconv):
            assert numpy.max(numpy.abs(dcal[0].data)) > 0.0, "before: dcal subimage is zero"
            dcal[0].data -= dconv[0].data
            assert numpy.max(numpy.abs(dcal[0].data)) > 0.0, "after: dcal subimage is zero"
            return dcal
        
        dirty_all_cal = [arlexecute.execute(diff_dirty, nout=1)(dirty_all_cal[i], dirty_all_conv[i])
                         for i in range(len(dirty_all_cal))]
        
        def make_residual(dcal, tl, it):
            res = create_empty_image_like(dcal[0][0])
            for i, d in enumerate(dcal):
                assert numpy.max(numpy.abs(d[0].data)) > 0.0, "Residual subimage is zero"
                if tl[i].mask is None:
                    res.data += d[0].data
                else:
                    assert numpy.max(numpy.abs(tl[i].mask.data)) > 0.0, "Mask image is zero"
                    res.data += d[0].data * tl[i].mask.data
                    
            assert numpy.max(numpy.abs(res.data)) > 0.0, "Residual image is zero"
            # import matplotlib.pyplot as plt
            # from processing_components.image.operations import show_image
            # show_image(res, title='MPCCAL residual image, iteration %d' % it)
            # plt.show()
            return res
        
        residual = arlexecute.execute(make_residual, nout=1)(dirty_all_cal, theta_list, iteration)
        
        deconvolved = deconvolve_list_arlexecute_workflow([(residual, 1.0)], [psf_obs[0]],
                                                          [model], **kwargs)
        
        # The M step: 2 - Update the gaintables
        vpredicted_list = predict_skymodel_list_arlexecute_workflow(visobs, theta_list, context=context,
                                                                    docal=True, **kwargs)
        vcalibrated_list, gaintable_list = calibrate_list_arlexecute_workflow(vdatamodel_list, vpredicted_list,
                                                                              calibration_context='T',
                                                                              iteration=iteration, global_solution=False,
                                                                              **kwargs)
        if mpccal_progress is not None:
            theta_list = arlexecute.execute(mpccal_progress, nout=len(theta_list))(residual, theta_list,
                                                                      gaintable_list, iteration)
        theta_list = \
            arlexecute.execute(update_skymodel_from_image, nout=len(theta_list))(theta_list, deconvolved[0])

        theta_list = arlexecute.execute(update_skymodel_from_gaintables, nout=len(theta_list))(theta_list,
                                                                                               gaintable_list,
                                                                                               calibration_context='T')

        result = arlexecute.execute((theta_list, residual))
    
    return result
Run MPC pipeline
    
    This runs the Model Partition Calibration algorithm. See SDP Memo 97 for more details,
    and see workflows/scripts/pipelines/mpccal_arlexecute_pipeline.py for an example of the application
    
    :param visobs: Visibility (not a list!)
    :param model: Model image
    :param theta_list: List of SkyModels i.e. theta in memo 97.
    :param nmajor: Number of major cycles
    :param context: Imaging context
    :param mpccal_progress: Function to display progress
    :return: Delayed tuple (theta_list, residual)
    
Run MPC pipeline
This runs the Model Partition Calibration algorithm. See SDP Memo 97 for more details,
and see workflows/scripts/pipelines/mpccal_arlexecute_pipeline.py for an example of the application
Run MPC pipeline This runs the Model Partition Calibration algorithm . See SDP Memo 97 for more details and see workflows / scripts / pipelines / mpccal_arlexecute_pipeline . py for an example of the application
def mpccal_skymodel_list_arlexecute_workflow(visobs, model, theta_list, nmajor=10, context='2d',
                                             mpccal_progress=None, **kwargs):
    psf_obs = invert_list_arlexecute_workflow([visobs], [model], context=context, dopsf=True)
    result = arlexecute.execute((theta_list, model))
    for iteration in range(nmajor):
        vdatamodel_list = predict_skymodel_list_arlexecute_workflow(visobs, theta_list, context=context,
                                                                    docal=True, **kwargs)
        vdatamodel_list = crosssubtract_datamodels_skymodel_list_arlexecute_workflow(visobs, vdatamodel_list)
        dirty_all_conv = convolve_skymodel_list_arlexecute_workflow(visobs, theta_list, context=context,
                                                                    docal=True, **kwargs)
        dirty_all_cal = invert_skymodel_list_arlexecute_workflow(vdatamodel_list, theta_list, context=context,
                                                                 docal=True, **kwargs)
        def diff_dirty(dcal, dconv):
            assert numpy.max(numpy.abs(dcal[0].data)) > 0.0, "before: dcal subimage is zero"
            dcal[0].data -= dconv[0].data
            assert numpy.max(numpy.abs(dcal[0].data)) > 0.0, "after: dcal subimage is zero"
            return dcal
        dirty_all_cal = [arlexecute.execute(diff_dirty, nout=1)(dirty_all_cal[i], dirty_all_conv[i])
                         for i in range(len(dirty_all_cal))]
        def make_residual(dcal, tl, it):
            res = create_empty_image_like(dcal[0][0])
            for i, d in enumerate(dcal):
                assert numpy.max(numpy.abs(d[0].data)) > 0.0, "Residual subimage is zero"
                if tl[i].mask is None:
                    res.data += d[0].data
                else:
                    assert numpy.max(numpy.abs(tl[i].mask.data)) > 0.0, "Mask image is zero"
                    res.data += d[0].data * tl[i].mask.data
            assert numpy.max(numpy.abs(res.data)) > 0.0, "Residual image is zero"
            return res
        residual = arlexecute.execute(make_residual, nout=1)(dirty_all_cal, theta_list, iteration)
        deconvolved = deconvolve_list_arlexecute_workflow([(residual, 1.0)], [psf_obs[0]],
                                                          [model], **kwargs)
        vpredicted_list = predict_skymodel_list_arlexecute_workflow(visobs, theta_list, context=context,
                                                                    docal=True, **kwargs)
        vcalibrated_list, gaintable_list = calibrate_list_arlexecute_workflow(vdatamodel_list, vpredicted_list,
                                                                              calibration_context='T',
                                                                              iteration=iteration, global_solution=False,
                                                                              **kwargs)
        if mpccal_progress is not None:
            theta_list = arlexecute.execute(mpccal_progress, nout=len(theta_list))(residual, theta_list,
                                                                      gaintable_list, iteration)
        theta_list = \
            arlexecute.execute(update_skymodel_from_image, nout=len(theta_list))(theta_list, deconvolved[0])
        theta_list = arlexecute.execute(update_skymodel_from_gaintables, nout=len(theta_list))(theta_list,
                                                                                               gaintable_list,
                                                                                               calibration_context='T')
        result = arlexecute.execute((theta_list, residual))
    return result
def mpccal_skymodel_list_arlexecute_workflow ( visobs , model , theta_list , nmajor = 10 , context = '2d' , mpccal_progress = None , ** kwargs ) : psf_obs = invert_list_arlexecute_workflow ( [ visobs ] , [ model ] , context = context , dopsf = True ) result = arlexecute . execute ( ( theta_list , model ) ) for iteration in range ( nmajor ) : vdatamodel_list = predict_skymodel_list_arlexecute_workflow ( visobs , theta_list , context = context , docal = True , ** kwargs ) vdatamodel_list = crosssubtract_datamodels_skymodel_list_arlexecute_workflow ( visobs , vdatamodel_list ) dirty_all_conv = convolve_skymodel_list_arlexecute_workflow ( visobs , theta_list , context = context , docal = True , ** kwargs ) dirty_all_cal = invert_skymodel_list_arlexecute_workflow ( vdatamodel_list , theta_list , context = context , docal = True , ** kwargs ) def diff_dirty ( dcal , dconv ) : assert numpy . max ( numpy . abs ( dcal [ 0 ] . data ) ) > 0.0 , "before: dcal subimage is zero" dcal [ 0 ] . data -= dconv [ 0 ] . data assert numpy . max ( numpy . abs ( dcal [ 0 ] . data ) ) > 0.0 , "after: dcal subimage is zero" return dcal dirty_all_cal = [ arlexecute . execute ( diff_dirty , nout = 1 ) ( dirty_all_cal [ i ] , dirty_all_conv [ i ] ) for i in range ( len ( dirty_all_cal ) ) ] def make_residual ( dcal , tl , it ) : res = create_empty_image_like ( dcal [ 0 ] [ 0 ] ) for i , d in enumerate ( dcal ) : assert numpy . max ( numpy . abs ( d [ 0 ] . data ) ) > 0.0 , "Residual subimage is zero" if tl [ i ] . mask is None : res . data += d [ 0 ] . data else : assert numpy . max ( numpy . abs ( tl [ i ] . mask . data ) ) > 0.0 , "Mask image is zero" res . data += d [ 0 ] . data * tl [ i ] . mask . data assert numpy . max ( numpy . abs ( res . data ) ) > 0.0 , "Residual image is zero" return res residual = arlexecute . execute ( make_residual , nout = 1 ) ( dirty_all_cal , theta_list , iteration ) deconvolved = deconvolve_list_arlexecute_workflow ( [ ( residual , 1.0 ) ] , [ psf_obs [ 0 ] ] , [ model ] , ** kwargs ) vpredicted_list = predict_skymodel_list_arlexecute_workflow ( visobs , theta_list , context = context , docal = True , ** kwargs ) vcalibrated_list , gaintable_list = calibrate_list_arlexecute_workflow ( vdatamodel_list , vpredicted_list , calibration_context = 'T' , iteration = iteration , global_solution = False , ** kwargs ) if mpccal_progress is not None : theta_list = arlexecute . execute ( mpccal_progress , nout = len ( theta_list ) ) ( residual , theta_list , gaintable_list , iteration ) theta_list = arlexecute . execute ( update_skymodel_from_image , nout = len ( theta_list ) ) ( theta_list , deconvolved [ 0 ] ) theta_list = arlexecute . execute ( update_skymodel_from_gaintables , nout = len ( theta_list ) ) ( theta_list , gaintable_list , calibration_context = 'T' ) result = arlexecute . execute ( ( theta_list , residual ) ) return result
Run MPC pipeline
This runs the Model Partition Calibration algorithm.
Run MPC pipeline This runs the Model Partition Calibration algorithm .
"""Run MPC pipeline
    
    This runs the Model Partition Calibration algorithm. See SDP Memo 97 for more details,
    and see workflows/scripts/pipelines/mpccal_arlexecute_pipeline.py for an example of the application
    
    :param visobs: Visibility (not a list!)
    :param model: Model image
    :param theta_list: List of SkyModels i.e. theta in memo 97.
    :param nmajor: Number of major cycles
    :param context: Imaging context
    :param mpccal_progress: Function to display progress
    :return: Delayed tuple (theta_list, residual)
    """ # The E step of decoupling the data models # The M step: 1 - Update the models by deconvolving the residual image. The residual image must be calculated # from a difference of the dirty images from the data model, and the dirty images # import matplotlib.pyplot as plt # from processing_components.image.operations import show_image # show_image(res, title='MPCCAL residual image, iteration %d' % it) # plt.show() # The M step: 2 - Update the gaintables
Delayed tuple (theta_list, residual)
Delayed tuple ( theta_list residual )
visobs
Visibility (not a list!)
Visibility ( not a list! )
model
None
theta_list
List of SkyModels i.e. theta in memo 97.
List of SkyModels i . e . theta in memo 97 .
nmajor
Number of major cycles
Number of major cycles
context
None
mpccal_progress
Function to display progress
Function to display progress