Cantera / enhancements

Repository for proposed and ongoing enhancements to Cantera
11 stars 5 forks source link

HTML formatting for SolutionArray Jupyter output #170

Open ischoegl opened 1 year ago

ischoegl commented 1 year ago

Abstract

With Cantera/cantera#1462, SolutionArray gained a formatted summary/representation, for example a FreeFlame object can be inspected as:

In [5]: f.to_array()
Out[5]:
        grid  velocity        T         D           H2  ...          HO2         H2O2        AR           N2
0    0.00000  0.727045   300.00  1.338612  9.47832e-03  ...  2.80753e-18 -1.59615e-17  0.853758 -1.71506e-19
1    0.00600  0.727045   300.00  1.338612  9.47832e-03  ...  1.83931e-16 -1.55774e-17  0.853758  1.51106e-19
2    0.01200  0.727045   300.00  1.338612  9.47832e-03  ...  6.68745e-17 -1.69521e-17  0.853758 -8.89406e-19
3    0.01500  0.727045   300.00  1.338612  9.47832e-03  ...  8.63558e-17 -9.43632e-18  0.853758  5.01373e-18
4    0.01650  0.727045   300.00  1.338612  9.47831e-03  ...  5.24568e-17  1.90509e-18  0.853758 -2.03546e-18
..       ...       ...      ...       ...          ...  ...          ...          ...       ...          ...
135  0.03300  4.148673  1858.59  0.234589  4.06486e-06  ...  8.51858e-07  5.07872e-08  0.853841 -1.13466e-15
136  0.03600  4.149756  1859.12  0.234527  3.61223e-06  ...  8.28391e-07  4.87767e-08  0.853841 -1.14964e-15
137  0.04200  4.150466  1859.46  0.234487  3.32514e-06  ...  8.14719e-07  4.75217e-08  0.853841 -1.12934e-15
138  0.04800  4.150702  1859.58  0.234474  3.23178e-06  ...  8.10511e-07  4.71187e-08  0.853841 -1.13340e-15
139  0.06000  4.150702  1859.58  0.234474  3.23178e-06  ...  8.10511e-07  4.71187e-08  0.853841 -1.13340e-15

[140 rows x 14 components; state='TDY']

The output formatting is inspired by pandas' DataFrame formatting for terminals. Similar to pandas' behavior, the above output could be extended to creating HTML formatted output when Jupyter is used.

On Jupyter, ``` f.to_array().to_pandas() ``` produces
grid velocity T density Y_H2 Y_H Y_O Y_O2 Y_OH Y_H2O Y_HO2 Y_H2O2 Y_AR Y_N2
0 0.0000 0.727045 300.000000 1.338612 0.009478 1.001306e-17 -1.218188e-16 0.136764 -6.255833e-18 -4.651697e-19 2.807527e-18 -1.596152e-17 0.853758 -1.715061e-19
1 0.0060 0.727045 300.000000 1.338612 0.009478 4.160246e-22 -8.545371e-17 0.136764 -1.426867e-19 -4.616339e-17 1.839306e-16 -1.557736e-17 0.853758 1.511059e-19
2 0.0120 0.727045 300.000000 1.338612 0.009478 -1.111190e-22 -5.987089e-17 0.136764 -9.186857e-20 -7.358939e-17 6.687452e-17 -1.695206e-17 0.853758 -8.894063e-19
3 0.0150 0.727045 300.000000 1.338612 0.009478 8.584904e-23 -4.302447e-17 0.136764 -5.268582e-21 1.452886e-16 8.635578e-17 -9.436319e-18 0.853758 5.013727e-18
4 0.0165 0.727045 300.000000 1.338612 0.009478 -3.950800e-22 -1.537121e-17 0.136764 -1.554119e-19 7.344556e-15 5.245678e-17 1.905086e-18 0.853758 -2.035465e-18
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
135 0.0330 4.148673 1858.589950 0.234589 0.000004 1.761981e-07 3.176888e-05 0.063450 5.089945e-04 8.216367e-02 8.518582e-07 5.078716e-08 0.853841 -1.134663e-15
136 0.0360 4.149756 1859.118289 0.234527 0.000004 1.481708e-07 2.830112e-05 0.063462 4.808296e-04 8.218310e-02 8.283907e-07 4.877670e-08 0.853841 -1.149641e-15
137 0.0420 4.150466 1859.464840 0.234487 0.000003 1.312334e-07 2.609431e-05 0.063471 4.619602e-04 8.219592e-02 8.147194e-07 4.752173e-08 0.853841 -1.129344e-15
138 0.0480 4.150702 1859.579882 0.234474 0.000003 1.258723e-07 2.537544e-05 0.063474 4.556363e-04 8.220018e-02 8.105112e-07 4.711874e-08 0.853841 -1.133396e-15
139 0.0600 4.150702 1859.579882 0.234474 0.000003 1.258723e-07 2.537544e-05 0.063474 4.556363e-04 8.220018e-02 8.105112e-07 4.711874e-08 0.853841 -1.133396e-15

140 rows × 14 columns

where satisfactory output formatting for `SolutionArray` itself would require some tweaks.

Motivation

Describe the need for the proposed change:

Possible Solutions

The basic infrastructure is already in place in C++; the only missing step is a conversion to a html formatted table used by a new SolutionArray._repr_html_() method.

References