本文整理汇总了Python中ecl.eclfile.EclKW.assign方法的典型用法代码示例。如果您正苦于以下问题:Python EclKW.assign方法的具体用法?Python EclKW.assign怎么用?Python EclKW.assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecl.eclfile.EclKW
的用法示例。
在下文中一共展示了EclKW.assign方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sliced_set
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_sliced_set(self):
kw = EclKW("REGIONS", 10, EclDataType.ECL_INT)
kw.assign(99)
kw[0:5] = 66
self.assertEqual(kw[0], 66)
self.assertEqual(kw[4], 66)
self.assertEqual(kw[5], 99)
示例2: test_scatter_copy
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_scatter_copy(self):
source = EclKW("SOURCE", 4 , EclDataType.ECL_INT)
with self.assertRaises(TypeError):
copy = source.scatter_copy([1,1,1,1])
actnum = EclKW("ACTNUM", 6 , EclDataType.ECL_FLOAT)
with self.assertRaises(ValueError):
copy = source.scatter_copy(actnum)
actnum = EclKW("ACTNUM", 8, EclDataType.ECL_INT)
actnum[0] = 1
actnum[1] = 1
with self.assertRaises(ValueError):
copy = source.scatter_copy(actnum)
actnum.assign(1)
with self.assertRaises(ValueError):
copy = source.scatter_copy(actnum)
for i in range(4):
source[i] = i+1
actnum[2*i] = 0
# src = [1,2,3,4]
# actnum = [0,1,0,1,0,1,0,1]
# copy = [0,1,0,2,0,3,0,4]
copy = source.scatter_copy(actnum)
for i in range(4):
self.assertEqual(copy[2*i + 1], i+1)
示例3: test_fault_block_edge
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_fault_block_edge(self):
grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) )
kw = EclKW( "FAULTBLK" , grid.getGlobalSize() , EclDataType.ECL_INT )
kw.assign( 0 )
for j in range(1,4):
for i in range(1,4):
g = i + j*grid.getNX()
kw[g] = 1
layer = FaultBlockLayer( grid , 0 )
示例4: test_mul
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_mul(self):
kw1 = EclKW("Name1", 10, EclDataType.ECL_INT)
kw1.assign(10)
kw2 = EclKW("Name1", 10, EclDataType.ECL_INT)
kw2.assign(2)
kw3 = kw1 * kw2
kw4 = kw1 + kw2
self.assertEqual(len(kw3), len(kw1))
self.assertEqual(len(kw4), len(kw1))
for v in kw3:
self.assertEqual(v, 20)
for v in kw4:
self.assertEqual(v, 12)
示例5: test_fault_block
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_fault_block(self):
grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) )
kw = EclKW( "FAULTBLK" , grid.getGlobalSize() , EclDataType.ECL_INT )
kw.assign( 0 )
for j in range(1,4):
for i in range(1,4):
g = i + j*grid.getNX()
kw[g] = 1
layer = FaultBlockLayer( grid , 0 )
layer.scanKeyword( kw )
block = layer[1]
self.assertEqual( (2.50 , 2.50) , block.getCentroid() )
self.assertEqual( len(block) , 9)
self.assertEqual( layer , block.getParentLayer() )
示例6: test_safe_div
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_safe_div(self):
kw1 = EclKW("SOURCE", 10, EclDataType.ECL_INT)
kw2 = EclKW("XXX", 11, EclDataType.ECL_INT)
with self.assertRaises(ValueError):
kw1.safe_div(kw2)
kw1 = EclKW("SOURCE", 2, EclDataType.ECL_FLOAT)
kw1.assign(10)
kw2 = EclKW("DIV", 2, EclDataType.ECL_INT)
kw2[0] = 0
kw2[1] = 2
kw1.safe_div( kw2 )
self.assertEqual(kw1[0], 10)
self.assertEqual(kw1[1], 5)
示例7: test_numeric_equal
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_numeric_equal(self):
kw1 = EclKW("Name1", 10, EclDataType.ECL_DOUBLE)
kw2 = EclKW("Name1", 10, EclDataType.ECL_DOUBLE)
shift = 0.0001
value = 1000
abs_diff = shift
rel_diff = shift / (shift + 2* value)
kw1.assign(value)
kw2.assign(value + shift)
self.assertTrue( kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 1.1, rel_epsilon=rel_diff * 1.1))
self.assertFalse(kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 1.1, rel_epsilon=rel_diff * 0.9))
self.assertFalse(kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 0.9, rel_epsilon=rel_diff * 1.1))
self.assertTrue( kw1.equal_numeric(kw2, abs_epsilon=0, rel_epsilon=rel_diff * 1.1))
self.assertTrue( kw1.equal_numeric(kw2, abs_epsilon=abs_diff * 1.1, rel_epsilon=0))
示例8: test_first_different
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_first_different(self):
kw1 = EclKW("NAME1", 100, EclDataType.ECL_INT)
kw2 = EclKW("NAME2", 100, EclDataType.ECL_INT)
kw3 = EclKW("NAME2", 200, EclDataType.ECL_INT)
kw4 = EclKW("NAME2", 100, EclDataType.ECL_FLOAT)
kw5 = EclKW("NAME2", 100, EclDataType.ECL_FLOAT)
with self.assertRaises(IndexError):
EclKW.firstDifferent(kw1, kw2, offset=100)
with self.assertRaises(ValueError):
EclKW.firstDifferent(kw1, kw3)
with self.assertRaises(TypeError):
EclKW.firstDifferent(kw1, kw4)
with self.assertRaises(IndexError):
kw1.firstDifferent(kw2, offset=100)
with self.assertRaises(ValueError):
kw1.firstDifferent(kw3)
with self.assertRaises(TypeError):
kw1.firstDifferent(kw4)
kw1.assign(1)
kw2.assign(1)
self.assertEqual(kw1.firstDifferent(kw2), len(kw1))
kw1[0] = 100
self.assertEqual(kw1.firstDifferent(kw2), 0)
self.assertEqual(kw1.firstDifferent(kw2, offset=1), len(kw1))
kw1[10] = 100
self.assertEqual(kw1.firstDifferent(kw2, offset=1), 10)
kw4.assign(1.0)
kw5.assign(1.0)
self.assertEqual(kw4.firstDifferent(kw5), len(kw4))
kw4[10] *= 1.0001
self.assertEqual(kw4.firstDifferent(kw5), 10)
self.assertEqual(kw4.firstDifferent(kw5, epsilon=1.0), len(kw4))
self.assertEqual(kw4.firstDifferent(kw5, epsilon=0.0000001), 10)
示例9: test_stepped
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_stepped(self):
grid = EclGrid.createRectangular( (6,1,4) , (1,1,1))
f = Fault(grid , "F")
f.addRecord(4,4,0,0,0,1,"X")
f.addRecord(2,2,0,0,1,1,"Z")
f.addRecord(1,1,0,0,2,3,"X")
block_kw = EclKW("FAULTBLK" , grid.getGlobalSize() , EclDataType.ECL_INT)
block_kw.assign(1)
block_kw[5] = 2
block_kw[11] = 2
block_kw[14:18] = 2
block_kw[14:18] = 2
block_kw[20:23] = 2
layer0 = FaultBlockLayer( grid , 0 )
layer0.scanKeyword( block_kw )
layer0.addFaultBarrier( f )
self.assertTrue( layer0.cellContact((0,0) , (1,0)))
self.assertFalse( layer0.cellContact((4,0) , (5,0)))
layer1 = FaultBlockLayer( grid , 1 )
layer1.scanKeyword( block_kw )
layer1.addFaultBarrier( f )
self.assertTrue( layer1.cellContact((0,0) , (1,0)))
self.assertFalse( layer1.cellContact((4,0) , (5,0)))
layer2 = FaultBlockLayer( grid , 2 )
layer2.scanKeyword( block_kw )
layer2.addFaultBarrier( f )
self.assertTrue( layer2.cellContact((0,0) , (1,0)))
self.assertFalse( layer2.cellContact((1,0) , (2,0)))
layer3 = FaultBlockLayer( grid , 3 )
layer3.scanKeyword( block_kw )
layer3.addFaultBarrier( f )
self.assertTrue( layer3.cellContact((0,0) , (1,0)))
self.assertFalse( layer3.cellContact((1,0) , (2,0)))
示例10: test_add_squared
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_add_squared(self):
kw1 = EclKW("TEST_KW", 3, EclDataType.ECL_STRING(4))
kw2 = EclKW("TEST_KW", 3, EclDataType.ECL_STRING(4))
with self.assertRaises(TypeError):
kw1.add_squared(kw2)
kw1 = EclKW("T1", 10, EclDataType.ECL_INT)
kw2 = EclKW("T2", 11, EclDataType.ECL_INT)
with self.assertRaises(ValueError):
kw1.add_squared(kw2)
kw2 = EclKW("T", 10, EclDataType.ECL_FLOAT)
with self.assertRaises(ValueError):
kw1.add_squared(kw2)
kw2 = EclKW("T2", 10, EclDataType.ECL_INT)
kw2.assign(2)
kw1.add_squared(kw2)
for elm in kw1:
self.assertEqual(elm, 4)
示例11: test_fmu_stat_workflow
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_fmu_stat_workflow(self):
N = 100
global_size = 100
active_size = 50
with TestAreaContext("FMU_FILES"):
for i in range(N):
permx = EclKW("PERMX", active_size, EclDataType.ECL_FLOAT)
poro = EclKW("PORO", active_size, EclDataType.ECL_FLOAT)
porv = EclKW("PORV", global_size, EclDataType.ECL_FLOAT)
porv.assign(0)
for g in random.sample( range(global_size), active_size):
porv[g] = 1
permx.assign(random.random())
poro.assign(random.random())
with openFortIO("TEST%d.INIT" % i, FortIO.WRITE_MODE) as f:
permx.fwrite(f)
poro.fwrite(f)
porv.fwrite(f)
mean_permx = EclKW("PERMX", global_size, EclDataType.ECL_FLOAT)
std_permx = EclKW("PERMX", global_size, EclDataType.ECL_FLOAT)
mean_poro = EclKW("PORO", global_size, EclDataType.ECL_FLOAT)
std_poro = EclKW("PORO", global_size, EclDataType.ECL_FLOAT)
count = EclKW("COUNT", global_size, EclDataType.ECL_INT)
for i in range(N):
f = EclFile("TEST%d.INIT" % i)
porv = f["PORV"][0]
permx = f["PERMX"][0]
poro = f["PORO"][0]
actnum = porv.create_actnum()
global_permx = permx.scatter_copy( actnum )
mean_permx += global_permx
std_permx.add_squared( global_permx)
global_poro = poro.scatter_copy( actnum )
mean_poro += global_poro
std_poro.add_squared( global_poro)
count += actnum
mean_permx.safe_div(count)
std_permx.safe_div(count)
std_permx -= mean_permx * mean_permx
std_permx.isqrt()
mean_poro.safe_div(count)
std_poro.safe_div(count)
std_poro -= mean_poro * mean_poro
std_poro.isqrt()
示例12: test_block_view
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
def test_block_view(self):
with TestAreaContext("python/ecl_file/view"):
with openFortIO("TEST" , mode = FortIO.WRITE_MODE) as f:
for i in range(5):
header = EclKW("HEADER" , 1 , EclDataType.ECL_INT )
header[0] = i
data1 = EclKW("DATA1" , 100 , EclDataType.ECL_INT )
data1.assign( i )
data2 = EclKW("DATA2" , 100 , EclDataType.ECL_INT )
data2.assign( i*10 )
header.fwrite( f )
data1.fwrite( f )
data2.fwrite( f )
ecl_file = EclFile("TEST")
pfx = 'EclFile('
self.assertEqual(pfx, repr(ecl_file)[:len(pfx)])
with self.assertRaises(KeyError):
ecl_file.blockView("NO" , 1)
with self.assertRaises(IndexError):
ecl_file.blockView("HEADER" , 100)
with self.assertRaises(IndexError):
ecl_file.blockView("HEADER" , 1000)
bv = ecl_file.blockView("HEADER" , -1)
for i in range(5):
view = ecl_file.blockView("HEADER" , i)
self.assertEqual( len(view) , 3)
header = view["HEADER"][0]
data1 = view["DATA1"][0]
data2 = view["DATA2"][0]
self.assertEqual( header[0] , i )
self.assertEqual( data1[99] , i )
self.assertEqual( data2[99] , i*10 )
for i in range(5):
view = ecl_file.blockView2("HEADER" , "DATA2", i )
self.assertEqual( len(view) , 2)
header = view["HEADER"][0]
data1 = view["DATA1"][0]
self.assertEqual( header[0] , i )
self.assertEqual( data1[99] , i )
self.assertFalse( "DATA2" in view )
view = ecl_file.blockView2("HEADER" , None, 0 )
self.assertEqual( len(view) , len(ecl_file))
view = ecl_file.blockView2(None , "DATA2", 0 )
示例13: FaultBlockTest
# 需要导入模块: from ecl.eclfile import EclKW [as 别名]
# 或者: from ecl.eclfile.EclKW import assign [as 别名]
class FaultBlockTest(EclTest):
def setUp(self):
self.grid = EclGrid.createRectangular( (10,10,10) , (1,1,1) )
self.kw = EclKW( "FAULTBLK" , self.grid.getGlobalSize() , EclDataType.ECL_INT )
self.kw.assign( 1 )
reg = EclRegion( self.grid , False )
for k in range(self.grid.getNZ()):
reg.clear( )
reg.select_kslice( k , k )
self.kw.assign( k , mask = reg )
self.kw[ k * self.grid.getNX() * self.grid.getNY() + 7] = 177
def test_fault_block(self):
grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) )
kw = EclKW( "FAULTBLK" , grid.getGlobalSize() , EclDataType.ECL_INT )
kw.assign( 0 )
for j in range(1,4):
for i in range(1,4):
g = i + j*grid.getNX()
kw[g] = 1
layer = FaultBlockLayer( grid , 0 )
layer.scanKeyword( kw )
block = layer[1]
self.assertEqual( (2.50 , 2.50) , block.getCentroid() )
self.assertEqual( len(block) , 9)
self.assertEqual( layer , block.getParentLayer() )
def test_get_ijk(self):
with TestAreaContext("python/fault_block_layer/neighbour") as work_area:
with open("kw.grdecl","w") as fileH:
fileH.write("FAULTBLK \n")
fileH.write("1 1 1 0 0\n")
fileH.write("1 2 2 0 3\n")
fileH.write("4 2 2 3 3\n")
fileH.write("4 4 4 0 0\n")
fileH.write("4 4 4 0 5\n")
fileH.write("/\n")
with cwrap.open("kw.grdecl") as f:
kw = EclKW.read_grdecl(
f, "FAULTBLK", ecl_type=EclDataType.ECL_INT)
grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) )
layer = FaultBlockLayer( grid , 0 )
layer.loadKeyword( kw )
block = layer[0,0]
self.assertEqual( block.getBlockID() , 1 )
block = layer[2,2]
self.assertEqual( block.getBlockID() , 2 )
with self.assertRaises(ValueError):
layer[3,3]
with self.assertRaises(IndexError):
layer[5,5]
def test_neighbours(self):
with TestAreaContext("python/fault_block_layer/neighbour") as work_area:
with open("kw.grdecl","w") as fileH:
fileH.write("FAULTBLK \n")
fileH.write("1 1 1 0 0\n")
fileH.write("1 2 2 0 3\n")
fileH.write("4 2 2 3 3\n")
fileH.write("4 4 4 0 0\n")
fileH.write("4 4 4 0 5\n")
fileH.write("/\n")
with cwrap.open("kw.grdecl") as f:
kw = EclKW.read_grdecl(
f, "FAULTBLK", ecl_type=EclDataType.ECL_INT)
grid = EclGrid.createRectangular( (5,5,1) , (1,1,1) )
layer = FaultBlockLayer( grid , 0 )
layer.loadKeyword( kw )
block1 = layer.getBlock( 1 )
block2 = layer.getBlock( 2 )
block3 = layer.getBlock( 3 )
block4 = layer.getBlock( 4 )
block5 = layer.getBlock( 5 )
self.assertEqual( block1.getParentLayer() , layer )
#Expected: 1 -> {2,4}, 2 -> {1,3,4}, 3 -> {2}, 4 -> {1,2}, 5-> {}
neighbours = block1.getNeighbours()
self.assertEqual( len(neighbours) , 2)
self.assertTrue( block2 in neighbours )
self.assertTrue( block4 in neighbours )
neighbours = block2.getNeighbours()
#.........这里部分代码省略.........