예제 #1
0
def load_inputs():
    """
    Defines a module to load the input file of the CO2MPAS model.

    .. dispatcher:: d

        >>> d = load_inputs()

    :return:
        The load input module.
    :rtype: SubDispatchFunction
    """

    d = dsp.Dispatcher(
        name='load_inputs',
        description='Loads from files the inputs for the CO2MPAS model.')

    d.add_function(function=get_cache_fpath,
                   inputs=['input_file_name'],
                   outputs=['cache_file_name'])

    d.add_data(data_id='overwrite_cache', default_value=False)

    d.add_function(
        function_id='load_data_from_cache',
        function=dsp_utl.add_args(dill.load_from_dill, n=2),
        inputs=['overwrite_cache', 'input_file_name', 'cache_file_name'],
        outputs=['raw_data'],
        input_domain=check_cache_fpath_exists)

    d.add_function(function=excel.parse_excel_file,
                   inputs=['input_file_name'],
                   outputs=['raw_data'],
                   input_domain=functools.partial(check_file_format,
                                                  extensions=('.xlsx',
                                                              '.xls')),
                   weight=5)

    d.add_function(function=dill.load_from_dill,
                   inputs=['input_file_name'],
                   outputs=['raw_data'],
                   input_domain=functools.partial(check_file_format,
                                                  extensions=('.dill', )),
                   weight=5)

    d.add_function(function_id='load_from_xlasso',
                   function=xleash.lasso,
                   inputs=['input_file_name'],
                   outputs=['raw_data'],
                   input_domain=check_xlasso,
                   weight=5)

    d.add_function(function_id='cache_parsed_data',
                   function=dill.save_dill,
                   inputs=['raw_data', 'cache_file_name'])

    return d
예제 #2
0
파일: NEDC.py 프로젝트: ncolloel/CO2MPAS-TA
def nedc_cycle():
    """
    Defines the wltp cycle model.

    .. dispatcher:: d

        >>> d = nedc_cycle()

    :return:
        The wltp cycle model.
    :rtype: co2mpas.dispatcher.Dispatcher
    """

    d = dsp.Dispatcher(
        name='NEDC cycle model',
        description='Returns the theoretical times, velocities, and gears of '
        'NEDC.')

    from ..defaults import dfl
    d.add_data(data_id='initial_temperature',
               default_value=dfl.values.initial_temperature_NEDC,
               description='Initial temperature of the test cell [°C].')

    d.add_data(data_id='max_time',
               default_value=dfl.values.max_time_NEDC,
               description='Maximum time [s].',
               initial_dist=5)

    d.add_data(data_id='k1', default_value=dfl.values.k1)

    d.add_data(data_id='k2', default_value=dfl.values.k2)

    d.add_function(function_id='set_max_gear_as_default_k5',
                   function=dsp_utl.bypass,
                   inputs=['max_gear'],
                   outputs=['k5'])

    d.add_data(data_id='k5', default_value=dfl.values.k5, initial_dist=10)

    d.add_data(data_id='time_sample_frequency',
               default_value=dfl.values.time_sample_frequency)

    d.add_function(
        function_id='nedc_gears',
        function=dsp_utl.add_args(nedc_gears),
        inputs=['gear_box_type', 'times', 'max_gear', 'k1', 'k2', 'k5'],
        outputs=['gears'],
        input_domain=lambda *args: args[0] == 'manual')

    d.add_function(function=nedc_velocities,
                   inputs=['times', 'gear_box_type'],
                   outputs=['velocities'])

    return d
예제 #3
0
def run_plan():
    """
    Defines the plan model.

    .. dispatcher:: d

        >>> d = run_plan()

    :return:
        The plan model.
    :rtype: Dispatcher
    """

    d = dsp.Dispatcher(name='run_plan',
                       description='Processes a vehicle plan.')

    d.add_data(data_id='engineering_mode', default_value=False)

    d.add_data(data_id='use_selector', default_value=False)

    d.add_data(data_id='soft_validation', default_value=False)

    d.add_function(function=dsp_utl.add_args(schema.validate_plan),
                   inputs=[
                       'run_plan', 'data', 'engineering_mode',
                       'soft_validation', 'use_selector'
                   ],
                   outputs=['validated_plan'],
                   input_domain=check_first_arg)

    d.add_function(function=default_start_time, outputs=['start_time'])

    d.add_function(function=default_timestamp,
                   inputs=['start_time'],
                   outputs=['timestamp'])

    from .plan import make_simulation_plan
    d.add_function(function=make_simulation_plan,
                   inputs=['validated_plan', 'timestamp', 'variation', 'flag'],
                   outputs=['summary'])

    return dsp_utl.SubDispatch(d)
