Output¶
In [1]:
import numpy as np
import pandas as pd
from tabulate import tabulate
from streng.common.io.output import OutputTable, OutputString, OutputExtended
OutputTable¶
some example data¶
In [2]:
data = [{'__iteration': 1,
'x_y': 0.04213429287708525,
'y_y': 1310.8730715333027,
'x_u': 0.44886,
'y_u': 1311.3866666666665,
'kinel': 1.2627555238564436,
'kel': 31111.785247171465,
'k_06': 24639.615704484408,
'error': 0.26267331521364284},
{'__iteration': 2,
'x_y': 0.05395737709629134,
'y_y': 1329.4890360745674,
'x_u': 0.44886,
'y_u': 1329.4890360745674,
'kinel': -91.76544991341024,
'kel': 24639.615704484408,
'k_06': 24476.018099972942,
'error': 0.006683995895216576},
{'__iteration': 3,
'x_y': 0.05434285482397955,
'y_y': 1330.0966982759253,
'x_u': 0.44886,
'y_u': 1330.0966982759253,
'kinel': -94.94217563576123,
'kel': 24476.018099972942,
'k_06': 24469.75466696404,
'error': 0.0002559663181812895},
{'__iteration': 4,
'x_y': 0.05435772305859232,
'y_y': 1330.1201474985282,
'x_u': 0.44886,
'y_u': 1330.1201474985282,
'kinel': -95.064891451666,
'kel': 24469.75466696404,
'k_06': 24469.51314473135,
'error': 9.870332575089462e-06},
{'__iteration': 5,
'x_y': 0.05435829655145874,
'y_y': 1330.1210519911244,
'x_u': 0.44886,
'y_u': 1330.1210519911244,
'kinel': -95.0696250854122,
'kel': 24469.51314473135,
'k_06': 24469.503828907287,
'error': 3.807116044736897e-07}]
using tabulate to show data as markdown table¶
In [3]:
print(tabulate(data, headers='keys', tablefmt="pipe", floatfmt=".3E"))
| __iteration | x_y | y_y | x_u | y_u | kinel | kel | k_06 | error |
|------------:|----------:|----------:|----------:|----------:|-----------:|----------:|----------:|----------:|
| 1 | 4.213E-02 | 1.311E+03 | 4.489E-01 | 1.311E+03 | 1.263E+00 | 3.111E+04 | 2.464E+04 | 2.627E-01 |
| 2 | 5.396E-02 | 1.329E+03 | 4.489E-01 | 1.329E+03 | -9.177E+01 | 2.464E+04 | 2.448E+04 | 6.684E-03 |
| 3 | 5.434E-02 | 1.330E+03 | 4.489E-01 | 1.330E+03 | -9.494E+01 | 2.448E+04 | 2.447E+04 | 2.560E-04 |
| 4 | 5.436E-02 | 1.330E+03 | 4.489E-01 | 1.330E+03 | -9.506E+01 | 2.447E+04 | 2.447E+04 | 9.870E-06 |
| 5 | 5.436E-02 | 1.330E+03 | 4.489E-01 | 1.330E+03 | -9.507E+01 | 2.447E+04 | 2.447E+04 | 3.807E-07 |
show data as pandas dataframe¶
In [4]:
df = pd.DataFrame(data=data, columns=list(data[0].keys()))
df
Out[4]:
__iteration | x_y | y_y | x_u | y_u | kinel | kel | k_06 | error | |
---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0.042134 | 1310.873072 | 0.44886 | 1311.386667 | 1.262756 | 31111.785247 | 24639.615704 | 2.626733e-01 |
1 | 2 | 0.053957 | 1329.489036 | 0.44886 | 1329.489036 | -91.765450 | 24639.615704 | 24476.018100 | 6.683996e-03 |
2 | 3 | 0.054343 | 1330.096698 | 0.44886 | 1330.096698 | -94.942176 | 24476.018100 | 24469.754667 | 2.559663e-04 |
3 | 4 | 0.054358 | 1330.120147 | 0.44886 | 1330.120147 | -95.064891 | 24469.754667 | 24469.513145 | 9.870333e-06 |
4 | 5 | 0.054358 | 1330.121052 | 0.44886 | 1330.121052 | -95.069625 | 24469.513145 | 24469.503829 | 3.807116e-07 |
Class usage¶
In [17]:
print(OutputTable.__doc__)
An output table given as a list of dictionaries that can be presented (and used) as
a pandas dataframe or a markdown table
Attributes:
data (List[dict]): A list of dictionaries
In [18]:
ot = OutputTable(data=data)
show data as markdown table¶
In [8]:
print(ot.to_markdown)
| __iteration | x_y | y_y | x_u | y_u | kinel | kel | k_06 | error |
|------------:|----------:|----------:|----------:|----------:|-----------:|----------:|----------:|----------:|
| 1 | 4.213E-02 | 1.311E+03 | 4.489E-01 | 1.311E+03 | 1.263E+00 | 3.111E+04 | 2.464E+04 | 2.627E-01 |
| 2 | 5.396E-02 | 1.329E+03 | 4.489E-01 | 1.329E+03 | -9.177E+01 | 2.464E+04 | 2.448E+04 | 6.684E-03 |
| 3 | 5.434E-02 | 1.330E+03 | 4.489E-01 | 1.330E+03 | -9.494E+01 | 2.448E+04 | 2.447E+04 | 2.560E-04 |
| 4 | 5.436E-02 | 1.330E+03 | 4.489E-01 | 1.330E+03 | -9.506E+01 | 2.447E+04 | 2.447E+04 | 9.870E-06 |
| 5 | 5.436E-02 | 1.330E+03 | 4.489E-01 | 1.330E+03 | -9.507E+01 | 2.447E+04 | 2.447E+04 | 3.807E-07 |
show data as pandas dataframe¶
In [9]:
ot.to_panda_dataframe
Out[9]:
__iteration | x_y | y_y | x_u | y_u | kinel | kel | k_06 | error | |
---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0.042134 | 1310.873072 | 0.44886 | 1311.386667 | 1.262756 | 31111.785247 | 24639.615704 | 2.626733e-01 |
1 | 2 | 0.053957 | 1329.489036 | 0.44886 | 1329.489036 | -91.765450 | 24639.615704 | 24476.018100 | 6.683996e-03 |
2 | 3 | 0.054343 | 1330.096698 | 0.44886 | 1330.096698 | -94.942176 | 24476.018100 | 24469.754667 | 2.559663e-04 |
3 | 4 | 0.054358 | 1330.120147 | 0.44886 | 1330.120147 | -95.064891 | 24469.754667 | 24469.513145 | 9.870333e-06 |
4 | 5 | 0.054358 | 1330.121052 | 0.44886 | 1330.121052 | -95.069625 | 24469.513145 | 24469.503829 | 3.807116e-07 |
retrieve value from output table¶
In [10]:
ot.retrieve(search_field='__iteration',
search_value=2,
find_field='kinel')
Out[10]:
-91.76544991341024
retrieve column to list¶
In [11]:
ot.retrieve_column_to_list('x_y')
Out[11]:
[0.04213429287708525,
0.05395737709629134,
0.05434285482397955,
0.05435772305859232,
0.05435829655145874]
OutputString¶
coming soon…see bilin notebook
OutputExtended¶
coming soon…see bilin notebook