XTGeo油藏數值模擬Eclipse模型處理python庫

目錄

1、XTgeo介紹 1

2 數據模型 2

(1)面數據Surface: RegularSurface 2

(2)立方體數據Cube data 3

(3)三維網格及模型屬性 4

(4)井數據well data 5

(5)點數據,多邊形數據 5

3、 使用方法 5

(1)RegularSurface 的使用方法 5

(2)立方體數據的使用方法 6

(3)三維網格模型的使用方法 7

(4)井數據的處理 8

(5)點和多邊形數據 8

4、 接口描述 8

o Subpackages 8

5、 5 參考資料 9

 

 

1、XTgeo介紹

XTGeo地層用c語言寫,python包使用了大量的numpy和pandas以保證數據處理的性能。

XTGeo is Python library to work with surfaces, grids, cubes, wells, etc, possibly in combinations.

 

XTGeo包含的數據模型有規則面數據,網格數據,地震立方體數據,井數據,點數據和多邊形數據,特別適用於不同類型數據的交互操作,比如從模型中提取面,。

·  Regular surfaces, i.e. 2D maps with regular sampling and rotation

·  3D grids (corner-point), supporting several formats such as RMS and Eclipse

·  Support of seismic cubes, using segyio as backend for SEGY format

·  Support of well data, line and polygons (still somewhat immature)

·  Operations between the data types listed above; e.g. slice a surface with a seismic cube

 

官方給出的教程如下,主要是安裝方法、數據模型和輸入輸出格式,使用方法等,其中的使用方法給的例子很少,體現的接口也很少。

 

2 數據模型

(1)面數據Surface: RegularSurface

面數據是結構化二維網格數據,在python中的是numpy對象。

A surface can in principle be represented in various ways. Currently, XTGeo supports a RegularSurface which is commonly used in the oil industry. Due to the regular layout, such surfaces are quite fast to work with and requires small storage (only the Z values array is stored).

RegularSurface is described by:

  • An origin in UTM coordinates, defined as xori and yori
  • An increment in each direction, defined as xinc and yinc
  • A number of columns and rows, where columns follow X and rows follow Y, if a rotation is zero, as ncol and nrow.
  • A rotation of the X axis; in XTGeo the rotation is counter-clockwise from the X (East) axis, in degrees.
  • An yflip indicator. Normally the system is left-handed (with Z axis positive down). If yflip is -1, then the map is right-handed.
  • A 2D array (masked numpy) of values, for a total of ncol * nrow entries. Undefined map nodes are masked. The 2D numpy array is stored in C-order (row-major). Default is 64 bit Float.

RegularSurface

支持的數據導入導出格式是:

(2)立方體數據Cube data

立方體數據可以是地震數據和正交網格的模型數據。Python中的是numpy對象

A Cube is described by:

  • An origin in UTM coordinates, defined as xori, yori and zori
  • An increment in each direction, defined as xinc, yinc and zinc
  • A number of columns, rows and layers, where columns follow X and rows follow Y, if a rotation is zero, as ncol and nrow. Vertically nlay
  • A rotation of the X axis; in XTGeo the rotation is counter-clockwise from the X (East) axis, in degrees.
  • An yflip indicator. Normally the system is left-handed (with Z axis positive down). If yflip is -1, then the cube is right-handed.
  • A 3D array (numpy) of values, for a total of ncol * nrow * nlay entries. All nodes are defined. The 3D numpy array is stored in C-order (row-major). Default is 32 bit Float.

支持的導入導出數據格式有:

cube data format support

(3)三維網格及模型屬性

三維網格包括兩部分,幾何網格部分是簡化版本的角點網格(Grid class),屬性部分是是網格模型上的屬性場(GridProperty class)。

