Skip to content

Commit

Permalink
Merge pull request #13 from jcrivenaes/develop
Browse files Browse the repository at this point in the history
Develop code for new release
  • Loading branch information
jcrivenaes authored Oct 8, 2018
2 parents 275dd66 + a425ad5 commit 74a19a8
Show file tree
Hide file tree
Showing 21 changed files with 546 additions and 305 deletions.
10 changes: 10 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,13 @@ Extract Pandas dataframe from 3D grid and props
.. literalinclude:: ../examples/grid3d_get_df.py
:language: python
Compute a grid property average across realisations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In this example, a technique that keeps memory usage
under control when computing averages is also presented.
.. literalinclude:: ../examples/grid3d_compute_stats.py
:language: python
4 changes: 2 additions & 2 deletions examples/grid3d_compute_stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Compute statistics of N realisations. In this the realisations are "faked" by
just adding a constant to each loop. It provides and insight on memomery
just adding a constant to each loop. It provides and insight on memory
handling and speed.
"""

Expand All @@ -18,7 +18,7 @@
RESTARTPROPS = ['PRESSURE', 'SWAT', 'SOIL']
RDATES = [20001101, 20030101]

NRUN = 60
NRUN = 10


def sum_stats():
Expand Down
48 changes: 36 additions & 12 deletions examples/grid3d_get_df.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
"""
Example on how to retrieve dataframe (Pandas) from a 3D grid.
Example on how to retrieve a dataframe (Pandas) from a 3D grid.
Explanation:
Both a GridProperties and a Grid instance can return a dataframe.
The `grd.gridprops` attribute below is the GridProperties, and
this will return a a dataframe by default which does not include
XYZ and ACTNUM, as this information is only from the Grid (geometry).
The grid itself can also return a dataframe, and in this case
XYZ and ACNUM will be returned by default. Also properties that
are "attached" to the Grid via a GridProperties attribute will
be shown.
"""

from os.path import join as ojn
Expand All @@ -16,23 +29,34 @@

def extractdf():
"""Extract dataframe from Eclipse case"""
# load as Eclipse run; this will look for EGRID, INIT, UNRST
grd = xtgeo.grid3d.Grid()
grd.from_file(GRIDFILEROOT, fformat='eclipserun', initprops=INITPROPS,
restartprops=RESTARTPROPS, restartdates=RDATES)

grdprops = grd.get_gridproperties() # get a GridProperties instance
# 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=INITPROPS,
# restartprops=RESTARTPROPS, restartdates=RDATES)

dataframe = grdprops.dataframe()
# # dataframe from a GridProperties instance, in this case grd.gridprops
# dataframe = grd.gridprops.dataframe() # properties for all cells

print(dataframe)
# print(dataframe)

# to get a dataframe for alle cells, with ijk and xyz:
dataframe = grdprops.dataframe(activeonly=False, ijk=True, xyz=True)
# # Get a dataframe for all cells, with ijk and xyz. In this case
# # a grid key input is required:
# dataframe = grd.dataframe()

print(dataframe)
# print(dataframe) # default is for all cells

# # For active cells only:
# dataframe = grd.dataframe(active=True)

# print(dataframe)

dataframe.to_csv('reek_sim.csv')
# dataframe.to_csv('reek_sim.csv')


if __name__ == '__main__':
Expand Down
39 changes: 39 additions & 0 deletions examples/grid3d_print_init_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Print a CSV from all INIT vectors
"""

from os.path import join as ojn
import numpy as np
import numpy.ma as ma
import pandas as pd
import xtgeo

# EXPATH1 = '../../xtgeo-testdata/3dgrids/reek'
# GRIDFILEROOT = ojn(EXPATH1, 'REEK')

EXPATH1 = '/scratch/troll_fmu/rnyb/10_troll_r003/realization-0/iter-0/eclipse/model'
GRIDFILEROOT = ojn(EXPATH1, 'ECLIPSE')

INITPROPS = 'all' # will look for all vectors that looks "gridvalid"


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...')
df = grd.dataframe(activeonly=True)

print(df.head())
print('Filter out columns with constant values...')
df = df.iloc[:, ~np.isclose(0, df.var())]
print(df.head())
print('Write to file...')
df.to_csv('mycsvdump.csv', index=False)


if __name__ == '__main__':

all_init_as_csv()
15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
# 'segyio',
]

# -----------------------------------------------------------------------------
# Explaining versions:
# As system the PEP 440 major.minor.micro is used:
# - major: API or any larger changes
# - minor: Functionality added, shall have backward compatibiility
# - micro: Bug fix with no expected side effects
# - Provide a tag on the form 3.4.0 for each release!
#
# Also, a verymicro may _sometimes_ exist (allowed in PEP440); which can be:
# - One single, very easy to understand, bugfixes
# - Additions in documentations (not affecting code)
# - These may not be tagged explicity!
#
# Hence, use major.minor.micro or major.minor.micro.verymicro scheme.
# -----------------------------------------------------------------------------

def the_version():
"""Process the version, to avoid non-pythonic version schemes.
Expand Down
11 changes: 8 additions & 3 deletions src/xtgeo/common/xtgeo_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import os
import sys
from datetime import datetime as dtime
import getpass
import platform
import inspect
import logging
import xtgeo
Expand Down Expand Up @@ -240,14 +243,16 @@ def print_xtgeo_header(appname, appversion):
cur_version += str(sys.version_info[1]) + '.' \
+ str(sys.version_info[2])

app = appname + ' (version ' + str(appversion) + ')'
app = appname + ', version ' + str(appversion)
print('')
print(_BColors.HEADER)
print('#' * 79)
print('#{}#'.format(app.center(77)))
print('#' * 79)
ver = 'XTGeo4Python version ' + xtgeo.__version__
ver = ver + ' (CXTGeo v. ' + xtgeo.__version__ + ')'
nowtime = dtime.now().strftime('%Y-%m-%d %H:%M:%S')
ver = 'Using XTGeo version ' + xtgeo.__version__
cur_version += ' @ {} on {} by {}'.format(nowtime, platform.node(),
getpass.getuser())
print('#{}#'.format(ver.center(77)))
print('#{}#'.format(cur_version.center(77)))
print('#' * 79)
Expand Down
2 changes: 1 addition & 1 deletion src/xtgeo/cxtgeo/clib/src/cube_value_xyz_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int cube_value_xyz_interp(
char s[24] = "cube_value_xyz_interp";
long ib, useib, ibmax;
int ic, jc, kc, i, j, k, ier, ier1, flag;
double x_v[8], y_v[8], z_v[8], xx, yy, zz, rx, ry, rz, upx, upy;
double x_v[8], y_v[8], z_v[8], xx, yy, zz, rx, ry, rz;
double usex, usey, dist, previousdist, avginc;
float p_v[8], val;

Expand Down
Loading

0 comments on commit 74a19a8

Please sign in to comment.