Skip to content

Commit

Permalink
MAINT: Add defaults to DerivedNamedStratigraphy
Browse files Browse the repository at this point in the history
Also fixed an annotation error.
  • Loading branch information
mferrera committed May 28, 2024
1 parent 156928d commit c69eb87
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/fmu/dataio/providers/objectdata/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class DerivedObjectDescriptor:
@dataclass
class DerivedNamedStratigraphy:
name: str
alias: list[str]
alias: list[str] = field(default_factory=list)

stratigraphic: bool
stratigraphic_alias: list[str]
stratigraphic: bool = field(default=False)
stratigraphic_alias: list[str] = field(default_factory=list)

offset: int
base: str | None
top: str | None
offset: float = field(default=0.0)
base: str | None = field(default=None)
top: str | None = field(default=None)


def derive_name(
Expand Down Expand Up @@ -266,25 +266,19 @@ def _derive_name_stratigraphy(self) -> DerivedNamedStratigraphy:
strat = self.dataio.config.get("stratigraphy", {})
no_stratigraphy_or_name = strat is None or name not in strat

if no_stratigraphy_or_name:
return DerivedNamedStratigraphy(name=name)

rv = DerivedNamedStratigraphy(
name=name if no_stratigraphy_or_name else strat[name].get("name", name),
alias=[] if no_stratigraphy_or_name else strat[name].get("alias", []),
stratigraphic=(
False
if no_stratigraphy_or_name
else strat[name].get("stratigraphic", False)
),
stratigraphic_alias=(
[]
if no_stratigraphy_or_name
else strat[name].get("stratigraphic_alias")
),
offset=0.0 if no_stratigraphy_or_name else strat[name].get("offset", 0.0),
top=None if no_stratigraphy_or_name else strat[name].get("top"),
base=None if no_stratigraphy_or_name else strat[name].get("base"),
name=strat[name].get("name", name),
alias=strat[name].get("alias", []),
stratigraphic=strat[name].get("stratigraphic", False),
stratigraphic_alias=strat[name].get("stratigraphic_alias"),
offset=strat[name].get("offset", 0.0),
top=strat[name].get("top"),
base=strat[name].get("base"),
)

if not no_stratigraphy_or_name and rv.name != "name":
if rv.name != "name":
rv.alias.append(name)

return rv
Expand Down

0 comments on commit c69eb87

Please sign in to comment.