@sh.add_function(dsp, outputs=['extended_integration_times'])
def calculate_extended_integration_times(
times, velocities, on_engine, phases_integration_times,
engine_coolant_temperatures, after_treatment_temperature_threshold,
stop_velocity):
"""
Calculates the extended integration times [-].
:param times:
Time vector [s].
:type times: numpy.array
:param velocities:
Velocity vector [km/h].
:type velocities: numpy.array
:param on_engine:
If the engine is on [-].
:type on_engine: numpy.array
:param phases_integration_times:
Cycle phases integration times [s].
:type phases_integration_times: tuple
:param engine_coolant_temperatures:
Engine coolant temperature vector [°C].
:type engine_coolant_temperatures: numpy.array
:param after_treatment_temperature_threshold:
Engine coolant temperature threshold when the after treatment system is
warm [°C].
:type after_treatment_temperature_threshold: (float, float)
:param stop_velocity:
Maximum velocity to consider the vehicle stopped [km/h].
:type stop_velocity: float
:return:
Extended cycle phases integration times [s].
:rtype: tuple
"""
lv, pit = np.zeros(velocities.size + 2), np.unique(phases_integration_times)
lv[1:-1] = np.asarray(velocities <= stop_velocity, int)
indices = np.where(np.diff(lv) != 0)[0].reshape(-1, 2)
split_points = []
for i, j in indices:
t0, t1 = times[i], times[j - 1]
if t1 - t0 < 20 or any(t0 <= x <= t1 for x in pit):
continue
b = ~on_engine[i:j]
if b.any() and not b.all():
t = np.median(times[i:j][b])
else:
t = (t0 + t1) / 2
split_points.append(t)
try:
i = np.searchsorted(
engine_coolant_temperatures,
(after_treatment_temperature_threshold[1],)
)[0]
if not lv[i + 1]:
split_points.append(times[i])
except IndexError:
pass
return sorted(split_points)