|
1 | | -# DCM |
2 | | - |
3 | | -A Python package for reading and writing DCM (Data Conservation Format) files used in various ECU calibration tools such as INCA, MDA, EHANDBOOK, CANape, and more. |
4 | | - |
5 | | -## Table of Contents |
6 | | - |
7 | | -- [Features](#features) |
8 | | -- [Installation](#installation) |
9 | | -- [Usage](#usage) |
10 | | - - [Reading a DCM File](#reading-a-dcm-file) |
11 | | - - [Writing a DCM File](#writing-a-dcm-file) |
12 | | - - [Accessing Data](#accessing-data) |
13 | | - - [Loading Data from Excel](#loading-data-from-excel) |
14 | | - - [Interpolation Functions](#interpolation-functions) |
15 | | -- [Examples](#examples) |
16 | | -- [Dependencies](#dependencies) |
17 | | -- [License](#license) |
18 | | -- [Contributing](#contributing) |
19 | | -- [Contact](#contact) |
20 | | - |
21 | | -## Features |
22 | | - |
23 | | -- **Read and Write DCM Files**: Parse and generate DCM files used in ECU calibration. |
24 | | -- **Data Manipulation**: Access and modify parameters, curves, maps, and other calibration data. |
25 | | -- **Excel Integration**: Load calibration data from Excel files. |
26 | | -- **Interpolation**: Perform 1D and 2D linear interpolation on calibration data. |
27 | | -- **Visualization**: Plot characteristic lines and maps using Matplotlib. |
28 | | -- **Support for Various Data Types**: Handle parameters, parameter blocks, characteristic lines, characteristic maps, distributions, and text strings. |
| 1 | +Let me revise it with a more user-friendly approach in English: |
29 | 2 |
|
30 | | -## Installation |
31 | | - |
32 | | -Ensure you have Python 3.11 or higher installed. Install the package using `pip`: |
33 | | - |
34 | | -```bash |
35 | | -pip install git+https://github.com/c0sogi/python-dcm.git |
36 | | -``` |
| 3 | +# python-dcm |
37 | 4 |
|
38 | | -Or if you have the package files locally: |
| 5 | +A high-performance Python package for handling ETAS DCM(Data Conversion Format) files used in engine calibration tools like INCA, MDA, EHANDBOOK, and CANape. |
39 | 6 |
|
40 | | -```bash |
41 | | -pip install . |
42 | | -``` |
43 | | - |
44 | | -## Usage |
45 | | - |
46 | | -### Reading a DCM File |
| 7 | +## Quick Start |
47 | 8 |
|
48 | 9 | ```python |
49 | 10 | from dcm import DCM |
50 | 11 |
|
51 | 12 | # Read a DCM file |
52 | | -dcm = DCM.from_file('path/to/your_file.dcm') |
53 | | -``` |
| 13 | +dcm = DCM.from_file('calibration.dcm') |
54 | 14 |
|
55 | | -### Writing a DCM File |
| 15 | +# Access calibration data |
| 16 | +parameter_value = dcm.parameters['ENGINE_SPEED'].value |
| 17 | +map_data = dcm.maps['FUEL_MAP'].dataframe |
| 18 | +curve_data = dcm.curves['BOOST_CURVE'].series |
56 | 19 |
|
57 | | -```python |
58 | | -# Write the DCM object to a file |
59 | | -dcm.write('path/to/output_file.dcm') |
60 | | -``` |
61 | | - |
62 | | -### Accessing Data |
63 | | - |
64 | | -```python |
65 | | -# Access a parameter |
66 | | -parameter = dcm.parameters['PARAMETER_NAME'] |
67 | | -print(parameter.value) |
| 20 | +# Interpolate values |
| 21 | +x_points = [1000, 1500, 2000] # RPM |
| 22 | +y_points = [50, 75, 100] # Load % |
| 23 | +interpolated = dcm.maps['FUEL_MAP'].as_function(x_points, y_points) |
68 | 24 |
|
69 | | -# Access a characteristic line (curve) |
70 | | -curve = dcm.curves['CURVE_NAME'] |
71 | | -print(curve.series) |
72 | | - |
73 | | -# Access a characteristic map |
74 | | -char_map = dcm.maps['MAP_NAME'] |
75 | | -print(char_map.dataframe) |
| 25 | +# Visualize data |
| 26 | +dcm.maps['FUEL_MAP'].to_figure() |
76 | 27 | ``` |
77 | 28 |
|
78 | | -### Loading Data from Excel |
79 | | - |
80 | | -You can load calibration data from Excel files into the DCM object. |
| 29 | +## Key Features |
81 | 30 |
|
82 | | -```python |
83 | | -# Load maps from an Excel file |
84 | | -dcm.load_maps('maps.xlsx') |
| 31 | +- **Easy Data Access**: Directly access parameters, curves, and maps with Pandas integration |
| 32 | +- **Interpolation**: Built-in 1D/2D linear interpolation for real-time value calculation |
| 33 | +- **Visualization**: One-line plotting of characteristic curves and maps |
| 34 | +- **Excel Integration**: Import/export calibration data from Excel spreadsheets |
| 35 | +- **Set Operations**: Compare and merge DCM files with `|`, `-`, `&`, and `%` operators |
| 36 | +- **Type Support**: Handle all DCM data types including fixed/group characteristics |
85 | 37 |
|
86 | | -# Load curves from an Excel file |
87 | | -dcm.load_lines('curves.xlsx') |
| 38 | +## Installation |
88 | 39 |
|
89 | | -# Load parameters from an Excel file |
90 | | -dcm.load_parameters('parameters.xlsx') |
| 40 | +Requires Python ≥ 3.10 |
91 | 41 |
|
92 | | -# Load parameter blocks from an Excel file |
93 | | -dcm.load_parameter_blocks('parameter_blocks.xlsx') |
| 42 | +```bash |
| 43 | +pip install python-dcm |
94 | 44 | ``` |
95 | 45 |
|
96 | | -### Interpolation Functions |
97 | | - |
98 | | -Perform interpolation using the calibration data. |
99 | | - |
100 | | -#### 1D Interpolation (Characteristic Line) |
| 46 | +## Common Use Cases |
101 | 47 |
|
| 48 | +### Data Access & Manipulation |
102 | 49 | ```python |
103 | | -# Get the interpolation function for a curve |
104 | | -curve_function = curve.as_function |
| 50 | +# Get parameter value |
| 51 | +rpm_limit = dcm.parameters['MAX_RPM'].value |
105 | 52 |
|
106 | | -# Interpolate at specific points |
107 | | -import numpy as np |
108 | | -x_values = np.array([1.0, 2.0, 3.0]) |
109 | | -interpolated_values = curve_function(x_values) |
110 | | -``` |
| 53 | +# Access map as DataFrame |
| 54 | +fuel_map = dcm.maps['FUEL_MAP'].dataframe |
| 55 | +fuel_map.iloc[0, 0] = 14.7 # Modify value |
111 | 56 |
|
112 | | -#### 2D Interpolation (Characteristic Map) |
| 57 | +# Get curve data |
| 58 | +boost_curve = dcm.curves['BOOST_CURVE'].series |
| 59 | +max_boost = boost_curve.max() |
| 60 | +``` |
113 | 61 |
|
| 62 | +### Excel Integration |
114 | 63 | ```python |
115 | | -# Get the interpolation function for a map |
116 | | -map_function = char_map.as_function |
117 | | - |
118 | | -# Interpolate at specific x and y points |
119 | | -x_values = np.array([1.0, 2.0, 3.0]) |
120 | | -y_values = np.array([4.0, 5.0, 6.0]) |
121 | | -interpolated_values = map_function(x_values, y_values) |
| 64 | +# Load calibration data from Excel |
| 65 | +dcm.load_from_excel( |
| 66 | + maps_path='maps.xlsx', |
| 67 | + curves_path='curves.xlsx', |
| 68 | + parameters_path='params.xlsx' |
| 69 | +) |
| 70 | + |
| 71 | +# Each sheet name becomes the calibration object name |
122 | 72 | ``` |
123 | 73 |
|
124 | | -## Examples |
125 | | - |
126 | | -### Plotting a Characteristic Line |
127 | | - |
| 74 | +### Visualization |
128 | 75 | ```python |
129 | 76 | import matplotlib.pyplot as plt |
130 | 77 |
|
131 | | -# Plot the curve |
132 | | -fig, ax = curve.to_figure() |
| 78 | +# Plot a map with custom settings |
| 79 | +fig, ax = dcm.maps['FUEL_MAP'].to_figure( |
| 80 | + cmap='viridis', |
| 81 | + fontsize=12 |
| 82 | +) |
133 | 83 | plt.show() |
| 84 | + |
| 85 | +# Plot multiple curves |
| 86 | +fig, ax = plt.subplots() |
| 87 | +dcm.curves['BOOST_LOW'].to_figure(ax=ax, label='Low') |
| 88 | +dcm.curves['BOOST_HIGH'].to_figure(ax=ax, label='High') |
| 89 | +plt.legend() |
134 | 90 | ``` |
135 | 91 |
|
136 | | -### Plotting a Characteristic Map |
| 92 | +### Advanced Features |
137 | 93 |
|
| 94 | +#### Parameter Type Conversion |
138 | 95 | ```python |
139 | | -import matplotlib.pyplot as plt |
140 | | - |
141 | | -# Plot the map |
142 | | -fig, ax = char_map.to_figure() |
143 | | -plt.show() |
| 96 | +param = dcm.parameters['CONTROL_BITS'] |
| 97 | +binary = param.as_bin() # [1, 3, 5] (bits set to 1) |
| 98 | +hex_val = param.as_hex() # [A, F, 1] (hexadecimal digits) |
144 | 99 | ``` |
145 | 100 |
|
146 | | -### Combining DCM Objects |
147 | | - |
148 | | -You can combine DCM objects using set operations: |
149 | | - |
| 101 | +#### DCM File Comparison |
150 | 102 | ```python |
151 | | -# Union of two DCM objects |
152 | | -combined_dcm = dcm1 | dcm2 |
| 103 | +# Find differences between calibrations |
| 104 | +modified = old_dcm % new_dcm |
| 105 | +print(modified.parameters.keys()) # Changed parameters |
153 | 106 |
|
154 | | -# Difference between two DCM objects |
155 | | -difference_dcm = dcm1 - dcm2 |
| 107 | +# Merge calibrations |
| 108 | +combined = dcm1 | dcm2 |
| 109 | +``` |
156 | 110 |
|
157 | | -# Intersection of two DCM objects |
158 | | -intersection_dcm = dcm1 & dcm2 |
| 111 | +## Supported Data Types |
159 | 112 |
|
160 | | -# Modifications between two DCM objects |
161 | | -modifications_dcm = dcm1 % dcm2 |
162 | | -``` |
| 113 | +- Parameters (FESTWERT) |
| 114 | +- Parameter Blocks (FESTWERTEBLOCK) |
| 115 | +- Characteristic Lines (KENNLINIE/FESTKENNLINIE/GRUPPENKENNLINIE) |
| 116 | +- Characteristic Maps (KENNFELD/FESTKENNFELD/GRUPPENKENNFELD) |
| 117 | +- Distributions (STUETZSTELLENVERTEILUNG) |
| 118 | +- Text Strings (TEXTSTRING) |
163 | 119 |
|
164 | 120 | ## Dependencies |
165 | 121 |
|
166 | | -- Python >= 3.11 |
167 | | -- [NumPy](https://numpy.org/) >= 1.20.0 |
168 | | -- [Pandas](https://pandas.pydata.org/) >= 1.5.0 |
169 | | -- [Matplotlib](https://matplotlib.org/) >= 3.0.0 |
170 | | -- [OpenPyXL](https://openpyxl.readthedocs.io/en/stable/) >= 3.1.0 |
| 122 | +- NumPy ≥ 1.20.0 |
| 123 | +- Pandas ≥ 1.5.0 |
| 124 | +- Matplotlib ≥ 3.0.0 |
| 125 | +- OpenPyXL ≥ 3.1.0 |
171 | 126 |
|
172 | 127 | ## License |
173 | 128 |
|
174 | | -This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 129 | +MIT License |
175 | 130 |
|
176 | 131 | ## Contributing |
177 | 132 |
|
178 | | -Contributions are welcome! Please follow these steps: |
| 133 | +Contributions welcome! Please format code with [ruff](https://docs.astral.sh/ruff/) before submitting PRs. |
179 | 134 |
|
180 | | -1. Fork the repository. |
181 | | -2. Create a new branch (`git checkout -b feature/YourFeature`). |
182 | | -3. Commit your changes (`git commit -am 'Add new feature'`). |
183 | | -4. Push to the branch (`git push origin feature/YourFeature`). |
184 | | -5. Create a new Pull Request. |
| 135 | +## Contact |
185 | 136 |
|
186 | | -Please ensure that your code adheres to the existing style and that all tests pass. |
| 137 | +- Author: c0sogi |
| 138 | +- Email: dcas@naver.com or cosogi1@gmail.com |
187 | 139 |
|
188 | | -## Contact |
| 140 | +Feel free to reach out for questions or suggestions. |
189 | 141 |
|
190 | | -Author: c0sogi |
191 | | -Email: [dcas@naver.com](mailto:dcas@naver.com) or [cosogi1@gmail.com](mailto:cosogi1@gmail.com) |
| 142 | +--- |
192 | 143 |
|
193 | | -Feel free to reach out for questions or discussions. |
| 144 | +For detailed documentation and examples, visit our [GitHub repository](https://github.com/c0sogi/python-dcm). |
0 commit comments