In [4]:
import pyfas as fa
import pandas as pd
import matplotlib.pyplot as plt
pd.options.display.max_colwidth = 120

OLGA ppl files, examples and howto

For an tpl file the following methods are available:

  • filter_data - return a filtered subset of trends
  • extract - extract a single trend variable
  • to_excel - dump all the data to an excel file

The usual workflow should be:

  1. Load the correct tpl
  2. Select the desired variable(s)
  3. Extract the results or dump all the variables to an excel file
  4. 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:


In [5]:
ppl_path = '../../pyfas/test/test_files/'
fname = 'FC1_rev01.ppl'
ppl = fa.Ppl(ppl_path+fname)

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.


In [6]:
ppl.filter_data('PT')


Out[6]:
{4: "PT 'SECTION:' 'BRANCH:' 'old_offshore' '(PA)' 'Pressure'\n",
 12: "PT 'SECTION:' 'BRANCH:' 'riser' '(PA)' 'Pressure'\n",
 20: "PT 'SECTION:' 'BRANCH:' 'new_offshore' '(PA)' 'Pressure'\n",
 28: "PT 'SECTION:' 'BRANCH:' 'to_vent' '(PA)' 'Pressure'\n",
 36: "PT 'SECTION:' 'BRANCH:' 'dry' '(PA)' 'Pressure'\n",
 44: "PT 'SECTION:' 'BRANCH:' 'tiein_spool' '(PA)' 'Pressure'\n"}

The same outpout can be reported as a pandas dataframe:


In [7]:
pd.DataFrame(ppl.filter_data('PT'), index=("Profiles",)).T


Out[7]:
Profiles
4 PT 'SECTION:' 'BRANCH:' 'old_offshore' '(PA)' 'Pressure'\n
12 PT 'SECTION:' 'BRANCH:' 'riser' '(PA)' 'Pressure'\n
20 PT 'SECTION:' 'BRANCH:' 'new_offshore' '(PA)' 'Pressure'\n
28 PT 'SECTION:' 'BRANCH:' 'to_vent' '(PA)' 'Pressure'\n
36 PT 'SECTION:' 'BRANCH:' 'dry' '(PA)' 'Pressure'\n
44 PT 'SECTION:' 'BRANCH:' 'tiein_spool' '(PA)' 'Pressure'\n

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:


In [8]:
pd.DataFrame(ppl.filter_data("TM"), index=("Profiles",)).T


Out[8]:
Profiles
5 TM 'SECTION:' 'BRANCH:' 'old_offshore' '(C)' 'Fluid temperature'\n
13 TM 'SECTION:' 'BRANCH:' 'riser' '(C)' 'Fluid temperature'\n
21 TM 'SECTION:' 'BRANCH:' 'new_offshore' '(C)' 'Fluid temperature'\n
29 TM 'SECTION:' 'BRANCH:' 'to_vent' '(C)' 'Fluid temperature'\n
37 TM 'SECTION:' 'BRANCH:' 'dry' '(C)' 'Fluid temperature'\n
45 TM 'SECTION:' 'BRANCH:' 'tiein_spool' '(C)' 'Fluid temperature'\n

In [9]:
pd.DataFrame(ppl.filter_data("PT"), index=("Profiles",)).T


Out[9]:
Profiles
4 PT 'SECTION:' 'BRANCH:' 'old_offshore' '(PA)' 'Pressure'\n
12 PT 'SECTION:' 'BRANCH:' 'riser' '(PA)' 'Pressure'\n
20 PT 'SECTION:' 'BRANCH:' 'new_offshore' '(PA)' 'Pressure'\n
28 PT 'SECTION:' 'BRANCH:' 'to_vent' '(PA)' 'Pressure'\n
36 PT 'SECTION:' 'BRANCH:' 'dry' '(PA)' 'Pressure'\n
44 PT 'SECTION:' 'BRANCH:' 'tiein_spool' '(PA)' 'Pressure'\n

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]:
dict_keys([12, 13])

while the label attibute stores the variable type:


In [12]:
ppl.label[13]


Out[12]:
"TM 'SECTION:' 'BRANCH:' 'riser' '(C)' 'Fluid temperature'"

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:


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