Skip to main content

*fuefit* fits engine-maps on physical parameters

Project description

Development Status Documentation status Latest Version in PyPI Downloads Issues count

Release:

x.x.x

Home:

https://github.com/ankostis/fuefit

Documentation:

https://fuefit.readthedocs.org/

PyPI:

https://pypi.python.org/pypi/fuefit

Copyright:

2014 European Commission (JRC-IET)

License:

EUPL 1.1+

Fuefit is a python package that calculates fitted fuel-maps from measured engine data-points based on coefficients with physical meaning.

Introduction

Overview

The Fuefit calculator performs the following:

  1. Accepts fuel-consumption engine data points as input (RPM, Power and Fuel-Consumption or equivalent quantities such as CM, PME/Torque and PMF/FC).

  2. Uses those points to fit the coefficients math(a, b, c, a2, b2, loss0, loss2) in the following formula:[1]

\begin{equation*} \mathbf{pme} = (a + b\times{\mathbf{cm}} + c\times{\mathbf{cm^2}})\times{\mathbf{pmf}} + (a2 + b2\times{\mathbf{cm}})\times{\mathbf{pmf^2}} + loss0 + loss2\times{\mathbf{cm^2}} \end{equation*}
  1. Spits-out the input engine-points according to the fitting.

An “execution” or a “run” of a calculation along with the most important pieces of data are depicted in the following diagram:

              .-----------------------------.                         .-------------------------------.
             /        Input-Model          /                         /         Output-Model          /
            /-----------------------------/                         /-------------------------------/
           / +--engine                   /                         / +--engine                     /
          /  |  +--...                  /                         /  |  +--fc_map_coeffs          /
         /   +--params                 /     ____________        /   +--measured_eng_points      /
        /    |  +--...                /     |            |      /    |    n   p  fc  pme  ...   /
       /     +--measured_eng_points  /  ==> | Calculator | ==> /     |  ... ... ...  ...  ...  /
      /          n    p    fc       /       |____________|    /      +--fitted_eng_points     /
     /          --  ----  ---      /                         /       |    n    p   fc        /
    /            0   0.0    0     /                         /        |  ...  ...  ...       /
   /           600  42.5   25    /                         /         +--mesh_eng_points    /
  /           ...    ...  ...   /                         /               n    p   fc     /
 /                             /                         /              ...  ...  ...    /
'-----------------------------'                         '-------------------------------'

The Input & Output Model are trees of strings and numbers, assembled with:

  • sequences,

  • dictionaries,

  • class(pandas.DataFrame),

  • class(pandas.Series), and

  • URI-references to other model-trees (TODO).

Apart from various engine-characteristics under /engine the table-columns such as capacity and p_rated, the table under /measured_eng_points must contain at least one column from each of the following categories (column-headers are case-insensitive):

  1. Engine-speed:

    N        (1/min)
    N_norm   (1/min)    : normalized against N_idle + (N_rated - N_idle)
    CM       (m/sec)    : Mean Piston speed
  2. Work-capability:

    P        (kW)
    P_norm   (kW)       : normalized against P_MAX
    T        (Nm)
    PME      (bar)
  3. Fuel-consumption:

    FC       (g/h)
    FC_norm  (g/h)      : normalized against P_MAX
    PMF      (bar)

Quick-start

Assuming you have a working python-environment, open a command-shell, (in Windows use program(cmd.exe) BUT ensure program(python.exe) is in its envvar(PATH)), you can try the following commands:

Install:
$ pip install fuefit --pre
$ fuefit --winmenus                             ## Windows only
Cmd-line:
$ fuefit --version
0.0.4-alpha.3

$ fuefit --help
...

## Change-directory into the `fuefit/test/` folder in the  *sources*.
$ fuefit -I FuelFit_real.csv header+=0 \
    --irenames n_norm _ fc_norm \
    -I engine.csv file_frmt=SERIES model_path=/engine header@=None \
    --irenames \
    -m /engine/fuel=petrol \
    -O - model_path=/engine/fc_map_coeffs \
    -m /params/plot_maps@=True
Excel:

$ fuefit --excelrun ## Windows & OS X only

Python-code:
import pandas as pd
from fuefit import model, processor

input_model = mdl = model.base_model()
input_model.update({...})                                   ## See "Python Usage" below.
input_model['engine_points'] = pd.read_csv('measured.csv')  ## Can also read Excel, matlab, ...
mdl = model.validate_model(mdl, additional_props)

output_model = processor.run(input_model)

print(model.resolve_jsonpointer(output_model, '/engine/fc_map_coeffs'))
print(output_model['fitted_eng_points'])

For more elaborate instructions, read the next sections.

Install

Current x.x.x runs on Python-3.3+ and it is distributed on Wheels.

Before installing it, make sure that there are no older versions left over. So run this command until you cannot find any project installed:

$ pip uninstall fuefit                                      ## Use `pip3` if both python-2 & 3 are in PATH.

You can install the project directly from the PyPi repo the “standard” way, by typing the command(pip) in the console:

$ pip install fuefit
  • If you want to install a pre-release version (the version-string is not plain numbers, but ends with alpha, beta.2 or something else), use additionally option(--pre).

  • If you want to upgrade an existing instalation along with all its dependencies, add also option(--upgrade) (or option(-U) equivalently), but then the build might take some considerable time to finish. Also there is the possibility the upgraded libraries might break existing programs(!) so use it with caution, or from within a virtualenv (isolated Python environment).

  • To install an older version issue the console command:

    $ pip install fuefit=1.1.1                    ## Use `--pre` if version-string has a build-suffix.
  • To install it for different Python environments, repeat the procedure using the appropriate program(python.exe) interpreter for each environment.

After installation, it is important that you check which version is visible in your envvar(PATH):

$ fuefit --version
0.0.4-alpha.3

Installing from sources

If you download the sources you have more options for installation. There are various methods to get hold of them:

  • Download a release-snapshot from github

  • Download the source distribution from PyPi repo.

  • Clone the git-repository at github.

    Assuming you have a working installation of git you can fetch and install the latest version of the project with the following series of commands:

    $ git clone "https://github.com/ankostis/fuefit.git" fuefit.git
    $ cd fuefit.git
    $ python setup.py install                                 ## Use `python3` if both python-2 & 3 installed.

When working with sources, you need to have installed all libraries that the project depends on. Particularly for the latest WinPython environments (Windows / OS X) you can install the necessary dependencies with:

$ pip install -r WinPython_requirements.txt -U .

The previous command installs a “snapshot” of the project as it is found in the sources. If you wish to link the project’s sources with your python environment, install the project in development mode:

$ python setup.py develop

Usage

Excel usage

In Windows and OS X you may utilize the excellent xlwings library to use Excel files for providing input and output to the processor.

To create the necessary template-files in your current-directory you should enter:

$ fuefit --excel

You could type instead fuefit --excel {file_path} to specify a different destination path.

In windows/OS X you can type fuefit --excelrun and the files will be created in your home-directory and the excel will open them in one-shot.

All the above commands creates two files:

