@sh.add_function(dsp, outputs=['service_battery_charging_statuses'])
def identify_service_battery_charging_statuses(
times, alternator_electric_powers, dcdc_converter_electric_powers,
motive_powers, on_engine,
service_battery_electric_powers_supply_threshold,
service_battery_starts_windows, service_battery_initialization_time):
"""
Identifies service battery charging statuses: Discharge (0), Charging (1),
BERS (2), and Initialization(3) [-].
:param times:
Time vector [s].
:type times: numpy.array
:param alternator_electric_powers:
Alternator electric power [kW].
:type alternator_electric_powers: numpy.array
:param dcdc_converter_electric_powers:
DC/DC converter electric power [kW].
:type dcdc_converter_electric_powers: numpy.array
:param motive_powers:
Motive power [kW].
:type motive_powers: numpy.array
:param on_engine:
If the engine is on [-].
:type on_engine: numpy.array
:param service_battery_electric_powers_supply_threshold:
Service battery not charging power threshold [kW].
:type service_battery_electric_powers_supply_threshold: float
:param service_battery_starts_windows:
Service battery starts windows [-].
:type service_battery_starts_windows: numpy.array
:param service_battery_initialization_time:
Service battery initialization time delta [s].
:type service_battery_initialization_time: float
:return:
Service battery charging statuses (0: Discharge, 1: Charging, 2: BERS,
3: Initialization) [-].
:rtype: numpy.array
"""
threshold = service_battery_electric_powers_supply_threshold
b = (alternator_electric_powers < threshold) & on_engine
status = b.astype(int, copy=True)
status[b & (motive_powers < 0)] = 2
off = ~on_engine | service_battery_starts_windows
mask = _mask_boolean_phases(status != 1)
for i, j in mask:
# noinspection PyUnresolvedReferences
if ((status[i:j] == 2) | off[i:j]).all():
status[i:j] = 1
status[dcdc_converter_electric_powers < threshold] = 1
_set_alt_init_status(times, service_battery_initialization_time, status)
return status