Skip to content

Commit

Permalink
CLN: Drop support for fmu_context='case_symlink_realization'
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt committed Apr 18, 2024
1 parent df6318c commit 283dafd
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 108 deletions.
2 changes: 0 additions & 2 deletions src/fmu/dataio/_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,13 @@ class FmuContext(str, Enum):
The different entries will impact where data is exported:
REALIZATION = "To realization-N/iter_M/share"
CASE = "To casename/share, but will also work on project disk"
CASE_SYMLINK_REALIZATION = "To case/share, with symlinks on realizations level"
PREPROCESSED = "To share/preprocessed; from interactive runs but re-used later"
NON_FMU = "Not ran in a FMU setting, e.g. interactive RMS"
"""

REALIZATION = "realization"
CASE = "case"
CASE_SYMLINK_REALIZATION = "case_symlink_realization"
PREPROCESSED = "preprocessed"
NON_FMU = "non-fmu"

Expand Down
30 changes: 15 additions & 15 deletions src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from ._logging import null_logger
from ._metadata import generate_export_metadata
from ._utils import (
create_symlink,
detect_inside_rms, # dataio_examples,
export_file,
export_metadata_file,
Expand Down Expand Up @@ -572,6 +571,17 @@ def _validate_and_establish_fmucontext(self) -> None:
will be established based on the presence of ERT environment variables.
"""

if self.fmu_context and self.fmu_context.lower() == "case_symlink_realization":
raise ValueError(
"fmu_context is set to 'case_symlink_realization', which is no "
"longer a supported option. Recommended workflow is to export "
"your data as preprocessed ouside of FMU, and re-export the data "
"with fmu_context='case' using a PRE_SIMULATION ERT workflow. "
"If needed, forward_models in ERT can be set-up to create symlinks "
"out into the individual realizations.",
UserWarning,
)

