PyPontem Documentation

Contents:

  • Introduction to pypontem
  • Installation
  • TPL parsing
    • Class & Method Description
    • Code Examples
  • PPL parsing
    • Class & Method Description
    • Code Examples
  • Input matrix templates
  • Utilities
PyPontem Documentation
  • pypontem
  • TPL Modules
  • View codes on GitHub

TPL Parsing

1. pypontem tpl parsing code examples

tplParser: a class which holds the tpl parser functions

Importing pypontem package

In [2]:
from pypontem.tpl.tplparser import tplParser

Instantiating a tplParser object

In [3]:
tpl = tplParser('data/example_tpl.tpl')

metadata

Extracts metadata from the content stored in the object and returns it as a pandas DataFrame.

In [4]:
metadata = tpl.metadata
print(metadata)
                version         Input file                pvt  \
0  OLGA 2015.3.1.142077  Simulation.genkey  ./Fluid_Tuned.tab   

                time project       title            author geometry  
0  24-05-10 17:49:57    OLGA  Basic Case  Pontem Analytics        M  

branch_names

Extracts branch names from the content stored in the tpl file.

In [5]:
branch_names = tpl.branch_names
print(branch_names)
["'JUMPER-1'", "'FLOWLINE-1'", "'FLOWLINE-2'", "'JUMPER-2'", "'FLOWLINE-3'", "'COILEDTUBING'"]

branch_profiles

Extracts and displays elevation for a specific branch or all branches in the file.

In [6]:
branch_profiles = tpl.branch_profiles.get("FLOWLINE-2")
print(branch_profiles)
{ 'FLOWLINE-2':    Lengths_(m)  Elevations_(m)
0     0.000000    -1920.240000
1   453.518520    -1912.620000
2   907.037040    -1905.000000
3  1213.865904    -1901.189991
4  1520.694768    -1897.380000
5  1962.662832    -1895.475001
6  2404.630897    -1893.570003
7  2846.598961    -1891.665004
8  3288.567026    -1889.760005}

n_vars

Parses the number of variables from a given file path.

In [26]:
n_vars = tpl.n_vars
print(n_vars)
140

catalog

Extracts variable information from the provided content using a regular expression pattern.

In [7]:
returned_catalog = tpl.catalog
print(returned_catalog.head())
  varname    BRANCH    PIPE NR POSITION out_unit  \
0    QLST  JUMPER-1  PIPE-1  1      NaN  (SM3/S)   
1    QOST  JUMPER-1  PIPE-1  1      NaN  (SM3/S)   
2    QWST  JUMPER-1  PIPE-1  1      NaN  (SM3/S)   
3    QGST  JUMPER-1  PIPE-1  1      NaN  (SM3/S)   
4      GT  JUMPER-1  PIPE-1  1      NaN   (KG/S)   
                            
                                 Description  
0  Liquid volume flow at standard conditions  
1     Oil volume flow at standard conditions  
2   Water volume flow at standard conditions  
3     Gas volume flow at standard conditions  
4                            Total mass flow  
                            

search_catalog:

Searches for variables containing a keyword in their names within a DataFrame.

In [11]:
search_catalog = tpl.search_catalog('QLST')
print(search_catalog.head())
   varname      BRANCH    PIPE NR out_unit  \
0     QLST    JUMPER-1  PIPE-1  1  (SM3/S)   
13    QLST  FLOWLINE-1   LPL-4  1  (SM3/S)   
25    QLST  FLOWLINE-2   LPL-5  1  (SM3/S)   
26    QLST  FLOWLINE-2   LPL-6  1  (SM3/S)   
27    QLST  FLOWLINE-2   LPL-7  1  (SM3/S)   
                            
                                  Description  
0   Liquid volume flow at standard conditions  
13  Liquid volume flow at standard conditions  
25  Liquid volume flow at standard conditions  
26  Liquid volume flow at standard conditions  
27  Liquid volume flow at standard conditions  
                            

extract_trends

Search for variables in the DataFrame based on variable names, branches, and pipe names, and display their information.

1. Extracting trends from a DataFrame created using a csv file.

In [17]:
import pandas as pd
input_data = pd.read_csv('data/test_inputs.csv')
trends = tpl.extract_trend(input_data)
print(trends.head())
             PT_psig_JUMPER-1  TM_degK_FLOWLINE-1
Time_(hour)                                      
0.0                  1442.121             304.671
2.0                  1468.391             304.671
4.0                  1465.278             304.667
6.0                  1463.820             304.669
8.0                  1464.741             304.668

2. Extracting trends from a DataFrame created using a dictionary.

In [10]:
matrix = {"varname":"PT",
              "BRANCH":"JUMPER-1",
              "PIPE":None,
              "out_unit":"psig",
              "time_unit":"h"}
            
 matrix_pd = pd.DataFrame(matrix, index=[0])
 trends = tpl.extract_trend(matrix_pd)
 print(trends.head(3))
          PT_psig_JUMPER-1
    Time_(h)                  
    0.0               1442.121
    2.0               1468.391
    4.0               1465.278
    

