def data_iter(dataset, vis_limit, vis_load, start_channel, stop_channel):
    """Wrapper around :py:meth:`katsdpimager.loader_core.LoaderBase.data_iter`
    that handles truncation to a number of visibilities specified on the
    command line.
    """
    N = vis_limit
    it = dataset.data_iter(start_channel, stop_channel, vis_load)
    for chunk in it:
        if N is not None:
            if N < len(chunk['uvw']):
                for key in ['uvw', 'baselines']:
                    if key in chunk:
                        chunk[key] = chunk[key][:N]
                for key in ['weights', 'vis']:
                    if key in chunk:
                        chunk[key] = chunk[key][:, :N]
                chunk['progress'] = chunk['total']
        yield chunk
        if N is not None:
            N -= len(chunk['uvw'])
            if N == 0:
                it.close()
                return