A 3D grid consists of two parts, a geometry which follows a simplified version of a corner-point grid (Grid class), and a number of assosiated properties (GridProperty class):

  • The geometry is stored as pointers to C arrays; hence the geometry itself is not directly accessible in Python. The C arrays are usually named p_coord_v, p_zcorn_v, and p_actnum_v. They are one dimensionial arrays.
  • The grid dimensions are given by ncol * nrow * nlay
  • The properties are stored as 3D masked numpy arrays in python. Undefined cells are masked. The machine order in python is C-order. For historical reasons, the order of the property arrays in C code (when applied) is F-order.

從上述介紹可以看出,網格部分的存儲是C矩陣,因此幾何屬性無法直接在python中獲取,C矩陣的名字分別是p_coord_v, p_zcorn_v和p_actnum_v,它們是一維矩陣。不過新版本好像提供了獲取網格信息的python接口,也是pandas對象。

dataframe=grd.dataframe(), #grid=xtgeo.grid3d.Grid()

網格的維數是· ncol * nrow * nlay

網格屬性場存儲方式是numpy對象,但後面的例子中看起來是pandas對象。

三維模型幾何網格部分支持的導入導出格式是:

3d grid geometry format support

三維模型屬性場支持的導入導出格式有:

3D grid property format support

(4)井數據well data

井數據在python中是pandas dataframe的格式,沒有給據悉的細節。

Well data is stored in python as Pandas dataframe plus some additional metadata.

A special subclass is Blocked Well data.

 

(5)點數據,多邊形數據

In general, Points and Polygons are XYZ data with possible atttributes.

Points and Polygons data is stored in python as Pandas dataframe plus some additional metadata.

The term “Polygons” here is not precise perhaps, at it refers to connected lines which can either form an open polyline or are closed polygon. A Polygons() instance may have a number of individual polygon “pieces”, which are defined by a POLY_ID (default name) column. This design is borrowed from RMS.

 

 

  1. 使用方法

(1)RegularSurface 的使用方法

可以從文件讀取面數據,也可以從三維網格場提取面數據,也可以對面數據進行各種計算。Nupy支持的計算應該都可以執行。

from xtgeo.surface import RegularSurface

# create an instance of a surface, read from file

mysurf = RegularSurface('myfile.gri')  # Irap binary as default

print('Mean is {}'.format(mysurf.values.mean()))

# change date so all values less than 2000 becomes 2000# The values attribute gives the Numpy array

mysurface.values[mysurface.values < 2000] = 2000

# export the modified surface:

mysurface.to_file('newfile.gri')

也可以從三維場中提取面

def slice_a_cube_with_surface():

    """Slice a seismic cube with a surface on OW dat/map format"""

    cubefile = join(EXPATH1, "ib_test_cube2.segy")

    surfacefile = join(EXPATH2, "h1.dat")

    mycube = xtgeo.cube_from_file(cubefile)

    # import map/dat surface using cube as template (inline/xline

    # must match)

    mysurf = xtgeo.surface_from_file(surfacefile, fformat="ijxyz", template=mycube)

    # sample cube values to mysurf (replacing current depth values)

    mysurf.slice_cube(mycube, sampling="trilinear")

    # export result

    mysurf.to_file("slice.dat", fformat="ijxyz")

 

(2)立方體數據的使用方法

Cube data主要是正交網格的模型和三維地震數據。Python中是個numpy的三維數組,支持兩個對量之間的數學運算和重採樣等。

import xtgeo

# make two cube objects from file import:cube1 = xtgeo.cube_from_file('cube1.segy')cube2 = xtgeo.cube_from_file('cube2.segy')

# subtract the two numpy arrayscube1.values = cube1.values - cube2.values

# export the updated cube1 to SEGYcube1.to_file('diff.segy')

面數據和立體方數據的相互操作,可以很方便地提取層面地震屬性和層間地震屬性。

To sample cube values into a surface can be quite useful. Both direct sampling, and interval sampling (over a window, or between two surfaces) is supported. For the interval sampling, various attributes can be extracted.

Sampling a surface from a cube

Here is sampling a regular surface from a cube. The two objects can have different rotation. See xtgeo.surface.RegularSurface.slice_cube() method

