Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 32bit floats for surfaces #6106

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from skbuild import setup

# list of pair of .proto file and out directory
PROTOBUF_FILES = [("src/_ert_com_protocol/_schema.proto", "src/_ert_com_protocol")]

Check failure on line 11 in setup.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (83 > 79 characters)


def compile_protocol_buffers():
Expand All @@ -29,11 +29,11 @@


class EggInfo(egg_info):
"""scikit-build uses the metadata of ert to determine what to include when building

Check failure on line 32 in setup.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (87 > 79 characters)
the project. This determination results in files being copied to a special build

Check failure on line 33 in setup.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (84 > 79 characters)
folder. If ert wants to compile e.g. protobuf files and have those included in the

Check failure on line 34 in setup.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (86 > 79 characters)
distribution, those files needs to be a part of the distribution metadata, i.e. it

Check failure on line 35 in setup.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (86 > 79 characters)
needs to happen in egg_info so that the compiled files are copied to the build

Check failure on line 36 in setup.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (82 > 79 characters)
folder."""

def run(self):
Expand Down Expand Up @@ -145,7 +145,7 @@
"httpx",
"tables",
"xarray",
"xtgeo",
"xtgeo >= 3.3.0",
"netCDF4",
],
entry_points={
Expand Down
9 changes: 7 additions & 2 deletions src/ert/config/surface_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +20,7 @@

# pylint: disable=too-many-instance-attributes
@dataclass
class SurfaceConfig(ParameterConfig): # pylint: disable=too-many-instance-attributes

Check failure on line 23 in src/ert/config/surface_config.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (85 > 79 characters)
ncol: int
nrow: int
xori: float
Expand All @@ -46,7 +47,7 @@
ErrorInfo("Missing required OUTPUT_FILE").set_context(surface)
)
if not init_file:
errors.append(ErrorInfo("Missing required INIT_FILES").set_context(surface))

Check failure on line 50 in src/ert/config/surface_config.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (88 > 79 characters)
elif not forward_init and "%d" not in init_file:
errors.append(
ErrorInfo(
Expand All @@ -59,7 +60,7 @@
)
elif not Path(base_surface).exists():
errors.append(
ErrorInfo(f"BASE_SURFACE:{base_surface} not found").set_context(surface)

Check failure on line 63 in src/ert/config/surface_config.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (88 > 79 characters)
)
if errors:
raise ConfigValidationError.from_collected(errors)
Expand All @@ -67,7 +68,9 @@
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
Expand Down Expand Up @@ -99,7 +102,9 @@
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,
Expand Down
5 changes: 4 additions & 1 deletion src/ert/storage/local_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
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

if TYPE_CHECKING:
from ert.config.parameter_config import ParameterConfig
from ert.storage.local_ensemble import LocalEnsembleAccessor, LocalEnsembleReader

Check failure on line 15 in src/ert/storage/local_experiment.py

View workflow job for this annotation

GitHub Actions / annotate-python-linting

line too long (85 > 79 characters)
from ert.storage.local_storage import LocalStorageAccessor, LocalStorageReader


Expand Down Expand Up @@ -58,7 +59,9 @@

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
Expand Down
2 changes: 1 addition & 1 deletion src/ert/storage/migration/block_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/analysis/test_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion tests/unit_tests/config/test_surface_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 7 additions & 1 deletion tests/unit_tests/storage/test_parameter_sample_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,8 @@ 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)]
Expand Down Expand Up @@ -748,6 +749,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])
)
Expand All @@ -758,6 +762,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
Expand All @@ -772,6 +777,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()
Expand Down
Loading