workflows/arlexecute/imaging/imaging_arlexecute.py
def invert_list_arlexecute_workflow(vis_list, template_model_imagelist, context, dopsf=False, normalize=True,
                                    facets=1, vis_slices=1, gcfcf=None, **kwargs):
    """ Sum results from invert, iterating over the scattered image and vis_list

    :param vis_list:
    :param template_model_imagelist: Model used to determine image parameters
    :param dopsf: Make the PSF instead of the dirty image
    :param facets: Number of facets
    :param normalize: Normalize by sumwt
    :param vis_slices: Number of slices
    :param context: Imaging context
    :param gcfcg: tuple containing grid correction and convolution function
    :param kwargs: Parameters for functions in components
    :return: List of (image, sumwt) tuple
   """
    
    # Use serial invert for each element of the visibility list. This means that e.g. iteration
    # through w-planes or timeslices is done sequentially thus not incurring the memory cost
    # of doing all at once.
    if get_parameter(kwargs, "use_serial_invert", False):
        from workflows.serial.imaging.imaging_serial import invert_list_serial_workflow
        return [arlexecute.execute(invert_list_serial_workflow, nout=1) \
                    (vis_list=[vis_list[i]], template_model_imagelist=[template_model_imagelist[i]],
                     context=context, dopsf=dopsf, normalize=normalize, vis_slices=vis_slices,
                     facets=facets, gcfcf=gcfcf, **kwargs)[0]
                for i, _ in enumerate(vis_list)]
    
    if not isinstance(template_model_imagelist, collections.Iterable):
        template_model_imagelist = [template_model_imagelist]
    
    c = imaging_context(context)
    vis_iter = c['vis_iterator']
    invert = c['invert']
    
    if facets % 2 == 0 or facets == 1:
        actual_number_facets = facets
    else:
        actual_number_facets = max(1, (facets - 1))
    
    def gather_image_iteration_results(results, template_model):
        result = create_empty_image_like(template_model)
        i = 0
        sumwt = numpy.zeros([template_model.nchan, template_model.npol])
        for dpatch in image_scatter_facets(result, facets=facets):
            assert i < len(results), "Too few results in gather_image_iteration_results"
            if results[i] is not None:
                assert len(results[i]) == 2, results[i]
                dpatch.data[...] = results[i][0].data[...]
                sumwt += results[i][1]
                i += 1
        return result, sumwt
    
    def invert_ignore_none(vis, model, gg):
        if vis is not None:
            return invert(vis, model, context=context, dopsf=dopsf, normalize=normalize,
                          gcfcf=gg, **kwargs)
        else:
            return create_empty_image_like(model), numpy.zeros([model.nchan, model.npol])
    
    # If we are doing facets, we need to create the gcf for each image
    if gcfcf is None and facets == 1:
        gcfcf = [arlexecute.execute(create_pswf_convolutionfunction)(template_model_imagelist[0])]
    
    # Loop over all vis_lists independently
    results_vislist = list()
    if facets == 1:
        for ivis, sub_vis_list in enumerate(vis_list):
            if len(gcfcf) > 1:
                g = gcfcf[ivis]
            else:
                g = gcfcf[0]
            # Create the graph to divide the visibility into slices. This is by copy.
            sub_sub_vis_lists = arlexecute.execute(visibility_scatter, nout=vis_slices)\
                (sub_vis_list, vis_iter, vis_slices=vis_slices)
            
            # Iterate within each sub_sub_vis_list
            vis_results = list()
            for sub_sub_vis_list in sub_sub_vis_lists:
                vis_results.append(arlexecute.execute(invert_ignore_none, pure=True)
                                   (sub_sub_vis_list, template_model_imagelist[ivis], g))
            results_vislist.append(sum_invert_results_arlexecute(vis_results))

        result = results_vislist
    else:
        for ivis, sub_vis_list in enumerate(vis_list):
            # Create the graph to divide an image into facets. This is by reference.
            facet_lists = arlexecute.execute(image_scatter_facets, nout=actual_number_facets ** 2)(
                template_model_imagelist[
                    ivis],
                facets=facets)
            # Create the graph to divide the visibility into slices. This is by copy.
            sub_sub_vis_lists = arlexecute.execute(visibility_scatter, nout=vis_slices)\
                (sub_vis_list, vis_iter, vis_slices=vis_slices)
            
            # Iterate within each vis_list
            vis_results = list()
            for sub_sub_vis_list in sub_sub_vis_lists:
                facet_vis_results = list()
                for facet_list in facet_lists:
                    facet_vis_results.append(
                        arlexecute.execute(invert_ignore_none, pure=True)(sub_sub_vis_list, facet_list, None))
                vis_results.append(arlexecute.execute(gather_image_iteration_results, nout=1)
                                   (facet_vis_results, template_model_imagelist[ivis]))
            results_vislist.append(sum_invert_results_arlexecute(vis_results))
        
        result = results_vislist
    return arlexecute.optimize(result)
 Sum results from invert, iterating over the scattered image and vis_list

    :param vis_list:
    :param template_model_imagelist: Model used to determine image parameters
    :param dopsf: Make the PSF instead of the dirty image
    :param facets: Number of facets
    :param normalize: Normalize by sumwt
    :param vis_slices: Number of slices
    :param context: Imaging context
    :param gcfcg: tuple containing grid correction and convolution function
    :param kwargs: Parameters for functions in components
    :return: List of (image, sumwt) tuple
   
