|
4 | 4 | import numpy as np |
5 | 5 | import pytest |
6 | 6 | import xtgeo |
7 | | -from surfio import IrapSurface |
| 7 | +from surfio import IrapHeader, IrapSurface |
8 | 8 |
|
9 | 9 | from ert.config import ConfigValidationError, SurfaceConfig |
10 | 10 | from ert.config.parameter_config import InvalidParameterFile |
@@ -339,3 +339,105 @@ def test_surface_create_storage_datasets_raises_surface_mismatch_error_when_the_ |
339 | 339 | ) |
340 | 340 | with pytest.raises(InvalidParameterFile, match=expected_error_msg): |
341 | 341 | next(storage_dataset_iterator) |
| 342 | + |
| 343 | + |
| 344 | +@pytest.fixture |
| 345 | +def surface_for_dl(): |
| 346 | + # Return a SurfaceConfig object for test purpose |
| 347 | + |
| 348 | + # Create a synthetic surface grid with rotation |
| 349 | + nx = 100 |
| 350 | + ny = 120 |
| 351 | + xori = 1000.0 |
| 352 | + yori = 2000.0 |
| 353 | + xsize = 500.0 |
| 354 | + ysize = 600.0 |
| 355 | + xinc = xsize / nx |
| 356 | + yinc = ysize / ny |
| 357 | + rotation = 0.0 |
| 358 | + return SurfaceConfig( |
| 359 | + type="surface", |
| 360 | + name="MySurface", |
| 361 | + forward_init=True, |
| 362 | + update=True, |
| 363 | + ncol=nx, |
| 364 | + nrow=ny, |
| 365 | + xori=xori, |
| 366 | + yori=yori, |
| 367 | + xinc=xinc, |
| 368 | + yinc=yinc, |
| 369 | + rotation=rotation, |
| 370 | + yflip=1, |
| 371 | + forward_init_file="dummy.txt", |
| 372 | + output_file=Path("dummy.txt"), |
| 373 | + base_surface_path="dummy.txt", |
| 374 | + ) |
| 375 | + |
| 376 | + |
| 377 | +@pytest.mark.parametrize( |
| 378 | + "xpos, ypos, main_range, perp_range, anisotropy_angle", |
| 379 | + [ |
| 380 | + ( |
| 381 | + [1050.0, 1250.0, 1250.0, 1250.0, 1000.0, 1500.0, 1000.0], # xpos |
| 382 | + [2050.0, 2300.0, 2300.0, 2300.0, 2000.0, 2000.0, 2600.0], # ypos |
| 383 | + [100.0, 300.0, 300.0, 600.0, 1000.0, 300.0, 300.0], # main_range |
| 384 | + [100.0, 100.0, 100.0, 200.0, 100.0, 10.0, 100.0], # perp_range |
| 385 | + [0.0, 35.0, 135.0, -135.0, 45.0, -45.0, -60.0], # angle |
| 386 | + ), |
| 387 | + ], |
| 388 | +) |
| 389 | +def test_calc_rho_for_2d_grid_layer( |
| 390 | + snapshot, |
| 391 | + surface_for_dl, |
| 392 | + xpos: list[float], |
| 393 | + ypos: list[float], |
| 394 | + main_range: list[float], |
| 395 | + perp_range: list[float], |
| 396 | + anisotropy_angle: list[float], |
| 397 | +): |
| 398 | + write_surface_file = False |
| 399 | + |
| 400 | + xposition = np.array(xpos) |
| 401 | + yposition = np.array(ypos) |
| 402 | + mainrange = np.array(main_range) |
| 403 | + perprange = np.array(perp_range) |
| 404 | + angles = np.array(anisotropy_angle) |
| 405 | + |
| 406 | + # Dimension of rho_for_one_grid_layer is (nx,ny,nobs) |
| 407 | + rho_for_one_grid_layer = surface_for_dl.calc_rho_for_2d_grid_layer( |
| 408 | + xposition, |
| 409 | + yposition, |
| 410 | + mainrange, |
| 411 | + perprange, |
| 412 | + angles, |
| 413 | + ) |
| 414 | + # Ensure -0 and +0 will be 0 |
| 415 | + rho_for_one_grid_layer = np.where( |
| 416 | + rho_for_one_grid_layer == 0, 0.0, rho_for_one_grid_layer |
| 417 | + ) |
| 418 | + |
| 419 | + snapshot.assert_match( |
| 420 | + str(rho_for_one_grid_layer) + "\n", "testdata_rho_for_one_grid_layer.txt" |
| 421 | + ) |
| 422 | + if write_surface_file: |
| 423 | + # Write surface of rho for visualization |
| 424 | + |
| 425 | + for obs_indx in range(len(xposition)): |
| 426 | + surf = IrapSurface( |
| 427 | + header=IrapHeader( |
| 428 | + ncol=surface_for_dl.ncol, |
| 429 | + nrow=surface_for_dl.nrow, |
| 430 | + xori=surface_for_dl.xori, |
| 431 | + yori=surface_for_dl.yori, |
| 432 | + xinc=surface_for_dl.xinc, |
| 433 | + yinc=surface_for_dl.yinc, |
| 434 | + rot=surface_for_dl.rotation, |
| 435 | + xrot=surface_for_dl.xori, |
| 436 | + yrot=surface_for_dl.yori, |
| 437 | + ), |
| 438 | + values=rho_for_one_grid_layer[:, :, obs_indx], |
| 439 | + ) |
| 440 | + |
| 441 | + file_path = Path("tmp_2d_rho_for_obs_" + str(obs_indx) + ".txt") |
| 442 | + print(f"Write file: {file_path}") |
| 443 | + surf.to_ascii_file(file_path) |
0 commit comments