Skip to content

Commit

Permalink
MAINT: Refactor data model structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Jul 4, 2024
1 parent 34b0084 commit cc731f7
Show file tree
Hide file tree
Showing 36 changed files with 435 additions and 419 deletions.
2 changes: 1 addition & 1 deletion docs/ext/pydantic_autosummary/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from typing import Any, Final, get_args, get_origin

_DATAIO_METADATA_PACKAGE: Final = "fmu.dataio.datastructure.meta"
_DATAIO_METADATA_PACKAGE: Final = "fmu.dataio._model"


def _is_dataio(annotation: Any) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/datamodel/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ documentation of these two models can be inspected from here.
.. toctree::
:maxdepth: -1

~fmu.dataio.datastructure.meta.meta.ObjectMetadata
~fmu.dataio.datastructure.meta.meta.CaseMetadata
~fmu.dataio._model.root.ObjectMetadata
~fmu.dataio._model.root.CaseMetadata


About the data model
Expand Down
59 changes: 33 additions & 26 deletions src/fmu/dataio/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from . import types
from ._definitions import SCHEMA, SOURCE, VERSION
from ._logging import null_logger
from .datastructure._internal import internal
from .datastructure.meta import meta
from ._model import fields, internal
from .exceptions import InvalidMetadataError
from .providers._filedata import FileDataProvider
from .providers._fmu import FmuProvider
Expand All @@ -34,25 +33,31 @@

def generate_meta_tracklog(
event: Literal["created", "merged"] = "created",
) -> list[meta.TracklogEvent]:
) -> list[fields.TracklogEvent]:
"""Initialize the tracklog with the 'created' event only."""
return [
meta.TracklogEvent.model_construct(
fields.TracklogEvent.model_construct(
datetime=datetime.datetime.now(timezone.utc),
event=event,
user=meta.User.model_construct(id=getpass.getuser()),
sysinfo=meta.SystemInformation.model_construct(
fmu_dataio=meta.Version.model_construct(version=__version__),
komodo=meta.Version.model_construct(version=kr)
if (kr := os.environ.get("KOMODO_RELEASE"))
else None,
operating_system=meta.OperatingSystem.model_construct(
hostname=platform.node(),
operating_system=platform.platform(),
release=platform.release(),
system=platform.system(),
version=platform.version(),
),
user=fields.User.model_construct(id=getpass.getuser()),
sysinfo=(
fields.SystemInformation.model_construct(
fmu_dataio=fields.Version.model_construct(version=__version__),
komodo=(
fields.Version.model_construct(version=kr)
if (kr := os.environ.get("KOMODO_RELEASE"))
else None
),
operating_system=(
fields.OperatingSystem.model_construct(
hostname=platform.node(),
operating_system=platform.platform(),
release=platform.release(),
system=platform.system(),
version=platform.version(),
)
),
)
),
)
]
Expand All @@ -64,7 +69,7 @@ def _get_meta_filedata(
objdata: ObjectDataProvider,
fmudata: FmuProvider | None,
compute_md5: bool,
) -> meta.File:
) -> fields.File:
"""Derive metadata for the file."""
return FileDataProvider(
dataio=dataio,
Expand All @@ -82,25 +87,27 @@ def _get_meta_fmu(fmudata: FmuProvider) -> internal.FMUClassMetaData | None:
return None


def _get_meta_access(dataio: ExportData) -> meta.SsdlAccess:
return meta.SsdlAccess(
asset=meta.Asset(
def _get_meta_access(dataio: ExportData) -> fields.SsdlAccess:
return fields.SsdlAccess(
asset=fields.Asset(
name=dataio.config.get("access", {}).get("asset", {}).get("name", "")
),
classification=dataio._classification,
ssdl=meta.Ssdl(
ssdl=fields.Ssdl(
access_level=dataio._classification,
rep_include=dataio._rep_include,
),
)


def _get_meta_masterdata(masterdata: dict) -> meta.Masterdata:
return meta.Masterdata.model_validate(masterdata)
def _get_meta_masterdata(masterdata: dict) -> fields.Masterdata:
return fields.Masterdata.model_validate(masterdata)


def _get_meta_display(dataio: ExportData, objdata: ObjectDataProvider) -> meta.Display:
return meta.Display(name=dataio.display_name or objdata.name)
def _get_meta_display(
dataio: ExportData, objdata: ObjectDataProvider
) -> fields.Display:
return fields.Display(name=dataio.display_name or objdata.name)


def generate_export_metadata(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .meta import Root, dump
from .root import Root, dump

__all__ = [
"dump",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from pydantic_core import CoreSchema
from typing_extensions import Annotated

from . import enums, specification
from . import enums
from .specification import AnySpecification


class Timestamp(BaseModel):
Expand Down Expand Up @@ -238,7 +239,8 @@ class Data(BaseModel):

bbox: Optional[Union[BoundingBox3D, BoundingBox2D]] = Field(default=None)
"""A block containing the bounding box for this data. Only applicable if the
object is coordinate-based. See :class:`BoundingBox3D` and :class:`BoudingBox2D`."""
object is coordinate-based. See :class:`BoundingBox3D` and
:class:`BoundingBox2D`."""

format: str = Field(examples=["irap_binary"])
"""A reference to a known file format."""
Expand All @@ -265,9 +267,9 @@ class Data(BaseModel):
"""If a specific horizon is represented with an offset, e.g.
"2 m below Top Volantis"."""

spec: Optional[specification.AnySpecification] = Field(default=None)
spec: Optional[AnySpecification] = Field(default=None)
"""A block containing the specs for this object, if applicable.
See :class:`specification.AnySpecification`."""
See :class:`AnySpecification`."""

time: Optional[Time] = Field(default=None)
"""A block containing lists of objects describing timestamp information for this
Expand Down
File renamed without changes.
Loading

0 comments on commit cc731f7

Please sign in to comment.