@sh.add_function(dsp, outputs=['service_battery_starts_windows'])
def identify_service_battery_starts_windows(
times, engine_starts, alternator_electric_powers,
service_battery_start_window_width,
service_battery_electric_powers_supply_threshold):
"""
Identifies the alternator starts windows [-].
:param times:
Time vector [s].
:type times: numpy.array
:param engine_starts:
When the engine starts [-].
:type engine_starts: numpy.array
:param alternator_electric_powers:
Alternator electric power [kW].
:type alternator_electric_powers: numpy.array
:param service_battery_start_window_width:
Service battery start window width [s].
:type service_battery_start_window_width: float
:param service_battery_electric_powers_supply_threshold:
Service battery not charging power threshold [kW].
:type service_battery_electric_powers_supply_threshold: float
:return:
Service battery starts windows [-].
:rtype: numpy.array
"""
ts, dt = times[engine_starts], service_battery_start_window_width / 2
starts_windows = np.zeros_like(times, dtype=bool)
ind = np.searchsorted(times, np.column_stack((ts - dt, ts + dt + dfl.EPS)))
b = service_battery_electric_powers_supply_threshold
b = alternator_electric_powers >= b
for i, j in ind:
starts_windows[i:j] = b[i:j].any()
return starts_windows