import xtgeo

# make two cube objects from file import:surf = xtgeo.surface_from_file('top.gri')cube = xtgeo.cube_from_file('cube2.segy')

surf.slice_cube(cube)

# export the updated to RMS binary map formatsurf.to_file('myslice.gri')

 

Sampling the root-mean-square surface over a window from a cube

The root mean scquare (rms) value over a surface, +- 10 units (e.g. metres if depth), see slice_cube_window method.

import xtgeo

# slice within a window (vertically) around surface:surf = xtgeo.surface_from_file('top.gri')cube = xtgeo.cube_from_file('cube.segy')

surf.slice_cube_window(cube, zrange=10, attribute='rms')

# export the updated to Irap (RMS) ascii map formatsurf.to_file('rmsaverage.fgr', fformat='irap_ascii')

 

(3)三維網格模型的使用方法

可以從大模型中提取小模型,也可以把模型網格幾何數據和屬性場提取出來,作爲pandas frame數據。

def extractdf():

    """Extract dataframe from Eclipse case"""

    # gete dataframe from the grid only

    grd = xtgeo.grid3d.Grid(GRIDFILEROOT + '.EGRID')

    dataframe = grd.dataframe()  # will not have any grid props

    print(dataframe)

    # load as Eclipse run; this will automatically look for EGRID, INIT, UNRST

    grd = xtgeo.grid3d.Grid()

    grd.from_file(GRIDFILEROOT, fformat='eclipserun', initprops=INITS,

                  restartprops=RESTARTS, restartdates=MYDATES)

    # dataframe from a GridProperties instance, in this case grd.gridprops

    dataframe = grd.gridprops.dataframe()  # properties for all cells

    print(dataframe)

    # Get a dataframe for all cells, with ijk and xyz. In this case

    # a grid key input is required:

    dataframe = grd.dataframe()

    print(dataframe)  # default is for all cells

    # For active cells only:

    dataframe = grd.dataframe(activeonly=True)

    print(dataframe)

    dataframe.to_csv('reek_sim.csv')

也可以計算某種沉積相其他屬性場的統計特徵。

Compute a grid property average and stdev

In this example, how to extract Mean ans Stddev from some geo properties, filtered on facies. An RMS inside version is also shown.

也可以計算多個實現的統計特徵。

Compute a grid property average across realisations

In this example, a technique that keeps memory usage under control when computing averages is also presented.

也可以從模型的初始化數據INIT文件中提取數據轉化爲CSV文件格式。

Make a CSV file from Eclipse INIT data (aka ERT ECL)

Example on how to create a CSV file from all INIT properties. Example is for Eclipse format, but shall work also with ROFF input

def all_init_as_csv():

    """Get dataframes, print as CSV."""

    print('Loading Eclipse data {}'.format(GRIDFILEROOT))

    grd = xtgeo.grid3d.Grid()

    grd.from_file(GRIDFILEROOT, fformat='eclipserun', initprops=INITPROPS)

    print('Get dataframes...')

    dfr = grd.dataframe(activeonly=True)

    print(dfr.head())

    print('Filter out columns with constant values...')

    dfr = dfr.iloc[:, ~np.isclose(0, dfr.var())]

    print(dfr.head())

    print('Write to file...')

    dfr.to_csv('mycsvdump.csv', index=False)

 

(4)井數據的處理

給的例子中做了每個層過井屬性數據的統計。

(5)點和多邊形數據

官方沒有給出例子。

 

  1. 接口描述

因爲例子不多,接口描述就非常關鍵。另外,也是因爲python是動態解釋語言,不做函數接口的數據類型檢查,讓代碼看起來很費勁。XTGeo的模塊結構如下,這裏不詳細介紹,具體看鏈接。

 

 

  1. 5 參考資料

https://pypi.org/project/xtgeo/

https://github.com/equinor/xtgeo

https://xtgeo.readthedocs.io/en/latest/apiref/modules.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章