Skip to content

Commit

Permalink
Mature grid_dimensions, general, fault and zone attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sol committed Nov 28, 2023
1 parent af3c86b commit 506b08c
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 2 deletions.
149 changes: 149 additions & 0 deletions src/fmu/dataio/rmscollectors/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,150 @@
from dataclasses import dataclass
from fmu.dataio.rmscollectors import utils

logging.basicConfig(level="DEBUG")
logger = logging.getLogger("__file__")


def check_if(parameters, keyword, i=-1):
"""Check if specific keyword is equal to str false
Args:
parameters (dict): the job parameters
keyword (str): keyword in parameters
Returns:
bool: true if keyword is "false", else false
"""
if i < 0:
bool_value = parameters[keyword]
print_key = keyword
else:
bool_value = parameters[keyword][i]
print_key = f"{keyword}[{i}]"
print(f"{print_key} {bool_value}, bool: {isinstance(bool_value, bool)}")

return bool_value


def _get_general_settings(parameters):
"""Get general setting for grid
Args:
parameters (dict): job parameters
Returns:
_type_: _description_
"""
general = {
"repeatsections_allowed": check_if(parameters, "RepeatSections"),
"regularized_grid": check_if(parameters, "RegularizedGrid"),
"vertical_boundary": check_if(parameters, "VerticalBoundary"),
"juxtaposition_correction": check_if(parameters, "JuxtapositionCorrection"),
"grid_clipped": check_if(parameters, "ClipGrid"),
}
return general


def _get_horizon_model(parameters):
"""Get information about horizon model used
Args:
parameters (dict): job parameters
Returns:
dict: dictionary with structural model info
"""
horizon_section = parameters["HorizonModel"]
return {"structural_model": horizon_section[1], "horizon_model": horizon_section[2]}


def _get_zone_info(parameters):
"""Extract information about zones
Args:
parameters (dict): job parameters
Returns:
dict: digested zone info
"""
zone_names = parameters["ZoneNames"]
zone_info = {}
for i, zone_name in enumerate(zone_names):
if parameters["ConformalMode"] == "0":
griding_type = "proportional"
elif parameters["ConformalMode"] == "1":
griding_type = "top_conformable"
else:
griding_type = "base_conformable"

sampled = check_if(parameters, "SampledHorizons", i)
air = check_if(parameters, "AirHorizons", i)
if not griding_type == "proportional":
truncated = check_if(parameters, "Truncated", i)
else:
truncated = False

if check_if(parameters, "UsedHorizons", i):
top = "from_structural_model"
else:
top = parameters["TopSurfaces"][i]

zone_info[zone_name] = {
"top_from": top,
"gridding": griding_type,
"sampled": sampled,
"air_interpretation": air,
"truncated_top": truncated,
}
return zone_info


def _get_fault_info(parameters):
"""Get information about the faults
Args:
parameters (dict): job parameters
Returns:
dict: key, fault name, value either stairstepped or amount of pillar adjustment
"""
fault_section = parameters["FaultStateMap"]
fault_info = {}
for name, definition in fault_section:
if definition == "-1":
definition = "stairstepped"
else:
definition = {"pillar_adjustment": definition}
fault_info[name] = definition
return fault_info


def _get_grid_dimensions(parameters):
"""Extract info about grid dimensions
Args:
parameters (dict): the job parameters
Returns:
dict: grid dimensions info
"""
grid_dimensions = {
"origin": {"x": parameters["Origin"][0], "y": parameters["Origin"][1]},
"length": {"x": parameters["XLength"], "y": parameters["YLength"]},
"rotation": parameters["Rotation"],
}
if parameters["UseXInc"]:
xinc = parameters["XInc"]
else:
xinc = round(parameters["XLength"] / parameters["XCells"])
if parameters["UseYInc"]:
yinc = parameters["YInc"]
else:
yinc = round(parameters["YLength"] / parameters["YCells"])

grid_dimensions["increment"] = {"x": xinc, "y": yinc}
return grid_dimensions


@dataclass
class RmsGrid:
Expand All @@ -18,3 +162,8 @@ def __post_init__(self):
["Grid models", self.grid_name, "Grid"], "Create Grid", self.job_name
)
self.project = utils._get_project(self.project, True)
self.dimensions = _get_grid_dimensions(self.params)
self.general_settings = _get_general_settings(self.params)
self.based_on = _get_horizon_model(self.params)
self.faults = _get_fault_info(self.params)
self.zones = _get_zone_info(self.params)
76 changes: 74 additions & 2 deletions tests/test_rmscollectors/test_rmsgrid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import yaml
from pathlib import Path
from fmu.dataio.rmscollectors.grid import RmsGrid
from fmu.dataio.rmscollectors.grid import (
_get_grid_dimensions,
_get_general_settings,
_get_fault_info,
_get_zone_info,
)
import pytest

TEST_DATA = Path(__file__).parent / "../data/drogon/"
Expand All @@ -26,5 +32,71 @@ def _fix_simgrid(drogon_project, write_yaml=False):
return grid


def test_something(simgrid):
print(simgrid.params)
@pytest.fixture(name="grid_parameters", scope="session")
def _fix_grid_parameters():
"""Return parameter set originally extracted from drogon
Raises:
IOError: if cannot find test data
Returns:
dict: the parameter dictionary
"""
# This parameter set is extracted from drogon rms project
# rms version 13.1.2 linux based
params = None
inplace_params = TEST_DATA / "rmscollectors/rmsgrid_params.yml"
with open(inplace_params, "r") as stream:
params = yaml.load(stream, Loader=yaml.SafeLoader)

if params is None:
raise IOError(f"Cannot find parameters at {str(inplace_params)}")
return params


def test_grid_dimensions(grid_parameters):
"""Test function _get_grid_dimensions
Args:
grid_parameters (dict): extracted parameters from grid job
"""
required = ["origin", "length", "increment"]
grid_dimensions = _get_grid_dimensions(grid_parameters)
assert isinstance(
grid_parameters, dict
), f"Grid dimensions should be dict, but is {type(grid_dimensions)}"
for name in required:
assert name in grid_dimensions.keys()
part = grid_dimensions[name]
for dim in ["x", "y"]:
assert dim in part.keys()
assert isinstance(part[dim], (int, float))


def test_general_settings(grid_parameters):
"""Test function _get_general_settings
Args:
grid_parameters (dict): extracted parameters from grid job
"""
general_settings = _get_general_settings(grid_parameters)
settings = [
"repeatsections_allowed",
"regularized_grid",
"vertical_boundary",
"juxtaposition_correction",
]
for setting in settings:
assert setting in general_settings.keys()
assert isinstance(general_settings[setting], bool)


def test_faults(simgrid):
faults = _get_fault_info(simgrid.params)
assert len(faults) == 6, f"Number of faults {len(faults)}, should be 6"
print(faults)


def test_get_zones(grid_parameters):
zones = _get_zone_info(grid_parameters)
print(zones)

0 comments on commit 506b08c

Please sign in to comment.