@sh.add_function(dsp, outputs=['batteries_phases_delta_energy'])
def calculate_batteries_phases_delta_energy(
times, phases_indices, drive_battery_electric_powers,
service_battery_electric_powers):
"""
Calculates the phases delta energy of the batteries [Wh].
:param times:
Time vector.
:type times: numpy.array
:param phases_indices:
Indices of the cycle phases [-].
:type phases_indices: numpy.array
:param drive_battery_electric_powers:
Drive battery electric power [kW].
:type drive_battery_electric_powers: numpy.array
:param service_battery_electric_powers:
Service battery electric power [kW].
:type service_battery_electric_powers: numpy.array
:return:
Phases delta energy of the batteries [Wh].
:rtype: numpy.array
"""
from scipy.integrate import cumtrapz
p = service_battery_electric_powers + drive_battery_electric_powers
e = cumtrapz(p, times, initial=0)
i = phases_indices.copy()
i[:, 1] -= 1
return np.diff(e[i], axis=1).ravel() / 3.6