def coord_shift180(lon):
    """Enforce coordinate longiude to range from -180 to 180.

    Sometimes longitudes are 0-360. This simple function will subtract
    360 from those that are above 180 to get the more user-friendly 
    [-180, 180], since slicing is a lot easier.

    Parameters
    ----------
    lon: numpy.ndarray
        Array of longitudes with values in range [0, 360].
    
    Returns
    -------
    numpy.ndarray with longitudes in range [-180, 180].
    """  # noqa

    nlon = len(lon)

    # change those above 180.0 to negative
    for i in range(nlon):
        x = lon[i]
        if x > 180:
            lon[i] = x - 360

    return lon