Reports until 16:17, Friday 12 July 2024
Controls Optimal Controls
Lee McCuller - posted 16:17, Friday 12 July 2024 (11735)
Vega-Altair plotter for optimal controls plots

I've wanted to create an example of how to bundle data and plot it through altair for a while. The recent optical controls work has given a good example to start from. Just pushed SHA d4ebcc2d0a7ed into the dev branch.

This adds a notebook vega_plot_AIC.ipynb that loads the pickle of controllers created by the optimal control scanner. After loading, this object is a list of dictionaries. Each dictionary maps a set of column-keys to values. Some of those values are floats, like the RMS of the figure of merit, or the phase margin, some are strings, like which solver. Some of them are objects (the wield.control.SISO or wield.control.MIMO of the controllers or system) and some of them are arrays of data, like from frequency response functions.

You can then process that list to drop the objects and setup the types of the arrays. You can then load them into a dataframe. I'm using polars as it seem to identify the lists-of-floats well, but pandas might be fine for this. Polars is much more complicated to use, but enforces mannerisms that are very fast.

After loading the data, then you can ship it to a modern plotter like altair. The frequency response functions are very large, so you have to be careful with them, to keep them as arrays. To plot them, you have to "explode", "melt" or "flatten" the arrays into (many) more data columns. Pandas and polars use explode and melt. Altair uses the "transform_flatten". This expands the data so that you can create line plots, but you can't ship expanded data because the resulting json uses too much memory (trust me)

Digression: Some might say I like Altair because it uses the type_action verbiage that my libraries use.

The linked notebook shows the data transform tricks so that this set of plots, around 100MB binary data, can be sent to a browser as JSON and not cause it to grind to a halt. Seems to work, but I haven't been sure.

 

The plots are interactive, you can scroll, zoom, and select points. Getting them to be comparable to Ians matplotlib ones will still be a fair amount of work, but this framework will allow it to happen. Note that altair has very unusual methodologies that are not intuitive, so this is far from a simple example. See their example library at https://altair-viz.github.io/gallery/index.html for more ideas.

We can make selectors based on the H2 vs HiB, or based on iso-zeta lines, and the coloration could use a lot of work (like having the fresponse color on igsq when when iso-zeta is selected). The phase plots could also probably be made to wrap the phase.

Anyway, it's pretty cool. I don't intend to work on this further except to help any of you take it from this demo into a more fully-nice setup.

Hmm - something about the log is causing the html attachement to time-out and fail.

Use the direct download link git download link instead (and then open the local file in browser).

Non-image files attached to this report