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 8, 2024
1 parent 14844cf commit 459142c
Show file tree
Hide file tree
Showing 37 changed files with 439 additions and 421 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
14 changes: 7 additions & 7 deletions schema/definitions/0.8.0/schema/fmu_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
"title": "metadata_class"
},
"fmu": {
"$ref": "#/$defs/FMUCaseAttributes"
"$ref": "#/$defs/FMUBase"
},
"masterdata": {
"$ref": "#/$defs/Masterdata"
Expand Down Expand Up @@ -955,7 +955,7 @@
"title": "DomainReference",
"type": "string"
},
"FMUAttributes": {
"FMU": {
"dependencies": {
"aggregation": {
"not": {
Expand Down Expand Up @@ -1033,10 +1033,10 @@
"model",
"context"
],
"title": "FMUAttributes",
"title": "FMU",
"type": "object"
},
"FMUCaseAttributes": {
"FMUBase": {
"description": "The ``fmu`` block contains all attributes specific to FMU. The idea is that the FMU\nresults data model can be applied to data from *other* sources - in which the\nfmu-specific stuff may not make sense or be applicable.",
"properties": {
"case": {
Expand All @@ -1050,7 +1050,7 @@
"case",
"model"
],
"title": "FMUCaseAttributes",
"title": "FMUBase",
"type": "object"
},
"FMUContext": {
Expand Down Expand Up @@ -4224,7 +4224,7 @@
"$ref": "#/$defs/File"
},
"fmu": {
"$ref": "#/$defs/FMUAttributes"
"$ref": "#/$defs/FMU"
},
"masterdata": {
"$ref": "#/$defs/Masterdata"
Expand Down Expand Up @@ -9463,4 +9463,4 @@
}
},
"title": "Root"
}
}
59 changes: 33 additions & 26 deletions src/fmu/dataio/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

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.objectdata._provider import objectdata_provider_factory
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 @@ -15,7 +15,8 @@
)
from typing_extensions import Annotated

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

if TYPE_CHECKING:
from pydantic_core import CoreSchema
Expand Down Expand Up @@ -240,7 +241,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 @@ -267,9 +269,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 459142c

Please sign in to comment.