@sh.add_function(dsp, weight=5, outputs=[
'identified_co2_emissions', 'co2_rescaling_scores', 'co2_params_identified'
])
def identify_co2_emissions(
co2_emissions_model, co2_params_initial_guess, times,
extended_phases_integration_times, extended_cumulative_co2_emissions,
engine_coolant_temperatures, is_cycle_hot, velocities, stop_velocity):
"""
Identifies instantaneous CO2 emission vector [CO2g/s].
:param co2_emissions_model:
CO2 emissions model (co2_emissions = models(params)).
:type co2_emissions_model: callable
:param co2_params_initial_guess:
Initial guess of co2 emission model params.
:type co2_params_initial_guess: dict
:param times:
Time vector [s].
:type times: numpy.array
:param extended_phases_integration_times:
Extended cycle phases integration times [s].
:type extended_phases_integration_times: tuple
:param extended_cumulative_co2_emissions:
Extended cumulative CO2 of cycle phases [CO2g].
:type extended_cumulative_co2_emissions: numpy.array
:param engine_coolant_temperatures:
Engine coolant temperature vector [°C].
:type engine_coolant_temperatures: numpy.array
:param is_cycle_hot:
Is an hot cycle?
:type is_cycle_hot: bool
:param velocities:
Velocity vector [km/h].
:type velocities: numpy.array
:param stop_velocity:
Maximum velocity to consider the vehicle stopped [km/h].
:type stop_velocity: float
:return:
The instantaneous CO2 emission vector [CO2g/s], rescaling scores
(i.e., mean, std, and number of perturbations) [-], and the identified
initial guess of co2 emission model params.
:rtype: numpy.array, tuple[float], dict
"""
p = co2_params_initial_guess
rescaling_matrix = _rescaling_matrix(
extended_phases_integration_times, times, velocities, stop_velocity
)
rescale = _define_rescaling_function(
co2_emissions_model, extended_cumulative_co2_emissions,
extended_phases_integration_times, times, rescaling_matrix
)
d = dfl.functions.identify_co2_emissions
n, (co2, k0) = 0, rescale(p)
if d.enable_first_step or d.enable_second_step or d.enable_third_step:
calibrate = functools.partial(
calibrate_co2_params, is_cycle_hot, engine_coolant_temperatures,
co2_emissions_model, _1st_step=d.enable_first_step,
_2nd_step=d.enable_second_step, _3rd_step=d.enable_third_step,
)
xatol = d.xatol
for n in range(d.n_perturbations):
p = calibrate(co2, p)[0]
co2, k1 = rescale(p)
if np.max(np.abs(k1 - k0)) <= xatol:
k0 = k1
break
k0 = k1
return co2, _rescaling_score(times, rescaling_matrix, k0) + (n,), p