Skip to content
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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = [
"PyYAML",
"annotated_types", # Dependency in Pydantic also
"fmu-config",
"fmu-datamodels",
"fmu-datamodels>=0.23.1", # StratigraphyElement.uuid support
"pandas",
"pydantic",
]
Expand Down
49 changes: 41 additions & 8 deletions src/fmu/settings/_drogon/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,51 @@
"stratigraphic": True,
"name": "VOLANTIS GP. Top",
"alias": ["TopVOLANTIS", "TOP_VOLANTIS"],
"uuid": "1629c229-0a2b-4f0a-94f7-dc01b171cb1c",
},
"TopTherys": {
"stratigraphic": True,
"name": "Therys Fm. Top",
"uuid": "0240dc8e-659a-4925-b569-6f1570ba6770",
},
"TopVolon": {
"stratigraphic": True,
"name": "Volon Fm. Top",
"uuid": "8aeab228-6b92-4875-8b13-2b68a3108c8d",
},
"BaseVolon": {
"stratigraphic": True,
"name": "Volon Fm. Base",
"uuid": "433bd00d-9cf8-4eec-9a35-8bac0821f07c",
},
"BaseVolantis": {
"stratigraphic": True,
"name": "VOLANTIS GP. Base",
"uuid": "3c36a234-91e3-4bc5-8642-f32b910c5c6c",
},
"TopTherys": {"stratigraphic": True, "name": "Therys Fm. Top"},
"TopVolon": {"stratigraphic": True, "name": "Volon Fm. Top"},
"BaseVolon": {"stratigraphic": True, "name": "Volon Fm. Base"},
"BaseVolantis": {"stratigraphic": True, "name": "VOLANTIS GP. Base"},
"BaseVelmodel": {"stratigraphic": False, "name": "BaseVelmodel"},
"Above": {"stratigraphic": False, "name": "Above"},
"Valysar": {"stratigraphic": True, "name": "Valysar Fm."},
"Therys": {"stratigraphic": True, "name": "Therys Fm."},
"Volon": {"stratigraphic": True, "name": "Volon Fm."},
"Valysar": {
"stratigraphic": True,
"name": "Valysar Fm.",
"uuid": "a9cdeb70-af4f-4e86-a209-4eb124ac096a",
},
"Therys": {
"stratigraphic": True,
"name": "Therys Fm.",
"uuid": "a21c5998-9506-44d8-b29d-208c817e3a0b",
},
"Volon": {
"stratigraphic": True,
"name": "Volon Fm.",
"uuid": "a6d740be-ef58-4569-9fad-2daf17aa214c",
},
"Below": {"stratigraphic": False, "name": "Below"},
"TopVolantis_BaseVolantis": {"stratigraphic": True, "name": "VOLANTIS GP."},
"TopVolantis_BaseVolantis": {
"stratigraphic": True,
"name": "VOLANTIS GP.",
"uuid": "08d5f9e0-56bc-4956-b0f3-68f2a3047ef9",
},
}

STRATIGRAPHY_MAPPINGS: Final[list[dict[str, Any]]] = [
Expand Down
29 changes: 15 additions & 14 deletions src/fmu/settings/_resources/mappings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,27 @@ def build_global_config_stratigraphy(self) -> Stratigraphy:
self.stratigraphy_mappings if self.exists else StratigraphyMappings(root=[])
)

primaries: dict[str, str] = {} # source_id -> target_id
aliases_by_target: dict[str, list[str]] = {} # target_id -> [alias source_ids]
aliases_by_target_id: dict[
str, list[str]
] = {} # target_id -> [alias source_ids]

# Stratigraphic entries from stratigraphy mappings
for mapping in stratigraphy_mappings:
if mapping.relation_type == RelationType.primary:
primaries[mapping.source_id] = mapping.target_id
elif mapping.relation_type == RelationType.alias:
aliases_by_target.setdefault(mapping.target_id, []).append(
if mapping.relation_type == RelationType.alias:
aliases_by_target_id.setdefault(mapping.target_id, []).append(
mapping.source_id
)

for source_id, target_id in primaries.items():
entry: dict[str, Any] = {
"stratigraphic": True,
"name": target_id,
Comment thread
GibranAlfa marked this conversation as resolved.
}
if aliases := aliases_by_target.get(target_id):
entry["alias"] = aliases
stratigraphy[source_id] = entry
for mapping in stratigraphy_mappings:
if mapping.relation_type == RelationType.primary:
entry: dict[str, Any] = {
"stratigraphic": True,
"name": mapping.target_id,
"uuid": mapping.target_uuid,
}
if aliases := aliases_by_target_id.get(mapping.target_id):
entry["alias"] = aliases
stratigraphy[mapping.source_id] = entry

# Non-stratigraphic entries from RMS
rms_config = self.fmu_dir.get_config_value("rms")
Expand Down
14 changes: 12 additions & 2 deletions tests/test_resources/test_mappings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pathlib import Path
from typing import TYPE_CHECKING
from uuid import UUID

import pytest
from fmu.datamodels.context.mappings import (
Expand Down Expand Up @@ -34,6 +35,7 @@ def _stratigraphy_mappings(
source_id: str,
target_id: str,
*aliases: str,
target_uuid: UUID | None = None,
) -> InternalStratigraphyMappings:
return InternalStratigraphyMappings(
root=[
Expand All @@ -60,6 +62,7 @@ def _stratigraphy_mappings(
relation_type=InternalRelationType.primary,
source_id=source_id,
target_id=target_id,
target_uuid=target_uuid,
),
]
)
Expand Down Expand Up @@ -555,14 +558,21 @@ def test_build_global_config_stratigraphy_only_mappings(
) -> None:
"""Only stratigraphic entries when there is no RMS config."""
mappings_manager = MappingsManager(fmu_dir)
target_uuid = UUID("00000000-0000-0000-0000-000000000001")
mappings_manager.update_internal_stratigraphy_mappings(
_stratigraphy_mappings("TopX", "X Fm. Top")
_stratigraphy_mappings("TopX", "X Fm. Top", target_uuid=target_uuid)
)

strat = mappings_manager.build_global_config_stratigraphy()

result = strat.model_dump(mode="json", exclude_none=True, exclude_unset=True)
assert result == {"TopX": {"stratigraphic": True, "name": "X Fm. Top"}}
assert result == {
"TopX": {
"stratigraphic": True,
"name": "X Fm. Top",
"uuid": str(target_uuid),
}
}


def test_build_global_config_stratigraphy_mapped_horizon_not_duplicated(
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading