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 @@ -40,7 +40,7 @@ dependencies = [
"click_option_group>=0.5",
"distro>=1.8.0",
"email-validator>=1.1",
"imas-python",
"imas-python>=2.0.1",
"netCDF4>=1.5",
"numpy>=1.14",
"pydantic>=2.10.6",
Expand Down
30 changes: 25 additions & 5 deletions src/simdb/imas/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import imas
import imas.dd_zip
import imas.ids_defs
from semantic_version import Version

from simdb.remote.models import _array_to_range

Expand Down Expand Up @@ -121,13 +122,32 @@ def load_imas_metadata(ids_dist, entry) -> dict:
:return: Dictionary containing metadata.
"""

metadata = {}
latest_dd_version = imas.dd_zip.latest_dd_version()
if latest_dd_version is None:
Comment thread
prasad-sawantdesai marked this conversation as resolved.
raise RuntimeError("Could not determine the data dictionary version.")

try:
parsed_dd_version = Version(latest_dd_version)
except ValueError as exc:
raise RuntimeError(
f"Could not parse the data dictionary version: {latest_dd_version!r}."
) from exc

dd_major_version = parsed_dd_version.major
if not isinstance(dd_major_version, int):
raise RuntimeError(
f"Could not determine the major data dictionary version from "
f"{latest_dd_version!r}."
)

if dd_major_version > 4:
raise RuntimeError(
f"Unsupported data dictionary version {latest_dd_version!r}: "
)

metadata = {"metadata_dd_version": latest_dd_version}
for ids_name, _v in ids_dist.items():
ids = entry.get(ids_name, autoconvert=False)
# Explicitly convert the IDS to the target version
latest_dd_version = imas.dd_zip.latest_dd_version()
if latest_dd_version is None:
raise ValueError("Could not determine the latest DD version.")
ids = imas.convert_ids(ids, latest_dd_version)
for node in imas.util.tree_iter(ids):
metadata[extract_ids_path(str(node.coordinates)).replace("/", ".")] = ( # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

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

Loading