def test_create(self): with self.assertRaises(IOError): s = Surface("File/does/not/exist") with self.assertRaises(ValueError): s = Surface(self.surface_short) with self.assertRaises(ValueError): s = Surface(self.surface_long) s = Surface(self.surface_valid) self.assertEqual(s.getNX(), 49) self.assertEqual(s.getNY(), 79) self.assertEqual(len(s), 49 * 79) with self.assertRaises(IndexError): v = s[49 * 79] with self.assertRaises(TypeError): v = s["KEY"] self.assertEqual(s[0], 0.0051) self.assertEqual(s[-1], -0.0014) with self.assertRaises(IndexError): s[49 * 79] = 787 s[0] = 10 self.assertEqual(s[0], 10) s[-1] = 77 self.assertEqual(s[len(s) - 1], 77)
def test_ops(self): s0 = Surface(self.surface_valid) s0.assign(1.0) for v in s0: self.assertEqual(v, 1.0) s0 += 1 for v in s0: self.assertEqual(v, 2.0) s0 *= 2 for v in s0: self.assertEqual(v, 4.0) s1 = s0 + 4 for v in s1: self.assertEqual(v, 8.0) s2 = Surface(self.surface_valid2) with self.assertRaises(ValueError): s3 = s1 + s2 s4 = s1 + s0 for v in s4: self.assertEqual(v, 12.0) s5 = s4 / 12 for v in s5: self.assertEqual(v, 1.0)
def test_ops(self): s0 = Surface( self.surface_valid ) s0.assign(1.0) for v in s0: self.assertEqual(v , 1.0) s0 += 1 for v in s0: self.assertEqual(v , 2.0) s0 *= 2 for v in s0: self.assertEqual(v , 4.0) s1 = s0 + 4 for v in s1: self.assertEqual(v , 8.0) s2 = Surface( self.surface_valid2 ) with self.assertRaises(ValueError): s3 = s1 + s2 s4 = s1 + s0 for v in s4: self.assertEqual(v , 12.0) s5 = s4 / 12 for v in s5: self.assertEqual(v , 1.0)
def test_header_equal(self): s0 = Surface( self.surface_valid ) s1 = Surface( self.surface_valid2 ) s2 = s0.copy( ) self.assertTrue( s0.headerEqual( s0 )) self.assertFalse( s0.headerEqual( s1 )) self.assertTrue( s0.headerEqual( s2 ))
def test_create_new(self): with self.assertRaises(ValueError): s = Surface(None, 1, 1, 1) with self.assertRaises(IOError): s = Surface(50, 1, 1, 1) # values copied from irap surface_small ny,nx = 20,30 xinc,yinc = 50.0, 50.0 xstart,ystart = 463325.5625, 7336963.5 angle = -65.0 s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) s = Surface(*s_args) self.assertEqual(ny*nx, len(s)) self.assertEqual(nx, s.getNX()) self.assertEqual(ny, s.getNY()) small = Surface (self.surface_small) self.assertTrue(small.headerEqual(s)) valid = Surface (self.surface_valid) self.assertFalse(valid.headerEqual(s)) self.assertNotEqual(s, small) idx = 0 for i in range(nx): for j in range(ny): s[idx] = small[idx] idx += 1 self.assertEqual(s, small)
def test_write(self): with TestAreaContext("surface/write"): s0 = Surface(self.surface_valid) s0.write("new_surface.irap") s1 = Surface("new_surface.irap") self.assertTrue(s1 == s0) s0[0] = 99 self.assertFalse(s1 == s0)
def test_write(self): with TestAreaContext("surface/write"): s0 = Surface( self.surface_valid ) s0.write( "new_surface.irap") s1 = Surface( "new_surface.irap") self.assertTrue( s1 == s0 ) s0[0] = 99 self.assertFalse( s1 == s0 )
def test_copy(self): with TestAreaContext("surface/copy"): s0 = Surface(self.surface_valid) s1 = s0.copy() self.assertTrue(s1 == s0) s1[0] = 99 self.assertFalse(s1 == s0) del s0 self.assertEqual(s1[0], 99) s2 = s1.copy(copy_data=False) self.assertEqual(s2[0], 0.0) self.assertEqual(s2[10], 0.0) self.assertEqual(s2[100], 0.0)
def test_copy(self): with TestAreaContext("surface/copy"): s0 = Surface( self.surface_valid ) s1 = s0.copy( ) self.assertTrue( s1 == s0 ) s1[0] = 99 self.assertFalse( s1 == s0 ) del s0 self.assertEqual( s1[0] , 99) s2 = s1.copy( copy_data = False ) self.assertEqual( s2[0] , 0.0 ) self.assertEqual( s2[10] , 0.0 ) self.assertEqual( s2[100] , 0.0 )
def small_surface(): ny, nx = 12, 12 xinc, yinc = 1, 1 xstart, ystart = -1, -1 angle = 0.0 s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) return Surface(*s_args)
def test_from_surface(self): srf_path = self.createTestPath( "local/geometry/surface/valid_ascii.irap") srf = Surface(srf_path) gp = GeoPointset.fromSurface(srf) self.assertEqual(3871, len(srf)) self.assertEqual(len(srf), len(gp))
def test_getitem(self): srf_path = self.createTestPath( "local/geometry/surface/valid_ascii.irap") srf = Surface(srf_path) gp = GeoPointset.fromSurface(srf) for i in (561, 1105, 1729, 2465, 2821): self.assertEqual(gp[i], srf[i])
def test_xyz(self): s = Surface(self.surface_valid2) self.assertEqual(s.getXYZ(i=5, j=13), s.getXYZ(idx=642)) x, y, z = s.getXYZ(i=5, j=13) self.assertFloatEqual(464041.44804, x) self.assertFloatEqual(7336966.309535, y) self.assertFloatEqual(0.0051, z) self.assertAlmostEqualList(s.getXYZ(i=6, j=13), s.getXYZ(idx=643)) self.assertFloatEqual(-0.0006, s.getXYZ(i=6, j=13)[2]) # z value
def _small_surf(self): # values copied from irap surface_small ny, nx = 20, 30 xinc, yinc = 50.0, 50.0 xstart, ystart = 463325.5625, 7336963.5 angle = -65.0 s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) return Surface(*s_args)
def _create_surface(self, z=None): """ Generate irap surface :param z: replace z values of surface """ nx = self._surface.nx ny = self._surface.ny x = self._surface.x y = self._surface.y if z is None: z = self._surface.z xstart = np.min(x) ystart = np.min(y) if nx < 2 or ny < 2: raise RuntimeError("Cannot create IRAP surface if nx or ny is <2") xinc = (np.max(x) - xstart) / (nx - 1) yinc = (np.max(y) - ystart) / (ny - 1) surf = Surface(nx=nx, ny=ny, xinc=xinc, yinc=yinc, xstart=xstart, ystart=ystart, angle=0) irap_x = np.empty(nx * ny) irap_y = np.array(irap_x) for i in range(len(surf)): irap_x[i], irap_y[i] = surf.getXY(i) # Interpolate vel grid to irap grid, should be the same apart from ordering z = np.nan_to_num(z) ip = CloughTocher2DInterpolator((x, y), z, fill_value=0) irap_z = ip(irap_x, irap_y) for i in range(len(surf)): surf[i] = irap_z[i] return surf
def test_ops2(self): s0 = Surface(self.surface_small) surface_list = [] for i in range(10): s = s0.copy() for j in range(len(s)): s[j] = random.random() surface_list.append(s) mean = s0.copy(copy_data=False) for s in surface_list: mean += s mean /= len(surface_list) std = s0.copy(copy_data=False) for s in surface_list: std += (s - mean) * (s - mean) std /= len(surface_list) - 1
def test_ops2(self): s0 = Surface( self.surface_small ) surface_list = [] for i in range(10): s = s0.copy() for j in range(len(s)): s[j] = random.random() surface_list.append(s) mean = s0.copy( copy_data = False ) for s in surface_list: mean += s mean /= len(surface_list) std = s0.copy( copy_data = False ) for s in surface_list: std += (s - mean) * (s - mean) std /= (len(surface_list) - 1)
def test_header_equal(self): s0 = Surface(self.surface_valid) s1 = Surface(self.surface_valid2) s2 = s0.copy() self.assertTrue(s0.headerEqual(s0)) self.assertFalse(s0.headerEqual(s1)) self.assertTrue(s0.headerEqual(s2))
def test_xy(self): ny,nx = 20,30 xinc,yinc = 50.0, 50.0 xstart,ystart = 463325.5625, 7336963.5 angle = 0 s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) s = Surface(*s_args) xy = s.getXY(0) self.assertEqual((xstart, ystart), xy) xy = s.getXY(1) self.assertEqual((xstart+xinc, ystart), xy) xy = s.getXY(nx) self.assertEqual((xstart, ystart+yinc), xy) xy = s.getXY(-1) self.assertEqual((xstart+xinc*(nx-1), ystart+yinc*(ny-1)), xy)
def test_xyz(self): s = Surface(self.surface_valid2) self.assertEqual(s.getXYZ(i=5,j=13), s.getXYZ(idx=642)) x,y,z = s.getXYZ(i=5,j=13) self.assertFloatEqual(464041.44804, x) self.assertFloatEqual(7336966.309535, y) self.assertFloatEqual(0.0051, z) self.assertAlmostEqualList(s.getXYZ(i=6,j=13), s.getXYZ(idx=643)) self.assertFloatEqual(-0.0006, s.getXYZ(i=6,j=13)[2]) # z value
def test_sqrt(self): s0 = Surface(self.surface_small) s0.assign(4) self.assertEqual(20 * 30, len(s0)) s_sqrt = s0.sqrt() for i in range(len(s0)): self.assertEqual(s0[i], 4) self.assertEqual(s_sqrt[i], 2) s0.inplaceSqrt() self.assertTrue(s0 == s_sqrt)
def test_create(self): with self.assertRaises(IOError): s = Surface("File/does/not/exist") with self.assertRaises(ValueError): s = Surface(self.surface_short) with self.assertRaises(ValueError): s = Surface(self.surface_long) s = Surface( self.surface_valid ) self.assertEqual( s.getNX( ) , 49 ) self.assertEqual( s.getNY( ) , 79 ) self.assertEqual( len(s) , 49*79 ) with self.assertRaises(IndexError): v = s[49 * 79] with self.assertRaises(TypeError): v = s["KEY"] self.assertEqual( s[0] , 0.0051 ) self.assertEqual( s[-1] , -0.0014 ) with self.assertRaises(IndexError): s[49*79] = 787 s[0] = 10 self.assertEqual( s[0] , 10 ) s[-1] = 77 self.assertEqual( s[len(s) - 1] , 77 )
def test_irap_surface(setUp): spec, actnum, parms = setUp grid = EclGridGenerator.createRectangular( dims=(2, 2, 2), dV=(100, 100, 100), actnum=actnum ) # with TestAreaContext("test_irap_surface"): create_restart(grid, "TEST") create_init(grid, "TEST") grid.save_EGRID("TEST.EGRID") parms.velocity_model = "TEST.segy" create_segy_file(parms.velocity_model, spec) ots = OverburdenTimeshift( parms.eclbase, parms.mapaxes, parms.seabed, parms.youngs, parms.poisson, parms.rfactor, parms.convention, parms.above, parms.velocity_model, ) f_name = "irap.txt" s = ots._create_surface() s.write(f_name) s = Surface(f_name) assert s.getNX() == 2 assert s.getNY() == 2 for val in s: assert val == 90
def test_sqrt(self): s0 = Surface( self.surface_small ) s0.assign(4) self.assertEqual(20*30, len(s0)) s_sqrt = s0.sqrt( ) for i in range(len(s0)): self.assertEqual(s0[i] , 4) self.assertEqual(s_sqrt[i] , 2) s0.inplaceSqrt( ) self.assertTrue( s0 == s_sqrt )
def test_xy(self): ny, nx = 20, 30 xinc, yinc = 50.0, 50.0 xstart, ystart = 463325.5625, 7336963.5 angle = 0 s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) s = Surface(*s_args) xy = s.getXY(0) self.assertEqual((xstart, ystart), xy) xy = s.getXY(1) self.assertEqual((xstart + xinc, ystart), xy) xy = s.getXY(nx) self.assertEqual((xstart, ystart + yinc), xy) xy = s.getXY(-1) self.assertEqual((xstart + xinc * (nx - 1), ystart + yinc * (ny - 1)), xy)
def test_ots_config_run_parameters(ots_tmpdir_enter, res_scale, size_scale, pos_shift, results, surf_res): eclcase_dir = ots_tmpdir_enter grid_file = os.path.join(eclcase_dir, "NORNE_ATW2013.EGRID") grid = EclGrid(grid_file, apply_mapaxes=True) mock_segy(grid, res_scale, size_scale, pos_shift, "norne_vol.segy") conf = { "eclbase": os.path.join(eclcase_dir, "NORNE_ATW2013"), "above": 100, "seabed": 300, "youngs": 0.5, "poisson": 0.3, "rfactor": 20, "mapaxes": False, "convention": 1, "output_dir": "ts", "horizon": "horizon.irap", "ascii": "ts.txt", "velocity_model": "norne_vol.segy", "vintages": { "ts_simple": [["1997-11-06", "1998-02-01"], ["1997-12-17", "1998-01-01"]], "dpv": [["1997-11-06", "1997-12-17"]], }, } with open("ots_config.yml", "w") as f: yaml.dump(conf, f, default_flow_style=False) ots_run("ots_config.yml") # test results # 1. we compare the surface resolution # 2. we test sum of output surface heightfields for # 2a. top left and bottom right corners (which is due to shift segy volume) # 2b. we expect the surface to drop with each timeshift def to_numpy(surf): arr = np.array([surf[i] for i in range(len(surf))]).reshape(-1, surf.getNX()) return arr # horizon s_horizon = Surface("horizon.irap") assert surf_res[0] == s_horizon.getNX() assert surf_res[1] == s_horizon.getNY() assert (s_horizon.getNX() > grid.getNY()) == results[-1] assert (s_horizon.getNY() > grid.getNX()) == results[-1] _err = 0.01 nx = s_horizon.getNX() ny = s_horizon.getNY() arr = to_numpy(s_horizon) sh_top_left = arr[:ny // 2 - 1, :nx // 2 - 1].sum() sh_bottom_right = arr[ny // 2:, nx // 2:].sum() assert ((sh_top_left - _err) > 0) == results[0] assert ((sh_bottom_right - _err) > 0) == results[1] # ts_simple1 ts_simple1 = Surface("ts_ts_simple/ots_1997_11_06_1998_02_01.irap") assert nx == ts_simple1.getNX() assert ny == ts_simple1.getNY() assert (ts_simple1.getNX() > grid.getNY()) == results[-1] assert (ts_simple1.getNY() > grid.getNX()) == results[-1] arr = to_numpy(ts_simple1) ts1_top_left = arr[:ny // 2 - 1, :nx // 2 - 1].sum() ts1_bottom_right = arr[ny // 2:, nx // 2:].sum() assert ((ts1_top_left - _err) > 0) == results[0] assert ((ts1_bottom_right - _err) > 0) == results[1] assert ts1_top_left + ts1_bottom_right < sh_top_left + sh_bottom_right # ts_simple2 ts_simple2 = Surface("ts_ts_simple/ots_1997_12_17_1998_01_01.irap") assert nx == ts_simple2.getNX() assert ny == ts_simple2.getNY() assert (ts_simple2.getNX() > grid.getNY()) == results[-1] assert (ts_simple2.getNY() > grid.getNX()) == results[-1] arr = to_numpy(ts_simple2) ts2_top_left = arr[:ny // 2 - 1, :nx // 2 - 1].sum() ts2_bottom_right = arr[ny // 2:, nx // 2:].sum() assert ((ts2_top_left - _err) > 0) == results[0] assert ((ts2_bottom_right - _err) > 0) == results[1] assert ts2_top_left + ts2_bottom_right < sh_top_left + sh_bottom_right assert ts2_top_left + ts2_bottom_right < ts1_top_left + ts1_bottom_right # ts_dpv ts_dpv = Surface("ts_dpv/ots_1997_11_06_1997_12_17.irap") assert nx == ts_dpv.getNX() assert ny == ts_dpv.getNY() assert (ts_dpv.getNX() > grid.getNY()) == results[-1] assert (ts_dpv.getNY() > grid.getNX()) == results[-1] arr = to_numpy(ts_simple2) dpv_top_left = arr[:ny // 2 - 1, :nx // 2 - 1].sum() dpv_bottom_right = arr[ny // 2:, nx // 2:].sum() assert ((dpv_top_left - _err) > 0) == results[0] assert ((dpv_bottom_right - _err) > 0) == results[1] assert dpv_top_left + dpv_bottom_right < sh_top_left + sh_bottom_right
def test_create_new(self): with self.assertRaises(ValueError): s = Surface(None, 1, 1, 1) with self.assertRaises(IOError): s = Surface(50, 1, 1, 1) # values copied from irap surface_small ny, nx = 20, 30 xinc, yinc = 50.0, 50.0 xstart, ystart = 463325.5625, 7336963.5 angle = -65.0 s_args = (None, nx, ny, xinc, yinc, xstart, ystart, angle) s = Surface(*s_args) self.assertEqual(ny * nx, len(s)) self.assertEqual(nx, s.getNX()) self.assertEqual(ny, s.getNY()) small = Surface(self.surface_small) self.assertTrue(small.headerEqual(s)) valid = Surface(self.surface_valid) self.assertFalse(valid.headerEqual(s)) self.assertNotEqual(s, small) idx = 0 for i in range(nx): for j in range(ny): s[idx] = small[idx] idx += 1 self.assertEqual(s, small)