Hello guys,
I'm right now in the middle of a master's degree in Data Science and I'm starting to work on little projects to practise my Python skills.
(If you can code properly, maybe you think my code is shit-code... I won't blame you for that).
The one I'm about to present might be interesting:
The thing is that everytime we need to modify an axis lot's of people here take for granted that linear-interpolating the map values for them is the best approach. But it's not.
I mean, myself and some of you maybe fine tune individual values by eye to try to overcome the phenomenon I'm explaining below.
You see, our ECU Maps are indeed a type of function called "Piecewise linear funcion". VAG Engineers had to make the compromise to recreate real life beheavour by a set of points.
They had 2 options here:

Left) They sample X points out of the real funcion and create the map with them as a piecewise linear function.
Right) They average the function between an endpoint tangent piecewise and a midpoint tangent one. I hope they did this.
If you do the left approach you're introducing error (quantization error), sign of it depending on function's convexity/concavity in that point, as you can clearly see below:

Now, things get worse if you re-define the axis and linear interpolate map values.
Let's imagine original axis to have setpoints on int values and you deceide to offset them by 0.5... Look at this simple example, y = x^2.

Blue is the real function.
Orange, the original piecewise from our ECUs.
The thicker segments, the new resultant interpolation. (Big positive error for the orange)
And what about the green one? Pretty good results, ah?
It's a recreation of the original function defined by its original setpoints.
I tried several approaches and this one threw the best results, "PCHIP Splines" (Piecewise Cubic Hermite Interpolating Polynomial).
A special kind of splines much less likely to overshoot.
If we place our new axis setpoints and extract their value from this PCHIP curve, we'll get a much better recreation of the original function and will avoid the vast majority of the error.
If we used the straight forward method of just linear interpolation, we'd be making error once (if engineers took the procedure on the right image above) or twice (if they took the left one).
So I came up with the idea of making an "enhanced" map inter/extrapolator... And yep, extrapolator, cause you can see PCHIP could perform better than linear for extrapolation too:

(Anyways, you'll can always choose which option, linear vs pchip, you prefer for each interpolation and extrapolation, cause sometimes pchip show strange beheavour for extrapolation. You'll can evaluate it on al final graph).

It'll show you, graphically and numerically, how important each original setpoint is, in case you want to delete one to put it outside the current defined zone instead of making a whole new one:
For the moment it only works for 2D, but I'm planning to make a 3D version.
Take this just as a demo.
Here's my GitHub repository just in case any of you is bored enough to give it a try:
https://github.com/Diegogp92/ECU-Map-Inter-Extrapolator/My initial intention was to generate a GUI integrated in an exe with Tkinter + Pyinstaller. However, I was forced to include all libraries I used and they weight +300MB, which I consider unacceptable for a program like this. I know I could just import the parts of the libraries I use rather than whole ones but I don't know, I felt it wasn't the right approach... Any ideas?
So I deceided to use a notebook + Google Colab instead (You can download it from the github above, the .ipynb. It comes with instructions and I tried to make it as much user friendly as possible and I suggest to colapse all "Code" markdowns, you don't need them.)
In case you never used colab, I attach a PDF with instructions for this too.
And please, feel free to post here what you think of this tool.