PVT Object¶
You can define a PVT object by providing a tabulated data indexed by pressure.
In [3]:
Copied!
from pvtpy.pvt import PVT
from pvtpy.units import Pressure
import numpy as np
import pandas as pd
from pvtpy.pvt import PVT
from pvtpy.units import Pressure
import numpy as np
import pandas as pd
Define some properties¶
In [4]:
Copied!
p = np.linspace(10,3500,15)
rho = np.linspace(0.8,1.3,15)
tt = np.linspace(90,130,15)
p = np.linspace(10,3500,15)
rho = np.linspace(0.8,1.3,15)
tt = np.linspace(90,130,15)
In [5]:
Copied!
p
p
Out[5]:
array([ 10. , 259.28571429, 508.57142857, 757.85714286, 1007.14285714, 1256.42857143, 1505.71428571, 1755. , 2004.28571429, 2253.57142857, 2502.85714286, 2752.14285714, 3001.42857143, 3250.71428571, 3500. ])
Create the PVT Object by providing a list of ordered pressure and corresponding properties in a dictionary form
In [6]:
Copied!
pvt1 = PVT(pressure=Pressure(value=p.tolist()), fields={'rho':rho.tolist(),'temp':tt.tolist()})
print(type(pvt1))
pvt1 = PVT(pressure=Pressure(value=p.tolist()), fields={'rho':rho.tolist(),'temp':tt.tolist()})
print(type(pvt1))
<class 'pvtpy.pvt.pvt.PVT'>
To export the pvt to a pandas DataFrame
call the df
method
In [7]:
Copied!
print(pvt1.df())
print(pvt1.df())
rho temp pressure 10.000000 0.800000 90.000000 259.285714 0.835714 92.857143 508.571429 0.871429 95.714286 757.857143 0.907143 98.571429 1007.142857 0.942857 101.428571 1256.428571 0.978571 104.285714 1505.714286 1.014286 107.142857 1755.000000 1.050000 110.000000 2004.285714 1.085714 112.857143 2253.571429 1.121429 115.714286 2502.857143 1.157143 118.571429 2752.142857 1.192857 121.428571 3001.428571 1.228571 124.285714 3250.714286 1.264286 127.142857 3500.000000 1.300000 130.000000
The pressure must be ordered either descending or ascending¶
By using the syntax [::-1]
you can reverse the order of a list
In [8]:
Copied!
pvt1_r = PVT(pressure=Pressure(value=p.tolist()[::-1]), fields={'rho':rho.tolist()[::-1],'temp':tt.tolist()[::-1]})
print(pvt1_r.df())
pvt1_r = PVT(pressure=Pressure(value=p.tolist()[::-1]), fields={'rho':rho.tolist()[::-1],'temp':tt.tolist()[::-1]})
print(pvt1_r.df())
rho temp pressure 3500.000000 1.300000 130.000000 3250.714286 1.264286 127.142857 3001.428571 1.228571 124.285714 2752.142857 1.192857 121.428571 2502.857143 1.157143 118.571429 2253.571429 1.121429 115.714286 2004.285714 1.085714 112.857143 1755.000000 1.050000 110.000000 1505.714286 1.014286 107.142857 1256.428571 0.978571 104.285714 1007.142857 0.942857 101.428571 757.857143 0.907143 98.571429 508.571429 0.871429 95.714286 259.285714 0.835714 92.857143 10.000000 0.800000 90.000000
In [9]:
Copied!
try:
p_random = np.random.rand(15)
pvt_error = PVT(pressure=Pressure(value=p_random.tolist()), fields={'rho':rho.tolist(),'temp':tt.tolist()})
except Exception as e:
print(e)
print('Pressure is not sorted. It raises an error')
try:
p_random = np.random.rand(15)
pvt_error = PVT(pressure=Pressure(value=p_random.tolist()), fields={'rho':rho.tolist(),'temp':tt.tolist()})
except Exception as e:
print(e)
print('Pressure is not sorted. It raises an error')
1 validation error for PVT pressure Pressure must be ordered (type=value_error) Pressure is not sorted. It raises an error
Interpolate at a custom Pressure¶
In [10]:
Copied!
pvt1.interpolate([1500,2100])
pvt1.interpolate([1500,2100])
Out[10]:
rho | temp | |
---|---|---|
pressure | ||
1500 | 1.013467 | 107.077364 |
2100 | 1.099427 | 113.954155 |
Interpolate olly certain columns¶
In [11]:
Copied!
pvt1.interpolate([1500,2100, 2500,2700],cols=['temp'])
pvt1.interpolate([1500,2100, 2500,2700],cols=['temp'])
Out[11]:
temp | |
---|---|
pressure | |
1500 | 107.077364 |
2100 | 113.954155 |
2500 | 118.538682 |
2700 | 120.830946 |
In [ ]:
Copied!