def breakpoint_B_for_period(binary_occupancy, bkpt_A):
    """Find breakpoint B.

    Breakpoint B is the first timestep after breakpoint A that the detector
    is not continuously occupied. This means it is the timestep that the
    discharge wave has reached the advance detector"""
    if bkpt_A is None:
        return None
    continuously_occupied = (binary_occupancy.loc[bkpt_A:]
                                             .expanding()
                                             .agg(lambda x: x.all()))
    bkpt = continuously_occupied.loc[continuously_occupied == 0]
    try:
        bkpt = bkpt.index[0]
    except IndexError:
        return None
    return bkpt