def closest_bin(q, bin_edges):
    """
        Find closest bin to a q-value
        :param float q: q-value
        :param list bin_edges: list of bin edges
    """
    for i in range(len(bin_edges)):
        if q > bin_edges[i] and q <= bin_edges[i+1]:
            return i
    return None