In [1]:
import pyfas as fa
import pandas as pd
import matplotlib.pyplot as plt
For an tpl file the following methods are available:
The usual workflow should be:
To load a specific tpl file the correct path and filename have to be provided:
In [2]:
tpl_path = '../../pyfas/test/test_files/'
fname = '11_2022_BD.tpl'
tpl = fa.Tpl(tpl_path+fname)
A tpl file may contain hundreds of trends, in particular for complex networks. For this reason a filtering method is quite useful. A trend can be specified in an OLGA input files in differnet ways, the identification of a single trend may be not trivial.
The easiest way is to filter all the trends using patters, the command tpl.filter_trends("PT")
filters all the pressure trends (or better, all the trends with "PT" in the description, if you have defined a temperature trend in the position "PTTOPSIDE", for example, this trend will be selected too).
The resulting python dictionaly will have a unique index for each filtered trend that can be used to identify the interesting trend(s).
In case of an emply pattern all the available trends will be reported.
In [3]:
tpl.filter_data('PT')
Out[3]:
or
In [4]:
tpl.filter_data("'POSITION:' 'EXIT'")
Out[4]:
The same outpout can be reported as a pandas dataframe:
In [5]:
pd.DataFrame(tpl.filter_data('PT'), index=("Trends",)).T
Out[5]:
The view_trends
method provides the same info better arranged:
In [18]:
tpl.view_trends('PT')
Out[18]:
To dump all the variables in an excel file use tpl.to_excel()
If no path is provided an excel file with the same name of the tpl file is generated in the working folder. Depending on the tpl size this may take a while.
Once you know the variable(s) index you are interested in (see the filtering paragraph above for more info) you can extract it (or them) and use the data directly in python.
Let's assume you are interested in the inlet pressure and the outlet temperature:
In [17]:
tpl.view_trends('TM')
Out[17]:
In [14]:
tpl.view_trends('PT')
Out[14]:
Our targets are:
variable 11 - TM 'POSITION:' 'EXIT' '(C)' 'Fluid temperature'
and
variable 38 - PT 'POSITION:' 'TUBINGHEAD' '(PA)' 'Pressure'\
Now we can proceed with the data extraction:
In [8]:
# single trend extraction
tpl.extract(11)
tpl.extract(38)
# multiple trends extraction
tpl.extract(12, 37)
The tpl object now has the four trends available in the data
attribute:
In [11]:
tpl.data.keys()
Out[11]:
while the label attibute stores the variable type as a dictionary:
In [15]:
tpl.label
Out[15]:
The results available in the data attribute are numpy arrays and can be easily manipulated and plotted:
In [49]:
%matplotlib inline
pt_inlet = tpl.data[38]
tm_outlet = tpl.data[11]
fig, ax1 = plt.subplots(figsize=(12, 7));
ax1.grid(True)
p0, = ax1.plot(tpl.time/3600, tm_outlet)
ax1.set_ylabel("Outlet T [C]", fontsize=16)
ax1.set_xlabel("Time [h]", fontsize=16)
ax2 = ax1.twinx()
p1, = ax2.plot(tpl.time/3600, pt_inlet/1e5, 'r')
ax2.grid(False)
ax2.set_ylabel("Inlet P [bara]", fontsize=16)
ax1.tick_params(axis="both", labelsize=16)
ax2.tick_params(axis="both", labelsize=16)
plt.legend((p0, p1), ("Outlet T", "Inlet P"), loc=4, fontsize=16)
plt.title("Inlet P and Outlet T for case FC1", size=20);