diff --git a/setup.py b/setup.py index c038908cdf9..37a7b91d931 100644 --- a/setup.py +++ b/setup.py @@ -145,7 +145,7 @@ def package_files(directory): "httpx", "tables", "xarray", - "xtgeo", + "xtgeo >= 3.3.0", "netCDF4", ], entry_points={ diff --git a/src/ert/config/surface_config.py b/src/ert/config/surface_config.py index 98369ddd8b0..9345f984a45 100644 --- a/src/ert/config/surface_config.py +++ b/src/ert/config/surface_config.py @@ -4,6 +4,7 @@ from pathlib import Path from typing import TYPE_CHECKING, List +import numpy as np import xarray as xr import xtgeo from typing_extensions import Self @@ -67,7 +68,9 @@ def from_config_list(cls, surface: List[str]) -> Self: assert out_file is not None assert base_surface is not None try: - surf = xtgeo.surface_from_file(base_surface, fformat="irap_ascii") + surf = xtgeo.surface_from_file( + base_surface, fformat="irap_ascii", dtype=np.float32 + ) except Exception as err: # pylint: disable=broad-exception-caught raise ConfigValidationError.with_context( f"Could not load surface {base_surface!r}", surface @@ -99,7 +102,9 @@ def read_from_runpath(self, run_path: Path, real_nr: int) -> xr.Dataset: f"'{self.name}' in file {file_name}: " "File not found\n" ) - surface = xtgeo.surface_from_file(file_path, fformat="irap_ascii") + surface = xtgeo.surface_from_file( + file_path, fformat="irap_ascii", dtype=np.float32 + ) da = xr.DataArray( surface.values, diff --git a/src/ert/storage/local_experiment.py b/src/ert/storage/local_experiment.py index 23bf015a262..e91065b8691 100644 --- a/src/ert/storage/local_experiment.py +++ b/src/ert/storage/local_experiment.py @@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional, Union from uuid import UUID +import numpy as np import xtgeo from ert.config import ExtParamConfig, Field, GenKwConfig, SurfaceConfig @@ -58,7 +59,9 @@ def parameter_info(self) -> Dict[str, Any]: def get_surface(self, name: str) -> xtgeo.RegularSurface: return xtgeo.surface_from_file( - str(self.mount_point / f"{name}.irap"), fformat="irap_ascii" + str(self.mount_point / f"{name}.irap"), + fformat="irap_ascii", + dtype=np.float32, ) @property diff --git a/src/ert/storage/migration/block_fs.py b/src/ert/storage/migration/block_fs.py index e69cc85efa5..7b13452de5f 100644 --- a/src/ert/storage/migration/block_fs.py +++ b/src/ert/storage/migration/block_fs.py @@ -205,7 +205,7 @@ def _migrate_surface( surface = surfaces[block.name] except KeyError: surface = surfaces[block.name] = xtgeo.surface_from_file( - config.base_surface_path, fformat="irap_ascii" + config.base_surface_path, fformat="irap_ascii", dtype=np.float32 ) array = data_file.load(block, np.prod(surface.dimensions)).reshape( surface.dimensions diff --git a/tests/unit_tests/analysis/test_es_update.py b/tests/unit_tests/analysis/test_es_update.py index 1ef2d52b49f..eaf87a0420e 100644 --- a/tests/unit_tests/analysis/test_es_update.py +++ b/tests/unit_tests/analysis/test_es_update.py @@ -402,7 +402,7 @@ def sample_prior(nx, ny): surf_prior = ens_prior.load_parameters("TOP", list(range(ensemble_size))) for i in range(ensemble_size): _prior_init = xtgeo.surface_from_file( - f"surface/surf_init_{i}.irap", fformat="irap_ascii" + f"surface/surf_init_{i}.irap", fformat="irap_ascii", dtype=np.float32 ) np.testing.assert_array_equal(surf_prior[i], _prior_init.values.data) diff --git a/tests/unit_tests/config/test_surface_config.py b/tests/unit_tests/config/test_surface_config.py index b3f504b0ecd..f174eebbb58 100644 --- a/tests/unit_tests/config/test_surface_config.py +++ b/tests/unit_tests/config/test_surface_config.py @@ -55,7 +55,9 @@ def test_runpath_roundtrip(tmp_path, storage, surface): # compare contents # Data is saved as 'irap_ascii', which means that we only keep 6 significant digits - actual_surface = xtgeo.surface_from_file(tmp_path / "output", fformat="irap_ascii") + actual_surface = xtgeo.surface_from_file( + tmp_path / "output", fformat="irap_ascii", dtype=np.float32 + ) np.testing.assert_allclose( actual_surface.values, surface.values, rtol=0, atol=1e-06 ) diff --git a/tests/unit_tests/storage/test_parameter_sample_types.py b/tests/unit_tests/storage/test_parameter_sample_types.py index 638b9df680c..a5aa8afeda4 100644 --- a/tests/unit_tests/storage/test_parameter_sample_types.py +++ b/tests/unit_tests/storage/test_parameter_sample_types.py @@ -674,7 +674,7 @@ def test_surface_param_update(tmpdir): values=values) surf.to_file("surf.irap", fformat="irap_ascii") - surf_fs = xtgeo.surface_from_file("surf.irap", fformat="irap_ascii") + surf_fs = xtgeo.surface_from_file("surf.irap", fformat="irap_ascii", dtype=np.float32) a, b, c, *_ = surf_fs.values.data.ravel() output = [a * x**2 + b * x + c for x in range(10)] @@ -748,6 +748,9 @@ def test_surface_param_update(tmpdir): .T ) + assert prior_param.dtype == np.float32 + assert posterior_param.dtype == np.float32 + assert np.linalg.det(np.cov(prior_param[:3])) > np.linalg.det( np.cov(posterior_param[:3]) ) @@ -758,6 +761,7 @@ def test_surface_param_update(tmpdir): surf = xtgeo.surface_from_file( f"simulations/realization-{realizations_to_test[0]}/iter-1/surf.irap", fformat="irap_ascii", + dtype=np.float32, ) assert base_surface.ncol == surf.ncol @@ -772,6 +776,7 @@ def test_surface_param_update(tmpdir): surf2 = xtgeo.surface_from_file( f"simulations/realization-{realizations_to_test[1]}/iter-1/surf.irap", fformat="irap_ascii", + dtype=np.float32, ) assert not (surf.values == surf2.values).any()