Sum results from invert, iterating over the scattered image and vis_list
Sum results from invert iterating over the scattered image and vis_list
def invert_list_arlexecute_workflow(vis_list, template_model_imagelist, context, dopsf=False, normalize=True,
                                    facets=1, vis_slices=1, gcfcf=None, **kwargs):
    if get_parameter(kwargs, "use_serial_invert", False):
        from workflows.serial.imaging.imaging_serial import invert_list_serial_workflow
        return [arlexecute.execute(invert_list_serial_workflow, nout=1) \
                    (vis_list=[vis_list[i]], template_model_imagelist=[template_model_imagelist[i]],
                     context=context, dopsf=dopsf, normalize=normalize, vis_slices=vis_slices,
                     facets=facets, gcfcf=gcfcf, **kwargs)[0]
                for i, _ in enumerate(vis_list)]
    if not isinstance(template_model_imagelist, collections.Iterable):
        template_model_imagelist = [template_model_imagelist]
    c = imaging_context(context)
    vis_iter = c['vis_iterator']
    invert = c['invert']
    if facets % 2 == 0 or facets == 1:
        actual_number_facets = facets
    else:
        actual_number_facets = max(1, (facets - 1))
    def gather_image_iteration_results(results, template_model):
        result = create_empty_image_like(template_model)
        i = 0
        sumwt = numpy.zeros([template_model.nchan, template_model.npol])
        for dpatch in image_scatter_facets(result, facets=facets):
            assert i < len(results), "Too few results in gather_image_iteration_results"
            if results[i] is not None:
                assert len(results[i]) == 2, results[i]
                dpatch.data[...] = results[i][0].data[...]
                sumwt += results[i][1]
                i += 1
        return result, sumwt
    def invert_ignore_none(vis, model, gg):
        if vis is not None:
            return invert(vis, model, context=context, dopsf=dopsf, normalize=normalize,
                          gcfcf=gg, **kwargs)
        else:
            return create_empty_image_like(model), numpy.zeros([model.nchan, model.npol])
    if gcfcf is None and facets == 1:
        gcfcf = [arlexecute.execute(create_pswf_convolutionfunction)(template_model_imagelist[0])]
    results_vislist = list()
    if facets == 1:
        for ivis, sub_vis_list in enumerate(vis_list):
            if len(gcfcf) > 1:
                g = gcfcf[ivis]
            else:
                g = gcfcf[0]
            sub_sub_vis_lists = arlexecute.execute(visibility_scatter, nout=vis_slices)\
                (sub_vis_list, vis_iter, vis_slices=vis_slices)
            vis_results = list()
            for sub_sub_vis_list in sub_sub_vis_lists:
                vis_results.append(arlexecute.execute(invert_ignore_none, pure=True)
                                   (sub_sub_vis_list, template_model_imagelist[ivis], g))
            results_vislist.append(sum_invert_results_arlexecute(vis_results))
        result = results_vislist
    else:
        for ivis, sub_vis_list in enumerate(vis_list):
            facet_lists = arlexecute.execute(image_scatter_facets, nout=actual_number_facets ** 2)(
                template_model_imagelist[
                    ivis],
                facets=facets)
            sub_sub_vis_lists = arlexecute.execute(visibility_scatter, nout=vis_slices)\
                (sub_vis_list, vis_iter, vis_slices=vis_slices)
            vis_results = list()
            for sub_sub_vis_list in sub_sub_vis_lists:
                facet_vis_results = list()
                for facet_list in facet_lists:
                    facet_vis_results.append(
                        arlexecute.execute(invert_ignore_none, pure=True)(sub_sub_vis_list, facet_list, None))
                vis_results.append(arlexecute.execute(gather_image_iteration_results, nout=1)
                                   (facet_vis_results, template_model_imagelist[ivis]))
            results_vislist.append(sum_invert_results_arlexecute(vis_results))
        result = results_vislist
    return arlexecute.optimize(result)
