@sh.add_function(dsp, outputs=['m1000_curve_factor'])
def calibrate_m1000_curve_factor(
full_load_curve, normalized_VDI253_model, clutch_phases,
engine_speeds_out_hot, gear_box_speeds_in, gear_box_torques_in,
clutch_tc_speeds_delta):
"""
Calibrate the rescaling factor of m1000 curve [N*m/1e6].
:param full_load_curve:
Vehicle full load curve.
:type full_load_curve: function
:param normalized_VDI253_model:
Normalized VDI253 model function.
:type normalized_VDI253_model: scipy.interpolate.LinearNDInterpolator
:param clutch_phases:
When the clutch is active [-].
:type clutch_phases: numpy.array
:param engine_speeds_out_hot:
Engine speed at hot condition [RPM].
:type engine_speeds_out_hot: numpy.array
:param gear_box_speeds_in:
Gear box speed vector [RPM].
:type gear_box_speeds_in: numpy.array
:param gear_box_torques_in:
Torque required vector [N*m].
:type gear_box_torques_in: numpy.array
:param clutch_tc_speeds_delta:
Engine speed delta due to the clutch or torque converter [RPM].
:type clutch_tc_speeds_delta: numpy.array
:return:
Rescaling factor of m1000 curve [N*m/1e6].
:rtype: float
"""
if clutch_phases.sum() <= 10:
return sh.NONE
from co2mpas.utils import mae
from scipy.optimize import fmin
# noinspection PyUnresolvedReferences
es, gbs, gbt, predict, ds = (
engine_speeds_out_hot[clutch_phases], gear_box_speeds_in[clutch_phases],
gear_box_torques_in[clutch_phases], normalized_VDI253_model.predict,
clutch_tc_speeds_delta[clutch_phases]
)
def _err(factor):
e = mae(ds, np.nan_to_num(predict((gbs, gbt / factor)) - es))
return np.float32(e)
return fmin(_err, default_m1000_curve_factor(full_load_curve))