python FieldProperties can return numpy double arrays.
This commit is contained in:
+17
-10
@@ -9,15 +9,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
py::list getitem( const FieldPropsManager& m, const std::string& kw) {
|
||||
if (m.has<int>(kw))
|
||||
return iterable_to_pylist( m.get<int>(kw) );
|
||||
if (m.has<double>(kw))
|
||||
return iterable_to_pylist( m.get<double>(kw) );
|
||||
|
||||
throw py::key_error( "no such grid property " + kw );
|
||||
}
|
||||
|
||||
bool contains( const FieldPropsManager& manager, const std::string& kw) {
|
||||
if (manager.has<int>(kw))
|
||||
return true;
|
||||
@@ -26,6 +17,21 @@ namespace {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
py::array_t<double> get_double_array(const FieldPropsManager& m, const std::string& kw) {
|
||||
if (m.has<double>(kw))
|
||||
return convert::numpy_array( m.get<double>(kw) );
|
||||
else
|
||||
throw std::invalid_argument("Keyword '" + kw + "'is not of type double.");
|
||||
}
|
||||
|
||||
py::array_t<int> get_int_array(const FieldPropsManager& m, const std::string& kw) {
|
||||
if (m.has<int>(kw))
|
||||
return convert::numpy_array( m.get<int>(kw) );
|
||||
else
|
||||
throw std::invalid_argument("Keyword '" + kw + "'is not of type int.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +39,8 @@ void python::common::export_FieldProperties(py::module& module) {
|
||||
|
||||
py::class_< FieldPropsManager >( module, "FieldProperties")
|
||||
.def( "__contains__", &contains )
|
||||
.def( "__getitem__", &getitem )
|
||||
.def( "get_double_array", &get_double_array )
|
||||
.def( "get_int_array", &get_int_array )
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ if (test_field_props()):
|
||||
|
||||
def test_getitem(self):
|
||||
p = self.props
|
||||
poro = p['PORO']
|
||||
poro = p.get_double_array('PORO')
|
||||
self.assertEqual(324, len(poro))
|
||||
self.assertEqual(0.13, poro[0])
|
||||
self.assertTrue( 'PERMX' in p )
|
||||
px = p['PERMX']
|
||||
px = p.get_double_array('PERMX')
|
||||
print(len(px))
|
||||
self.assertEqual(324, len(px))
|
||||
|
||||
@@ -47,7 +47,7 @@ if (test_field_props()):
|
||||
field_props = self.props
|
||||
|
||||
grid = self.spe3.grid()
|
||||
permx = field_props['PERMX']
|
||||
permx = field_props.get_double_array('PERMX')
|
||||
print('set(PERMX) = %s' % set(permx))
|
||||
# 130mD, 40mD, 20mD, and 150mD, respectively, top to bottom
|
||||
darcys = {0:md2si(130), 1:md2si(40), 2:md2si(20), 3:md2si(150)}
|
||||
|
||||
@@ -19,6 +19,9 @@ class TestProps(unittest.TestCase):
|
||||
def setUp(self):
|
||||
parser = Parser()
|
||||
deck = parser.parse(test_path('spe3/SPE3CASE1.DATA'))
|
||||
#int_array = np.array([0, 1, 2, 3])
|
||||
#hbnum_kw = DeckKeyword( parser["HBNUM"], int_array)
|
||||
#deck.add(hbnum_kw)
|
||||
self.spe3 = EclipseState(deck)
|
||||
self.props = self.spe3.ecl3d_props()
|
||||
if (not test_field_props()):
|
||||
|
||||
Reference in New Issue
Block a user