def invert_list_arlexecute_workflow ( vis_list , template_model_imagelist , context , dopsf = False , normalize = True , facets = 1 , vis_slices = 1 , gcfcf = None , ** kwargs ) : if get_parameter ( kwargs , "use_serial_invert" , False ) : from workflows . serial . imaging . imaging_serial import invert_list_serial_workflow return [ arlexecute . execute ( invert_list_serial_workflow , nout = 1 ) ( vis_list = [ vis_list [ i ] ] , template_model_imagelist = [ template_model_imagelist [ i ] ] , context = context , dopsf = dopsf , normalize = normalize , vis_slices = vis_slices , facets = facets , gcfcf = gcfcf , ** kwargs ) [ 0 ] for i , _ in enumerate ( vis_list ) ] if not isinstance ( template_model_imagelist , collections . Iterable ) : template_model_imagelist = [ template_model_imagelist ] c = imaging_context ( context ) vis_iter = c [ 'vis_iterator' ] invert = c [ 'invert' ] if facets % 2 == 0 or facets == 1 : actual_number_facets = facets else : actual_number_facets = max ( 1 , ( facets - 1 ) ) def gather_image_iteration_results ( results , template_model ) : result = create_empty_image_like ( template_model ) i = 0 sumwt = numpy . zeros ( [ template_model . nchan , template_model . npol ] ) for dpatch in image_scatter_facets ( result , facets = facets ) : assert i < len ( results ) , "Too few results in gather_image_iteration_results" if results [ i ] is not None : assert len ( results [ i ] ) == 2 , results [ i ] dpatch . data [ ... ] = results [ i ] [ 0 ] . data [ ... ] sumwt += results [ i ] [ 1 ] i += 1 return result , sumwt def invert_ignore_none ( vis , model , gg ) : if vis is not None : return invert ( vis , model , context = context , dopsf = dopsf , normalize = normalize , gcfcf = gg , ** kwargs ) else : return create_empty_image_like ( model ) , numpy . zeros ( [ model . nchan , model . npol ] ) if gcfcf is None and facets == 1 : gcfcf = [ arlexecute . execute ( create_pswf_convolutionfunction ) ( template_model_imagelist [ 0 ] ) ] results_vislist = list ( ) if facets == 1 : for ivis , sub_vis_list in enumerate ( vis_list ) : if len ( gcfcf ) > 1 : g = gcfcf [ ivis ] else : g = gcfcf [ 0 ] sub_sub_vis_lists = arlexecute . execute ( visibility_scatter , nout = vis_slices ) ( sub_vis_list , vis_iter , vis_slices = vis_slices ) vis_results = list ( ) for sub_sub_vis_list in sub_sub_vis_lists : vis_results . append ( arlexecute . execute ( invert_ignore_none , pure = True ) ( sub_sub_vis_list , template_model_imagelist [ ivis ] , g ) ) results_vislist . append ( sum_invert_results_arlexecute ( vis_results ) ) result = results_vislist else : for ivis , sub_vis_list in enumerate ( vis_list ) : facet_lists = arlexecute . execute ( image_scatter_facets , nout = actual_number_facets ** 2 ) ( template_model_imagelist [ ivis ] , facets = facets ) sub_sub_vis_lists = arlexecute . execute ( visibility_scatter , nout = vis_slices ) ( sub_vis_list , vis_iter , vis_slices = vis_slices ) vis_results = list ( ) for sub_sub_vis_list in sub_sub_vis_lists : facet_vis_results = list ( ) for facet_list in facet_lists : facet_vis_results . append ( arlexecute . execute ( invert_ignore_none , pure = True ) ( sub_sub_vis_list , facet_list , None ) ) vis_results . append ( arlexecute . execute ( gather_image_iteration_results , nout = 1 ) ( facet_vis_results , template_model_imagelist [ ivis ] ) ) results_vislist . append ( sum_invert_results_arlexecute ( vis_results ) ) result = results_vislist return arlexecute . optimize ( result )
Sum results from invert, iterating over the scattered image and vis_list
Sum results from invert iterating over the scattered image and vis_list
""" Sum results from invert, iterating over the scattered image and vis_list

    :param vis_list:
    :param template_model_imagelist: Model used to determine image parameters
    :param dopsf: Make the PSF instead of the dirty image
    :param facets: Number of facets
    :param normalize: Normalize by sumwt
    :param vis_slices: Number of slices
    :param context: Imaging context
    :param gcfcg: tuple containing grid correction and convolution function
    :param kwargs: Parameters for functions in components
    :return: List of (image, sumwt) tuple
   """ # Use serial invert for each element of the visibility list. This means that e.g. iteration # through w-planes or timeslices is done sequentially thus not incurring the memory cost # of doing all at once. # If we are doing facets, we need to create the gcf for each image # Loop over all vis_lists independently # Create the graph to divide the visibility into slices. This is by copy. # Iterate within each sub_sub_vis_list # Create the graph to divide an image into facets. This is by reference. # Create the graph to divide the visibility into slices. This is by copy. # Iterate within each vis_list
List of (image, sumwt) tuple
List of ( image sumwt ) tuple
vis_list
None
template_model_imagelist
Model used to determine image parameters
Model used to determine image parameters
context
None
dopsf
Make the PSF instead of the dirty image
Make the PSF instead of the dirty image
normalize
Normalize by sumwt
Normalize by sumwt
facets
Number of facets
Number of facets
vis_slices
Number of slices
Number of slices
gcfcf
gcfcg
tuple containing grid correction and convolution function
tuple containing grid correction and convolution function
kwargs
Parameters for functions in components
Parameters for functions in components