Skip to content

Commit

Permalink
Resample with extrapolation: test fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Nov 27, 2018
2 parents 5985965 + 5b3e65f commit d8f8c9a
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python/lib64
/libenkf/src/.faultlist
/develbranch/libenkf/src/.faultlist
/build
/temp-build
/libert_util/tests/data/latex_OK.pdf
/test-data/Statoil
/python/python/ert/ecl/ecl_local.py
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ fopt = summary.numpy_vector("FOPT")
```

The installation with Python enabled is described in a [YouTube video](https://www.youtube.com/watch?v=Qqy1vA1PSk8) by Carlf Fredrik Berg.

[1]: The exact paths here will depend on your system and Python version. The example given is for a RedHat system with Python version 2.7.
27 changes: 27 additions & 0 deletions WINDOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Compiling and Installing **_libecl_** on Windows

## Prerequisits:
* Python 2.7 or 3.x https://www.python.org/ or https://anaconda.org/
* Microsoft Visual Studio https://visualstudio.microsoft.com/downloads/
* Local copy of **_libecl_**

## Instructions:
1. Download or clone the **_libecl_** Github repository to your local disk.

2. Python 2.7 or 3.x installation
- Download a python instalation or a python environment solution such as Anaconda.

3. Download and install Microsoft Visual Studio . At a minimum **_libecl_** requires the VS Studio packages for cmake, msbuild, c and c++ compilers (CL.exe).

4. Open a MSVC command prompt such as _x64 Native Tools Command Prompt for VS 2017_ from your start menu. In the open prompt, navigate to the **_libecl_** source directory you created in step 1. Use the Python package manager **pip** to install **_libecl_** requirements via `pip install -r requirements.txt`. If Python is not accessible from the prompt it may be necessary to add the Python environment location to your system path variable `PATH`.

5. Execute the build commands with the desired CMAKE parameters from `README.md`. The cmake generator can be _`NMake Makefiles`_ , _`Ninja`_ or an appropriate version of _`MSVC`_. For the availble options type `cmake -G` in the MSVC command prompt.

An example build and install is provided below where %VARIABLE% are user defined directory paths:
~~~~
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALLPATH% -DBUILD_SHARED_LIBS="ON" -DENABLE_PYTHON="ON" -DCMAKE_BUILD_TYPE="Release" %SOURCEPATH%
cmake --build %BUILDPATH% --config Release --target install
~~~~
6. For **_libecl_** to be accessible in Python the `%INSTALLPATH%\lib\pythonX.Y\site-package` and Python subdirectories must be added to the `PATH` and `PYTHONPATH` variables. Where `pythonx.y` is the current Python version _e.g._ (`python2.7`, `python3.6` _etc._) .

8. Open a Python interactive session and run `import ecl` to check that the install and paths are now set.
90 changes: 0 additions & 90 deletions Windows.txt

This file was deleted.

58 changes: 57 additions & 1 deletion python/ecl/summary/ecl_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import datetime
import os.path
import ctypes
import pandas
import re

# Observe that there is some convention conflict with the C code
# regarding order of arguments: The C code generally takes the time
Expand Down Expand Up @@ -500,7 +502,6 @@ def pandas_frame(self, time_index = None, column_keys = None):
....
"""
from ecl.summary import EclSumKeyWordVector
import pandas
if column_keys is None:
keywords = EclSumKeyWordVector(self, add_keywords = True)
else:
Expand All @@ -524,6 +525,61 @@ def pandas_frame(self, time_index = None, column_keys = None):
frame = pandas.DataFrame(index = time_index, columns=list(keywords), data=data)
return frame

@staticmethod
def _compile_headers_list(headers, dims):
var_list = []
for key in headers:
lst = re.split(':', key)
kw = lst[0]
wgname = None
num = 0;
unit = "UNIT"
if len(lst) > 1:
nums = []
if lst[1][0].isdigit():
nums = re.split(',', lst[1])
else:
wgname = lst[1]
if len(lst) == 3:
nums = re.split(",", lst[2])
if len(nums) == 3:
i = int(nums[0])-1
j = int(nums[1])-1
k = int(nums[2])-1
if dims is None:
raise ValueError("For key %s When using indexing i,j,k you must supply a valid value for the dims argument" % key)
num = i + j * dims[0] + k * dims[0]*dims[1] + 1
elif len(nums) == 1:
num = int(nums[0])

var_list.append( [kw, wgname, num, unit] )
return var_list

@classmethod
def from_pandas(cls, case, frame, dims = None, headers = None):
start_time = frame.index[0]
var_list = []
if headers is None:
header_list = EclSum._compile_headers_list( frame.columns.values, dims )
else:
header_list = EclSum._compile_headers_list( headers, dims )
if dims is None:
dims = [1,1,1];
ecl_sum = EclSum.writer(case,
start_time.to_pydatetime(),
dims[0], dims[1], dims[2])
for kw, wgname, num, unit in header_list:
var_list.append( ecl_sum.addVariable( kw , wgname = wgname , num = num, unit =unit).getKey1() )

for i, time in enumerate(frame.index):
days = (time - start_time).days
t_step = ecl_sum.addTStep( i+1 , days )

for var in var_list:
t_step[var] = frame.iloc[i][var]

return ecl_sum


def get_key_index(self, key):
"""
Expand Down
35 changes: 35 additions & 0 deletions python/tests/ecl_tests/test_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import shutil
import cwrap
import stat
import pandas
from pandas.testing import assert_frame_equal
from contextlib import contextmanager
from unittest import skipIf, skipUnless, skipIf

Expand Down Expand Up @@ -78,6 +80,21 @@ def create_case(case = "CSV", restart_case = None, restart_step = -1, data_start
restart_case = restart_case,
restart_step = restart_step)

def create_case2(case = "CSV", restart_case = None, restart_step = -1, data_start = None):
length = 100
return createEclSum(case , [("WOPT", "OPX" , 0, "SM3") , ("FOPR" , None , 0, "SM3/DAY"), ("BPR" , None , 10, "SM3"), ("RPR", None, 3, "BARS"), ("COPR", "OPX", 421, "BARS")],
sim_length_days = length,
num_report_step = 10,
num_mini_step = 10,
data_start = data_start,
func_table = {"FOPT" : fopt,
"FOPR" : fopr ,
"FGPT" : fgpt },
restart_case = restart_case,
restart_step = restart_step)



class SumTest(EclTest):


Expand Down Expand Up @@ -549,6 +566,24 @@ def test_pandas(self):
self.assertEqual(len(case), rows)


def test_csv_load(self):
case = create_case2()
frame = case.pandas_frame()
ecl_sum = EclSum.from_pandas("PANDAS", frame, dims=[20,10,5])

for key in frame.columns:
self.assertTrue(key in ecl_sum)

df = ecl_sum.pandas_frame()
assert_frame_equal(frame, df)

ecl_sum_less = EclSum.from_pandas("PANDAS", frame, dims=[20,10,5], headers=['BPR:10', 'RPR:3,1,1', 'COPR:OPX:1,2,3'])
del frame['WOPT:OPX']
del frame['FOPR']
df_less = ecl_sum_less.pandas_frame()
assert_frame_equal(frame, df_less)


def test_total_and_rate(self):
self.assertTrue( EclSum.is_total("FOPT"))
self.assertTrue( EclSum.is_total("WWPT:OP_3"))
Expand Down

0 comments on commit d8f8c9a

Please sign in to comment.