In [4]:
import pyfas as fa
import pandas as pd
import matplotlib.pyplot as plt
pd.options.display.max_colwidth = 120
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 [5]:
ppl_path = '../../pyfas/test/test_files/'
fname = 'FC1_rev01.ppl'
ppl = fa.Ppl(ppl_path+fname)
As for tpl files, a ppl file may contain hundreds of profiles, in particular for complex networks. For this reason a filtering method is quite useful.
The easiest way is to filter on all the profiles using patters, the command ppl.filter_trends("PT")
filters all the pressure profiless (or better, all the profiles with "PT" in the description, if you have defined a temperature profile in the position "PTTOPSIDE", for example, this profile will be selected too).
The resulting python dictionaly will have a unique index for each filtered profile that can be used to identify the interesting profile(s).
In case of an emply pattern all the available profiles will be reported.
In [6]:
ppl.filter_data('PT')
Out[6]:
The same outpout can be reported as a pandas dataframe:
In [7]:
pd.DataFrame(ppl.filter_data('PT'), index=("Profiles",)).T
Out[7]:
To dump all the variables in an excel file use ppl.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 pressure and the temperature profile of the branch riser
:
In [8]:
pd.DataFrame(ppl.filter_data("TM"), index=("Profiles",)).T
Out[8]:
In [9]:
pd.DataFrame(ppl.filter_data("PT"), index=("Profiles",)).T
Out[9]:
Our targets are:
variable 13 for the temperature
and
variable 12 for the pressure
Now we can proceed with the data extraction:
In [10]:
ppl.extract(13)
ppl.extract(12)
The ppl object now has the two profiles available in the data
attribute:
In [11]:
ppl.data.keys()
Out[11]:
while the label attibute stores the variable type:
In [12]:
ppl.label[13]
Out[12]:
The ppl data structure at the moment contains:
ppl.data[variable_index][0]
ppl.data[variable_index][1][0]
ppl.data[variable_index][1][-1]
In other words the first index is the variable, the second is 0 for the geometry and 1 for the data, the last one identifies the timestep.
The results available in the data attribute are numpy arrays and can be easily manipulated and plotted:
In [13]:
%matplotlib inline
geometry = ppl.data[12][0]
pt_riser = ppl.data[12][1]
tm_riser = ppl.data[13][1]
def ppl_plot(geo, v0, v1, ts):
fig, ax0 = plt.subplots(figsize=(12, 7));
ax0.grid(True)
p0, = ax0.plot(geo, v0[ts])
ax0.set_ylabel("[C]", fontsize=16)
ax0.set_xlabel("[m]", fontsize=16)
ax1 = ax0.twinx()
p1, = ax1.plot(geo, v1[ts]/1e5, 'r')
ax1.grid(False)
ax1.set_ylabel("[bara]", fontsize=16)
ax1.tick_params(axis="both", labelsize=16)
ax1.tick_params(axis="both", labelsize=16)
plt.legend((p0, p1), ("Temperature profile", "Pressure profile"), loc=3, fontsize=16)
plt.title("P and T for case FC1", size=20);
To plot the last timestep:
In [14]:
ppl_plot(geometry, tm_riser, pt_riser, -1)
The time can also be used as parameter:
In [15]:
import ipywidgets.widgets as widgets
from ipywidgets import interact
timesteps=len(tm_riser)-1
@interact
def ppl_plot(ts=widgets.IntSlider(min=0, max=timesteps)):
fig, ax0 = plt.subplots(figsize=(12, 7));
ax0.grid(True)
p0, = ax0.plot(geometry, tm_riser[ts])
ax0.set_ylabel("[C]", fontsize=16)
ax0.set_xlabel("[m]", fontsize=16)
ax0.set_ylim(10, 12)
ax1 = ax0.twinx()
ax1.set_ylim(90, 130)
p1, = ax1.plot(geometry, pt_riser[ts]/1e5, 'r')
ax1.grid(False)
ax1.set_ylabel("[bara]", fontsize=16)
ax1.tick_params(axis="both", labelsize=16)
ax1.tick_params(axis="both", labelsize=16)
plt.legend((p0, p1), ("Temperature profile", "Pressure profile"), loc=3, fontsize=16)
plt.title("P and T for case FC1 @ timestep {}".format(ts), size=20);
The above plot has an interactive widget if executed