def METHOD_NAME(grid, fourier_grid, sort_by_energy=True):
    '''Make a cosine basis.
    Repeated frequencies will not be repeated in this mode basis. This means that opposite points in the `fourier_grid` will be silently ignored.
    Parameters
    ----------
    grid : Grid
        The :class:`Grid` on which to calculate the modes.
    fourier_grid : Grid
        The grid defining all frequencies.
    sort_by_energy : bool
        Whether to sort by increasing energy or not.
    Returns
    -------
    ModeBasis
        The mode basis containing all cosine modes.
    '''
    modes = []
    energies = []
    ignore_list = []
    c = np.array(grid.coords)
    for i, p in enumerate(fourier_grid.points):
        if i in ignore_list:
            continue
        mode = Field(np.cos(np.dot(p, c)), grid)
        # Correctly normalize the non-zero energy mode.
        if not np.dot(p, p) < _epsilon**2:
            mode *= np.sqrt(2)
        modes.append(mode)
        j = fourier_grid.closest_to(-p)
        dist = fourier_grid.points[j] + p
        dist2 = np.dot(dist, dist)
        p_length2 = np.dot(p, p)
        energies.append(p_length2)
        if dist2 < (_epsilon * p_length2):
            ignore_list.append(j)
    if sort_by_energy:
        ind = np.argsort(energies)
        modes = [modes[i] for i in ind]
    return ModeBasis(modes, grid)