def to_interpolation_method(im):
    """
    to_interpolation_method(x) yields either 'linear' or 'nearest' or raises an exception, depending
      on x; if x is None or a string resembling 'nearest', then 'nearest' is returned, while a
      string resembling 'linear' results in 'linear' being returned.
    """
    if im is None:
        return 'nearest'
    im = im.lower()
    if im in ['linear', 'lin', 'trilinear', 'trilin']:
        return 'linear'
    elif im in ['nearest', 'near', 'nn', 'nearest-neighbor', 'nearest_neighbor'
        ]:
        return 'nearest'
    else:
        raise ValueError(
            'given interpolation_method (%s) is not recognized' % (im,))