file(fuefit_excel_runner{#}.xlsm)

The python-enabled excel-file where input and output data are written, as seen in the screenshot below:

After opening it the first tie, enable the macros on the workbook, select the python-code at the left and click the Run Selection as Pyhon button; one sheet per vehicle should be created.

The excel-file contains additionally appropriate VBA modules allowing you to invoke Python code present in selected cells with a click of a button, and python-functions declared in the python-script, below, using the mypy namespace.

To add more input-columns, you need to set as column Headers the json-pointers path of the desired model item (see Python usage below,).

file(fuefit_excel_runner{#}.py)

Python functions used by the above xls-file for running a batch of experiments.

The particular functions included reads multiple vehicles from the input table with various vehicle characteristics and/or experiment coefficients, and then it adds a new worksheet containing the cycle-run of each vehicle . Of course you can edit it to further fit your needs.

Some general notes regarding the python-code from excel-cells:

  • An elaborate syntax to reference excel cells, rows, columns or tables from python code, and to read them as class(pandas.DataFrame) is utilized by the Excel . Read its syntax at func(fuefit.excel.fuefit_excel_runner.resolve_excel_ref).

  • On each invocation, the predefined VBA module pandalon executes a dynamically generated python-script file in the same folder where the excel-file resides, which, among others, imports the “sister” python-script file. You can read & modify the sister python-script to import libraries such as ‘numpy’ and ‘pandas’, or pre-define utility python functions.

  • The name of the sister python-script is automatically calculated from the name of the Excel-file, and it must be valid as a python module-name. Therefore: * Do not use non-alphanumeric characters such as spaces(` ), dashes(-) and dots(.`) on the Excel-file. * If you rename the excel-file, rename also the python-file, or add this python import <old_py_file> as mypy`

  • On errors, a log-file is written in the same folder where the excel-file resides, for as long as the message-box is visible, and it is deleted automatically after you click ‘ok’!

  • Read http://docs.xlwings.org/quickstart.html

Cmd-line usage

Example command:

fuefit -v\
    -I fuefit/test/FuelFit.xlsx sheetname+=0 header@=None names:='["p","rpm","fc"]' \
    -I fuefit/test/engine.csv file_frmt=SERIES model_path=/engine header@=None \
    -m /engine/fuel=petrol \
    -O ~t2.csv model_path=/fitted_eng_points    index?=false \
    -O ~t2.csv model_path=/mesh_eng_points      index?=false \
    -O ~t.csv model_path= -m /params/plot_maps@=True

Python usage

Example code:

>> from fuefit import model, processor

>> input_model = model.base_model()
>> input_model.update({
    "engine": {
        "fuel": "diesel",
        "p_max": 95,
        "n_idle": 850,
        "n_rated": 6500,
        "stroke": 94.2,
        "capacity": 2000,
        "bore": null,
        "cylinders": null,
    }
})

>> model.validate_model(input_model)

>> output_model = processor.run(input_model)

>> print(output_model['engine'])
>> print(output_model['fitted_eng_maps'])

For information on the model-data, check the schema:

>> print(fuefit.model.model_schema())

You can always check the Test-cases and the mod(fuefit.cmdline) for sample code. You explore documentation in Html by serving it with a web-server:

Contribute

sad [TBD]

Development team

  • Author:
    • Kostis Anagnostopoulos

  • Contributing Authors:
    • Giorgos Fontaras for the physics, policy and admin support.

Footnotes

rubric:

CM
    Mean piston speed (measure for the engines operating speed)

PME
    Mean effective pressure (the engines ability to produce mechanical work)

PMF
    Available mean effective pressure (the maximum mean effective pressure which could be produced if n = 1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fuefit-0.0.4-alpha.3.zip (95.0 kB view details)

Uploaded Source

Built Distribution

fuefit-0.0.4_alpha.3-py3-none-any.whl (111.3 kB view details)

Uploaded Python 3

File details

Details for the file fuefit-0.0.4-alpha.3.zip.

File metadata

  • Download URL: fuefit-0.0.4-alpha.3.zip
  • Upload date:
  • Size: 95.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fuefit-0.0.4-alpha.3.zip
Algorithm Hash digest
SHA256 e138d47ea8832b7b6de4a50f0f36c9db2a42f5e59d0e84739289a3d376dc3c09
MD5 9bbcf1c630ee1134ce977e328c0dd1a1
BLAKE2b-256 87f74ef32178fe637d31a08867e5a7e23ec4efa20f2e6de77e5228255deee6df

See more details on using hashes here.

File details

Details for the file fuefit-0.0.4_alpha.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fuefit-0.0.4_alpha.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5376cb7f0489641cf5cfb781c776fbd5ee84d24eec2613abc8ebfdbc2216e07e
MD5 efe06d52aad888b0e1f52be7b5c91a24
BLAKE2b-256 273b404a2b34157371930adcc05c4d88af9310f1f4a1b2e2fa0e04925051cf81

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page