def fw0(m0, n0, c0, xs_norm, ts, funcnum=2):
    """Calculates the imperfection field `w_0` for a given input.

    Parameters
    ----------
    m0 : int
        The number of terms along the meridian.
    n0 : int
        The number of terms along the circumference.
    c0 : numpy.ndarray
        The coefficients of the imperfection pattern.
    xs_norm : numpy.ndarray
        The meridian coordinate (`x`) normalized to be between ``0.`` and
        ``1.``.
    ts : numpy.ndarray
        The angles in radians representing the circumferential coordinate
        (`\\theta`).
    funcnum : int, optional
        The function used for the approximation (see the ``calc_c0`` function)

    Notes
    -----
    The inputs ``xs_norm`` and ``ts`` must be of the same size.

    If ``funcnum==1 or funcnum==2`` then ``size=2``, if ``funcnum==3`` then
    ``size=4`` and the inputs must satisfy ``c0.shape[0] == size*m0*n0``.

    """
    if xs_norm.shape != ts.shape:
        raise ValueError('xs_norm and ts must have the same shape')
    if funcnum == 1:
        size = 2
    elif funcnum == 2:
        size = 2
    elif funcnum == 3:
        size = 4
    if c0.shape[0] != size * m0 * n0:
        raise ValueError('Invalid c0 for the given m0 and n0!')
    import mgi
    w0s = mgi.fw0(m0, n0, c0, xs_norm.ravel(), ts.ravel(), funcnum)
    return w0s.reshape(xs_norm.shape)