env_fmu_context = get_fmu_context_from_environment()
logger.debug("fmu context from input is %s", self.fmu_context)
logger.debug("fmu context from environment is %s", env_fmu_context)
Expand Down Expand Up @@ -818,15 +828,16 @@ def export(
Args:
obj: XTGeo instance, a Pandas Dataframe instance or other supported object.
return_symlink: If fmu_context is 'case_symlink_realization' then the link
adress will be returned if this is True; otherwise the physical file
path will be returned.
**kwargs: For other arguments, see ExportData() input keys. If they
exist both places, this function will override!
Returns:
String: full path to exported item.
"""
if return_symlink:
warnings.warn(
"The return_symlink option is deprecated and can safely be removed."
)
self.generate_metadata(obj, compute_md5=True, **kwargs)
metadata = self._metadata
logger.info("Object type is: %s", type(self._object)) # from generate_metadata
Expand All @@ -847,17 +858,6 @@ def export(
else:
warnings.warn("Data will be exported, but without metadata.", UserWarning)

# generate symlink if requested
outfile_target = None
if metadata["file"].get("absolute_path_symlink"):
outfile_target = Path(metadata["file"]["absolute_path_symlink"])
outfile_target.parent.mkdir(parents=True, exist_ok=True)
create_symlink(str(outfile), str(outfile_target))
metafile_target = outfile_target.parent / ("." + str(outfile.name) + ".yml")
create_symlink(str(metafile), str(metafile_target))

self._metadata = metadata

if return_symlink and outfile_target:
return str(outfile_target)
return str(outfile)
42 changes: 4 additions & 38 deletions src/fmu/dataio/providers/_filedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,13 @@ def name(self) -> str:
return self.dataio.name or self.objdata.name

def get_metadata(self) -> meta.File:
relpath, symrelpath = self._get_path()
relpath = self._get_path()
relative_path, absolute_path = self._derive_filedata_generic(relpath)
relative_path_symlink, absolute_path_symlink = (
self._derive_filedata_generic(symrelpath) if symrelpath else (None, None)
)
logger.info("Returning metadata pydantic model meta.File")
return meta.File(
absolute_path=absolute_path,
relative_path=relative_path,
checksum_md5=self._compute_md5() if self.compute_md5 else None,
relative_path_symlink=relative_path_symlink,
absolute_path_symlink=absolute_path_symlink,
)

def _derive_filedata_generic(self, inrelpath: Path) -> tuple[Path, Path]:
Expand Down Expand Up @@ -157,35 +152,11 @@ def _get_filestem(self) -> str:
stem = stem.replace("ø", "oe")
return stem.replace("å", "aa")

def _get_path(self) -> tuple[Path, Path | None]:
def _get_path(self) -> Path:
"""Construct and get the folder path(s)."""
linkdest = None

assert isinstance(
self.dataio.fmu_context, FmuContext
) # Converted to a FmuContext obj. in post-init.

dest = self._get_path_generic(
mode=self.dataio.fmu_context,
allow_forcefolder=True,
)
# assert isinstance(self.dataio.fmu_context, FmuContext)

if self.dataio.fmu_context == FmuContext.CASE_SYMLINK_REALIZATION:
linkdest = self._get_path_generic(
mode=FmuContext.REALIZATION,
allow_forcefolder=False,
info=self.dataio.fmu_context.name,
)

return dest, linkdest

def _get_path_generic(
self,
mode: FmuContext,
allow_forcefolder: bool = True,
info: str = "",
) -> Path:
"""Generically construct and get the folder path and verify."""
mode = self.dataio.fmu_context
outroot = deepcopy(self.rootpath)

logger.info("FMU context is %s", mode)
Expand Down Expand Up @@ -226,9 +197,4 @@ def _get_path_generic(
dest = Path(self.dataio.forcefolder).absolute()
self.forcefolder_is_absolute = True

if not allow_forcefolder:
raise RuntimeError(
f"You cannot use forcefolder in combination with fmucontext={info}"
)

return dest if not self.dataio.subfolder else dest / self.dataio.subfolder
1 change: 0 additions & 1 deletion tests/test_units/test_enum_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def test_fmu_context_validation() -> None:
assert FmuContext.list_valid_values() == [
"realization",
"case",
"case_symlink_realization",
"preprocessed",
"non-fmu",
]
5 changes: 2 additions & 3 deletions tests/test_units/test_filedataprovider_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ def test_get_paths_path_exists_already(regsurf, edataobj1, tmp_path):

fdata = FileDataProvider(edataobj1, objdata)

path, linkpath = fdata._get_path()
path = fdata._get_path()
assert str(path) == "share/results/efolder"
assert linkpath is None


def test_get_paths_not_exists_so_create(regsurf, edataobj1, tmp_path):
Expand All @@ -202,7 +201,7 @@ def test_get_paths_not_exists_so_create(regsurf, edataobj1, tmp_path):

fdata = FileDataProvider(cfg, objdata)

path, _ = fdata._get_path()
path = fdata._get_path()
assert str(path) == "share/results/efolder"


Expand Down
28 changes: 0 additions & 28 deletions tests/test_units/test_prerealization_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import logging
import os
from pathlib import Path

import fmu.dataio.dataio as dataio
import pytest
Expand Down Expand Up @@ -50,33 +49,6 @@ def test_regsurf_case_observation(fmurun_w_casemetadata, rmsglobalconfig, regsur
assert "ertrun1/share/observations/maps/mymap.gri" in exp


def test_regsurf_case_observation_w_symlinks(
fmurun_w_casemetadata, rmsglobalconfig, regsurf
):
"""Generating case level surface, with symlinks in realization folders."""
logger.info("Active folder is %s", fmurun_w_casemetadata)

os.chdir(fmurun_w_casemetadata)

edata = dataio.ExportData(
config=rmsglobalconfig, # read from global config
fmu_context="case_symlink_realization",
name="mymap",
content="depth",
is_observation=True,
)
metadata = edata.generate_metadata(regsurf)
logger.info("\n%s", utils.prettyprint_dict(metadata))
assert (
"realization-0/iter-0/share/observations/maps/mymap.gri"
in metadata["file"]["relative_path_symlink"]
)

exp = edata.export(regsurf, return_symlink=True)
myfile = Path(exp)
assert myfile.is_symlink() is True


def test_regsurf_preprocessed_observation(
fmurun_w_casemetadata, rmssetup, rmsglobalconfig, regsurf
):
Expand Down
34 changes: 13 additions & 21 deletions tests/test_units/test_rms_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,29 +397,21 @@ def test_cube_export_as_case(rmssetup, rmsglobalconfig, cube):


@inside_rms
def test_cube_export_as_case_symlink_realization(rmssetup, rmsglobalconfig, cube):
"""Export the cube to file with correct metadata and name, is_observation.
In addition, try fmu_conext=case
"""
def test_case_symlink_realization_raises_error(
rmssetup, rmsglobalconfig, cube, monkeypatch
):
"""Test that fmu_context="case_symlink_realization" raises error."""
logger.info("Active folder is %s", rmssetup)
os.chdir(rmssetup)

edata = dataio.ExportData(
config=rmsglobalconfig, content="depth"
) # read from global config

output = edata.export(
cube,
name="MyCube",
fmu_context="case_symlink_realization",
is_observation=True,
)
logger.info("Output %s", output)
monkeypatch.chdir(rmssetup)

assert str(output) == str(
(edata._rootpath / "share/observations/cubes/mycube.segy").resolve()
)
edata = dataio.ExportData(config=rmsglobalconfig, content="depth")
with pytest.raises(ValueError):
edata.export(
cube,
name="MyCube",
fmu_context="case_symlink_realization",
is_observation=True,
)


@inside_rms
Expand Down

0 comments on commit 283dafd

Please sign in to comment.