예제 #4
0
파일: WLTP.py 프로젝트: ankostis/CO2MPAS-TA
def wltp_cycle():
    """
    Defines the wltp cycle model.

    .. dispatcher:: dsp

        >>> dsp = wltp_cycle()

    :return:
        The wltp cycle model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='WLTP cycle model',
        description='Returns the theoretical times, velocities, and gears of '
                    'WLTP.'
    )

    dsp.add_data(
        data_id='initial_temperature',
        default_value=dfl.values.initial_temperature_WLTP
    )

    dsp.add_data(
        data_id='wltp_base_model',
        default_value=deepcopy(dfl.values.wltp_base_model)
    )

    dsp.add_function(
        function=define_wltp_base_model,
        inputs=['wltp_base_model'],
        outputs=['base_model']
    )

    dsp.add_data(
        data_id='time_sample_frequency',
        default_value=dfl.values.time_sample_frequency
    )

    dsp.add_function(
        function=wltp_time_length,
        inputs=['time_sample_frequency'],
        outputs=['time_length'],
        weight=5
    )

    dsp.add_dispatcher(
        dsp=calculate_wltp_velocities(),
        inputs={
            'times': 'times',
            'base_model': 'base_model',
            'velocities': 'velocities',
            'speed_velocity_ratios': 'speed_velocity_ratios',
            'inertial_factor': 'inertial_factor',
            'downscale_phases': 'downscale_phases',
            'climbing_force': 'climbing_force',
            'downscale_factor': 'downscale_factor',
            'downscale_factor_threshold': 'downscale_factor_threshold',
            'vehicle_mass': 'vehicle_mass',
            'driver_mass': 'driver_mass',
            'road_loads': 'road_loads',
            'engine_max_power': 'engine_max_power',
            'engine_max_speed_at_max_power': 'engine_max_speed_at_max_power',
            'max_velocity': 'max_velocity',
            'wltp_class': 'wltp_class',
            'max_speed_velocity_ratio': 'max_speed_velocity_ratio'
        },
        outputs={
            'velocities': 'velocities'
        }
    )

    dsp.add_function(
        function=dsp_utl.add_args(wltp_gears),
        inputs=['gear_box_type', 'full_load_curve', 'velocities',
                'accelerations', 'motive_powers', 'speed_velocity_ratios',
                'idle_engine_speed', 'engine_max_speed_at_max_power',
                'engine_max_power', 'base_model'],
        outputs=['gears'],
        input_domain=lambda *args: args[0] == 'manual'
    )

    return dsp
예제 #5
0
def load_inputs():
    """
    Defines a module to load the input file of the CO2MPAS model.

    .. dispatcher:: dsp

        >>> dsp = load_inputs()

    :return:
        The load input module.
    :rtype: SubDispatchFunction
    """

    dsp = Dispatcher(
        name='load_inputs',
        description='Loads from files the inputs for the CO2MPAS model.'
    )

    dsp.add_function(
        function=get_cache_fpath,
        inputs=['input_file_name'],
        outputs=['cache_file_name']
    )

    dsp.add_data(
        data_id='overwrite_cache',
        default_value=False,
    )

    dsp.add_function(
        function_id='load_data_from_cache',
        function=dsp_utl.add_args(load_from_dill, n=2),
        inputs=['overwrite_cache', 'input_file_name', 'cache_file_name'],
        outputs=['data'],
        input_domain=check_cache_fpath_exists
    )

    dsp.add_function(
        function=parse_excel_file,
        inputs=['input_file_name'],
        outputs=['data'],
        input_domain=partial(check_file_format, extensions=('.xlsx', '.xls')),
        weight=5
    )

    dsp.add_function(
        function=load_from_dill,
        inputs=['input_file_name'],
        outputs=['data'],
        input_domain=partial(check_file_format, extensions=('.dill',)),
        weight=5
    )

    dsp.add_function(
        function_id='load_from_xlasso',
        function=lasso,
        inputs=['input_file_name'],
        outputs=['data'],
        input_domain=check_xlasso,
        weight=5
    )

    dsp.add_function(
        function_id='cache_parsed_data',
        function=save_dill,
        inputs=['data', 'cache_file_name']
    )

    dsp.add_function(
        function=partial(validate_data, read_schema=define_data_schema()),
        inputs=['data', 'soft_validation'],
        outputs=['validated_data', 'validated_plan'],
        weight=1
    )

    dsp.add_data(
        data_id='validated_data',
        function=check_data_version
    )

    return dsp
예제 #6
0
def run_base():
    """
    Defines the vehicle-processing model.

    .. dispatcher:: d

        >>> d = run_base()

    :return:
        The vehicle-processing model.
    :rtype: Dispatcher
    """

    d = dsp.Dispatcher(
        name='run_base',
        description='Processes a vehicle from the file path to the write of its'
        ' outputs.')

    d.add_data(data_id='engineering_mode', default_value=False)

    d.add_data(data_id='output_folder', default_value='.')

    d.add_data(data_id='use_selector', default_value=False)

    d.add_data(data_id='soft_validation', default_value=False)

    d.add_function(function=dsp_utl.add_args(schema.validate_base),
                   inputs=[
                       'run_base', 'data', 'engineering_mode',
                       'soft_validation', 'use_selector'
                   ],
                   outputs=['validated_base'],
                   input_domain=check_first_arg,
                   weight=10)

    d.add_data(data_id='only_summary', default_value=False)

    d.add_function(function=default_vehicle_name,
                   inputs=['input_file_name'],
                   outputs=['vehicle_name'])

    d.add_function(function=default_start_time, outputs=['start_time'])

    d.add_function(function=default_timestamp,
                   inputs=['start_time'],
                   outputs=['timestamp'])

    d.add_function(function=default_output_file_name,
                   inputs=['output_folder', 'vehicle_name', 'timestamp'],
                   outputs=['output_file_name'])

    from .model import model
    d.add_function(
        function=dsp_utl.SubDispatch(model()),
        inputs=['validated_base'],
        outputs=['dsp_solution'],
    )

    d.add_function(function=parse_dsp_solution,
                   inputs=['dsp_solution'],
                   outputs=['output_data'])

    from .report import report
    d.add_function(
        function=report(),
        inputs=['output_data', 'vehicle_name'],
        outputs=['report', 'summary'],
    )

    d.add_function(function=get_template_file_name,
                   inputs=['output_template', 'input_file_name'],
                   outputs=['template_file_name'])

    d.add_data(data_id='output_template',
               default_value=_get_co2mpas_output_template_fpath(),
               initial_dist=10)

    from .io import write_outputs
    d.add_function(function=dsp_utl.add_args(write_outputs()),
                   inputs=[
                       'only_summary', 'output_file_name',
                       'template_file_name', 'report', 'start_time', 'flag'
                   ],
                   outputs=[dsp_utl.SINK],
                   input_domain=lambda *args: not args[0])

    d.add_function(
        function=dsp_utl.add_args(plot_model_workflow),
        inputs=['plot_workflow', 'output_file_name', 'vehicle_name'],
        outputs=[dsp_utl.PLOT],
        weight=30,
        input_domain=check_first_arg)

    return dsp_utl.SubDispatch(d)
예제 #7
0
def final_drive():
    """
    Defines the final drive model.

    .. dispatcher:: d

        >>> d = final_drive()

    :return:
        The final drive model.
    :rtype: co2mpas.dispatcher.Dispatcher
    """

    d = dsp.Dispatcher(name='Final drive',
                       description='Models the final drive.')

    from .defaults import dfl
    d.add_data(data_id='final_drive_ratio',
               default_value=dfl.values.final_drive_ratio)

    d.add_function(function=calculate_final_drive_speeds_in,
                   inputs=['final_drive_speeds_out', 'final_drive_ratio'],
                   outputs=['final_drive_speeds_in'])

    d.add_data(data_id='final_drive_efficiency',
               default_value=dfl.values.final_drive_efficiency)

    d.add_data(data_id='n_wheel_drive', default_value=dfl.values.n_wheel_drive)

    d.add_function(
        function=calculate_final_drive_torque_losses,
        inputs=['final_drive_torques_out', 'final_drive_torque_loss'],
        outputs=['final_drive_torque_losses'])

    d.add_function(
        function=dsp_utl.add_args(calculate_final_drive_torque_losses_v1),
        inputs=[
            'n_dyno_axes', 'n_wheel_drive', 'final_drive_torques_out',
            'final_drive_ratio', 'final_drive_efficiency'
        ],
        outputs=['final_drive_torque_losses'],
        weight=5,
        input_domain=domain_final_drive_torque_losses_v1)

    d.add_function(function=calculate_final_drive_torques_in,
                   inputs=[
                       'final_drive_torques_out', 'final_drive_ratio',
                       'final_drive_torque_losses'
                   ],
                   outputs=['final_drive_torques_in'])

    d.add_function(function=calculate_final_drive_efficiencies,
                   inputs=[
                       'final_drive_torques_out', 'final_drive_ratio',
                       'final_drive_torques_in'
                   ],
                   outputs=['final_drive_efficiencies'])

    d.add_function(
        function=calculate_final_drive_powers_in,
        inputs=['final_drive_powers_out', 'final_drive_efficiencies'],
        outputs=['final_drive_powers_in'])

    return d
예제 #8
0
def vehicle_processing_model():
    """
    Defines the vehicle-processing model.

    .. dispatcher:: dsp

        >>> dsp = vehicle_processing_model()

    :return:
        The vehicle-processing model.
    :rtype: Dispatcher
    """

    dsp = Dispatcher(
        name='CO2MPAS vehicle_processing_model',
        description='Processes a vehicle from the file path to the write of its'
        ' outputs.')

    dsp.add_data(data_id='overwrite_cache', default_value=False)

    dsp.add_data(data_id='soft_validation', default_value=False)

    dsp.add_data(data_id='with_output_file', default_value=False)

    dsp.add_function(function=default_vehicle_name,
                     inputs=['input_file_name'],
                     outputs=['vehicle_name'])

    dsp.add_function(function=default_start_time, outputs=['start_time'])

    dsp.add_function(function=default_timestamp,
                     inputs=['start_time'],
                     outputs=['timestamp'])

    dsp.add_function(function=dsp_utl.add_args(default_output_file_name),
                     inputs=[
                         'with_output_file', 'output_folder', 'vehicle_name',
                         'timestamp'
                     ],
                     outputs=['output_file_name'],
                     input_domain=lambda *args: args[0])

    from .io import load_inputs, write_outputs

    dsp.add_dispatcher(dsp=load_inputs(),
                       inputs={
                           'input_file_name': 'input_file_name',
                           'overwrite_cache': 'overwrite_cache',
                           'soft_validation': 'soft_validation'
                       },
                       outputs={
                           'validated_data': 'validated_data',
                           'validated_plan': 'validated_plan'
                       })

    from .model import model
    dsp.add_function(function=dsp_utl.add_args(
        dsp_utl.SubDispatch(model(), output_type='dsp')),
                     inputs=['plan', 'validated_data'],
                     outputs=['dsp_model'],
                     input_domain=lambda *args: not args[0])

    dsp.add_function(function=parse_dsp_model,
                     inputs=['dsp_model'],
                     outputs=['output_data'])

    from .report import report
    dsp.add_function(
        function=report(),
        inputs=['output_data', 'vehicle_name'],
        outputs=['report', 'summary'],
    )

    dsp.add_function(function=dsp_utl.bypass,
                     inputs=['output_data'],
                     outputs=['report'],
                     weight=1)

    dsp.add_function(function=get_template_file_name,
                     inputs=['output_template', 'input_file_name'],
                     outputs=['template_file_name'])

    dsp.add_data(data_id='output_template', default_value='', initial_dist=10)

    main_flags = ('template_file_name', 'overwrite_cache', 'soft_validation',
                  'with_output_file', 'plot_workflow')

    dsp.add_function(function=partial(dsp_utl.map_list, main_flags),
                     inputs=main_flags,
                     outputs=['main_flags'])

    dsp.add_function(function=write_outputs(),
                     inputs=[
                         'output_file_name', 'template_file_name', 'report',
                         'start_time', 'main_flags'
                     ],
                     outputs=[dsp_utl.SINK],
                     input_domain=check_first_arg)

    dsp.add_function(function_id='has_plan',
                     function=check_first_arg,
                     inputs=['validated_plan'],
                     outputs=['plan'])

    from .plan import make_simulation_plan
    dsp.add_function(function=dsp_utl.add_args(make_simulation_plan),
                     inputs=[
                         'plan', 'validated_plan', 'timestamp',
                         'output_folder', 'main_flags'
                     ],
                     outputs=['summary'],
                     input_domain=check_first_arg)

    return dsp