calc_average

Calculate the average of values in the DataFrame between the specified start and end indices.

1. Calculating averages from a DataFrame created using a csv file.

In [20]:
average = tpl.calc_average(input_data,start_index=1,end_index=4)
print(average)
PT_psig_JUMPER-1      1459.9025
TM_degK_FLOWLINE-1     304.6695
dtype: float64

2. Calculating averages from a DataFrame created using a dictionary.

In [12]:
average_dict = tpl.calc_average(matrix_pd, start_index=1,end_index=4)
 print(average_dict)
PT_psig_JUMPER-1    1459.9025
  dtype: float64
  

3. Users can also calculate the average of any quantity based on the time units specified in the input matrix. The argument n_timeunits takes an integer value to represent the number of time units to be extracted. Note: a positive value, say x, denotes the first x time units and a negative value, say -x, denotes the last x time units. In the examples below,we extract the first 4 and last 4 hours from a tpl file

In [32]:
 average_first_n_hours = tpl.calc_average(matrix_pd, n_timeunits=4)
 average_last_n_hours = tpl.calc_average(matrix_pd, n_timeunits=-4)
 print("The average of the first 4 hours is:")
 print(average_first_n_hours)
 print("The average of the last 4 hours is:")
 print(average_last_n_hours)

The average of the first 4 hours is:

PT_psig_JUMPER-1    1458.596667
    dtype: float64
    

The average of the last 4 hours is:

PT_psig_JUMPER-1    1464.553667
      dtype: float64
      

2. pypontem tpl batch parsing code examples

tplBatchParser: a class to handle batches of tpl files

Note that: tpl batch parsing functionality only works for files of the same batch of simulations with the same branch names and structure, otherwise this will raise an error. For illustration purposes below, we have duplicated the same file

Importing tpl batch parser class

In [21]:
from pypontem.tpl.tplparser import tplBatchParser

Instantiating an object with a list of tpl files

In [22]:
files = ['data/example_tpl.tpl','data/example_tpl.tpl']
tplbatch = tplBatchParser(files)

extract_trends:

Function to extract trends from a batch of tpl files

1. Extracting batch trends from a DataFrame created using a csv file.

In [24]:
batch_trends = tplbatch.extract_trends(input_data)
print(batch_trends.head(3))
             PT_psig_JUMPER-1_example_tpl.tpl_x  \
Time_(hour)                                       
0.0                                    1442.121   
2.0                                    1468.391   
4.0                                    1465.278   

             TM_degK_FLOWLINE-1_example_tpl.tpl_x  \
Time_(hour)                                         
0.0                                       304.671   
2.0                                       304.671   
4.0                                       304.667   

             PT_psig_JUMPER-1_example_tpl.tpl_y  \
Time_(hour)                                       
0.0                                    1442.121   
2.0                                    1468.391   
4.0                                    1465.278   

             TM_degK_FLOWLINE-1_example_tpl.tpl_y  
Time_(hour)                                        
0.0                                       304.671  
2.0                                       304.671  
4.0                                       304.667  

2. Extracting batch trends from a DataFrame created using a dictionary.

In [16]:
batch_trends_dict = tplbatch.extract_trends(matrix_pd)
 print(batch_trends_dict.head(3))
          PT_psig_JUMPER-1_example_tpl.tpl_x  \
  Time_(h)                                       
  0.0                                 1442.121   
  2.0                                 1468.391   
  4.0                                 1465.278   
  
            PT_psig_JUMPER-1_example_tpl.tpl_y  
  Time_(h)                                      
  0.0                                 1442.121  
  2.0                                 1468.391  
  4.0                                 1465.278  
  

calc_averages

Calculates the average of values in the DataFrame up to the specified index or of the last n values.

1. Calculating batch averages from a DataFrame created using a csv file.

In [25]:
batch_average = tplbatch.calc_averages(input_data,start_index=1,end_index=4)
print(batch_average)
                                        Average
PT_psig_JUMPER-1_example_tpl.tpl_x    1459.9025
TM_degK_FLOWLINE-1_example_tpl.tpl_x   304.6695
PT_psig_JUMPER-1_example_tpl.tpl_y    1459.9025
TM_degK_FLOWLINE-1_example_tpl.tpl_y   304.6695

2. Calculating batch averages from a DataFrame created using a dictionary.

In [17]:
batch_average = tplbatch.calc_averages(matrix_pd,start_index=1,end_index=4)
 print(batch_average)
                                      Average
  PT_psig_JUMPER-1_example_tpl.tpl_x  1459.9025
  PT_psig_JUMPER-1_example_tpl.tpl_y  1459.9025
  
Previous Next

© Copyright 2025, Pontem Analytics.

Built with Sphinx using a theme provided by Read the Docs.