import numpy


def expandI(a):
    """
    Expands an array by one column, averaging the data to the middle columns and
    extrapolating for the first and last columns. Needed for shifting coordinates
    from centers to corners.
    """
    nj, ni = a.shape
    b = numpy.zeros((nj, ni + 1))
    b[:, 1:-1] = 0.5 * (a[:, :-1] + a[:, 1:])
    b[:, 0] = a[:, 0] + 0.5 * (a[:, 0] - a[:, 1])
    b[:, -1] = a[:, -1] + 0.5 * (a[:, -1] - a[:, -2])
    return b
