<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 OLGA ppl files, examples and howto
For an tpl file the following methods are available
Step1:  Profile selection
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.
Step2:  The same outpout can be reported as a pandas dataframe
Step3:  Dump to excel
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.
Extract a specific variable
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
Step4:  Our targets are
Step5:  The ppl object now has the two profiles available in the data attribute
Step6:  while the label attibute stores the variable type
Step7:  Ppl data structure
The ppl data structure at the moment contains
Step8:  To plot the last timestep
Step9:  The time can also be used as parameter
<ASSISTANT_TASK:>
Python Code:
ppl_path = '../../pyfas/test/test_files/'
fname = 'FC1_rev01.ppl'
ppl = fa.Ppl(ppl_path+fname)
Explanation: OLGA ppl files, examples and howto
For an tpl file the following methods are available:
<b>filter_data</b> - return a filtered subset of trends
<b>extract</b> - extract a single trend variable
<b>to_excel</b> - dump all the data to an excel file
The usual workflow should be:
Load the correct tpl
Select the desired variable(s)
Extract the results or dump all the variables to an excel file
Post-process your data in Excel or in the notebook itself
Ppl loading
To load a specific tpl file the correct path and filename have to be provided:
End of explanation
ppl.filter_data('PT')
Explanation: Profile selection
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.
End of explanation
pd.DataFrame(ppl.filter_data('PT'), index=("Profiles",)).T
Explanation: The same outpout can be reported as a pandas dataframe:
End of explanation
pd.DataFrame(ppl.filter_data("TM"), index=("Profiles",)).T
pd.DataFrame(ppl.filter_data("PT"), index=("Profiles",)).T
Explanation: Dump to excel
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.
Extract a specific variable
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:
End of explanation
ppl.extract(13)
ppl.extract(12)
Explanation: Our targets are:
<i>variable 13</i> for the temperature
and  
<i>variable 12</i> for the pressure
Now we can proceed with the data extraction:
End of explanation
ppl.data.keys()
Explanation: The ppl object now has the two profiles available in the data attribute:
End of explanation
ppl.label[13]
Explanation: while the label attibute stores the variable type:
End of explanation
%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);
Explanation: Ppl data structure
The ppl data structure at the moment contains:
the geometry profile of the branch as ppl.data[variable_index][0]
the selected profile at the timestep 0 as ppl.data[variable_index][1][0]
the selected profile at the last timestep as 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.
Data processing
The results available in the data attribute are numpy arrays and can be easily manipulated and plotted:
End of explanation
ppl_plot(geometry, tm_riser, pt_riser, -1)
Explanation: To plot the last timestep:
End of explanation
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);
Explanation: The time can also be used as parameter:
End of explanation
<END_TASK>