workflows/serial/imaging/imaging_serial.py
def invert_list_serial_workflow(vis_list, template_model_imagelist, dopsf=False, normalize=True,
                                facets=1, vis_slices=1, context='2d', 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
   """
    
    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 = [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]
            # Iterate within each vis_list
            result_image = create_empty_image_like(template_model_imagelist[ivis])
            result_sumwt = numpy.zeros([template_model_imagelist[ivis].nchan,
                                        template_model_imagelist[ivis].npol])
            for rows in vis_iter(sub_vis_list, vis_slices):
                row_vis = create_visibility_from_rows(sub_vis_list, rows)
                result = invert_ignore_none(row_vis, template_model_imagelist[ivis], g)
                if result is not None:
                    result_image.data += result[1][:, :, numpy.newaxis, numpy.newaxis] * result[0].data
                    result_sumwt += result[1]
            result_image = normalize_sumwt(result_image, result_sumwt)
            results_vislist.append((result_image, result_sumwt))
    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 = image_scatter_facets(template_model_imagelist[ivis],
                                               facets=facets)
            # Create the graph to divide the visibility into slices. This is by copy.
            sub_sub_vis_lists = visibility_scatter(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(invert_ignore_none(sub_sub_vis_list, facet_list, None))
                vis_results.append(gather_image_iteration_results(facet_vis_results,
                                                                  template_model_imagelist[ivis]))
            results_vislist.append(sum_invert_results(vis_results))
    
    return results_vislist
 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_serial_workflow(vis_list, template_model_imagelist, dopsf=False, normalize=True,
                                facets=1, vis_slices=1, context='2d', gcfcf=None, **kwargs):
    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 = [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]
            result_image = create_empty_image_like(template_model_imagelist[ivis])
            result_sumwt = numpy.zeros([template_model_imagelist[ivis].nchan,
                                        template_model_imagelist[ivis].npol])
            for rows in vis_iter(sub_vis_list, vis_slices):
                row_vis = create_visibility_from_rows(sub_vis_list, rows)
                result = invert_ignore_none(row_vis, template_model_imagelist[ivis], g)
                if result is not None:
                    result_image.data += result[1][:, :, numpy.newaxis, numpy.newaxis] * result[0].data
                    result_sumwt += result[1]
            result_image = normalize_sumwt(result_image, result_sumwt)
            results_vislist.append((result_image, result_sumwt))
    else:
        for ivis, sub_vis_list in enumerate(vis_list):
            facet_lists = image_scatter_facets(template_model_imagelist[ivis],
                                               facets=facets)
            sub_sub_vis_lists = visibility_scatter(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(invert_ignore_none(sub_sub_vis_list, facet_list, None))
                vis_results.append(gather_image_iteration_results(facet_vis_results,
                                                                  template_model_imagelist[ivis]))
            results_vislist.append(sum_invert_results(vis_results))
    return results_vislist
def invert_list_serial_workflow ( vis_list , template_model_imagelist , dopsf = False , normalize = True , facets = 1 , vis_slices = 1 , context = '2d' , gcfcf = None , ** kwargs ) : 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 = [ 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 ] result_image = create_empty_image_like ( template_model_imagelist [ ivis ] ) result_sumwt = numpy . zeros ( [ template_model_imagelist [ ivis ] . nchan , template_model_imagelist [ ivis ] . npol ] ) for rows in vis_iter ( sub_vis_list , vis_slices ) : row_vis = create_visibility_from_rows ( sub_vis_list , rows ) result = invert_ignore_none ( row_vis , template_model_imagelist [ ivis ] , g ) if result is not None : result_image . data += result [ 1 ] [ : , : , numpy . newaxis , numpy . newaxis ] * result [ 0 ] . data result_sumwt += result [ 1 ] result_image = normalize_sumwt ( result_image , result_sumwt ) results_vislist . append ( ( result_image , result_sumwt ) ) else : for ivis , sub_vis_list in enumerate ( vis_list ) : facet_lists = image_scatter_facets ( template_model_imagelist [ ivis ] , facets = facets ) sub_sub_vis_lists = visibility_scatter ( 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 ( invert_ignore_none ( sub_sub_vis_list , facet_list , None ) ) vis_results . append ( gather_image_iteration_results ( facet_vis_results , template_model_imagelist [ ivis ] ) ) results_vislist . append ( sum_invert_results ( vis_results ) ) return results_vislist
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
   """ # If we are doing facets, we need to create the gcf for each image # Loop over all vis_lists independently # Iterate within each 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
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
context
None
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