Coverage for python/lsst/images/ndf/_common.py: 35%
17 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-29 01:48 -0700
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-29 01:48 -0700
1# This file is part of lsst-images.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# Use of this source code is governed by a 3-clause BSD-style
10# license that can be found in the LICENSE file.
12from __future__ import annotations
14__all__ = ("NdfPointerModel", "archive_path_to_hdf5_path", "archive_path_to_hdf5_path_components")
16import pydantic
19class NdfPointerModel(pydantic.BaseModel):
20 """Reference to an NDF-archive sub-tree by HDF5 path.
22 Used by `NdfOutputArchive`/`NdfInputArchive` to point to
23 sub-trees that have been hoisted out of the main JSON tree into separate
24 HDS components.
25 """
27 path: str
28 """HDF5 absolute path (e.g. ``/MORE/LSST/PSF``)."""
31def archive_path_to_hdf5_path(archive_path: str) -> str:
32 """Translate a serialization archive path to an NDF HDF5 path.
34 The empty path maps to the main JSON tree at ``/MORE/LSST/JSON``.
35 Any non-empty path is uppercased and kept hierarchical under
36 ``/MORE/LSST/``. This mirrors the serialization path while keeping HDS
37 component names within their 16-character limit.
38 """
39 if not archive_path:
40 return "/MORE/LSST/JSON"
41 components = archive_path_to_hdf5_path_components(archive_path)
42 return "/MORE/LSST/" + "/".join(components)
45def archive_path_to_hdf5_path_components(archive_path: str) -> list[str]:
46 """Return HDS-compatible path components for an archive path."""
47 components = [component.upper() for component in archive_path.strip("/").split("/") if component]
48 for component in components:
49 if len(component) > 16:
50 raise ValueError(
51 f"NDF/HDS component {component!r} from archive path {archive_path!r} "
52 "is longer than the 16-character HDS limit."
53 )
54 return components