def _calc_num_bins(binsize, t_start, t_stop):
    """
    Calculates the number of bins from given parameters.

    Calculates the number of bins `num_bins` from the three parameters
    `binsize`, `t_start`, `t_stop`.

    Parameters
    ----------
    binsize : pq.Quantity
        Size of Bins
    t_start : pq.Quantity
        Start time
    t_stop : pq.Quantity
        Stop time

    Returns
    -------
    num_bins : int
       Number of bins calculated from given parameters.

    Raises
    ------
    ValueError
        When `t_stop` is smaller than `t_start`".

    """
    if binsize is not None and t_start is not None and t_stop is not None:
        if t_stop < t_start:
            raise ValueError('t_stop (%s) is smaller than t_start (%s)' % (
                t_stop, t_start))
        return int(((t_stop - t_start).rescale(binsize.units) / binsize).
            magnitude)
