Skip to content
Snippets Groups Projects
Simon Wittl's avatar
Simon Wittl authored
fffd206d
History

Json Datadefinition

This repository contains data structure definitions for the RoboCT group at Deggendorf. It includes custom data structure schemas, example data files, and validation scripts.

  • Example Files: Stored in the example folder, these files demonstrate data structure usage.
  • Validation Scripts: Located in the scripts folder, these scripts validate thd_json data structure definitions against their schemas.

THD JSON

This data structure uses human-readable .json for storing header information.

CLI

CLI tools for the validation of folder are automatically created. To install the current tools just use:

uv tool install --from git+https://mygit.th-deg.de/roboct/definitions/json_schemas thd-json

After the installation the validators are available as CLI:

projection_validator(.exe) --help 

Projection

This schema defines the properties for projection data in THD JSON format.

Property Type Description Constraints Required
header header Header to identify File. format: Header Yes
focal_spot_position_mm array Position of the focal spot in millimeters 3 numbers Yes
focal_spot_orientation_quat array Quaternion representing the focal spots orientation 4 numbers No
detector_center_position_mm array Center position of the detector in millimeters 3 numbers Yes
detector_horizontal_vector array Horizontal orientation vector of the detector 3 numbers No
detector_vertical_vector array Vertical orientation vector of the detector 3 numbers No
detector_center_orientation_quat array Quaternion representing the detector's center orientation 4 numbers Yes
pixel_pitch_width_mm number Pixel pitch in millimeters (width) Minimum 0.001 Yes
pixel_pitch_height_mm number Pixel pitch in millimeters (height) Minimum 0.001 Yes
image_width_px integer Width of the image in pixels Minimum 1 Yes
image_height_px integer Height of the image in pixels Minimum 1 Yes
projection_matrix_cera array Projection matrix for CERA, representing transformations 3 arrays of 4 numbers No

Header

Property Type Description Constraints Required
timestamp string Timestamp, e.g., 2018-11-13T20:20:39+00:00 format: date-time Yes
uuid string Unique identifier format: uuid Yes

Examples

Python example to validate a projection file:

from thd_json.projection import get_projection_validator
from thd_json.header import get_header_validator
from thd_json.source import get_source_validator
from pathlib import Path


FILE_H = Path("./examples/generated/example_header.json")
FILE_P = Path("./examples/generated/example_projection.json")
FILE_S = Path("./examples/generated/example_source.json")


def main():
    source_validator = get_source_validator()
    source_validator.file(FILE_S)

    projection_validator = get_projection_validator()
    projection_validator.file(FILE_P)

    header_validator = get_header_validator()
    header_validator.file(FILE_H)


if __name__ == "__main__":
    main()

Python example to validate a folder of projections

def main():
    projection_validator = get_projection_validator()
    projection_validator.folder(FOLDER)

Contribute

  • For changes please make a pull request.
  • Update the version and date number of the schema.
  • Add a new datatyp:
    • add a moulde to src\ thd_json\ new_data_type
    • add a validation function to the __init__.py of the new_data_typ. Example of projection._init_.py":
from thd_json import Validator
from thd_json.header import JsonHeader, generate_header
from thd_json.projection_geometry import get_projection_geometry_dict
from thd_json.detector import get_detector_dict


from pathlib import Path
import argparse
import numpy as np


def get_projection_validator(json_suffix: str = "*.json") -> Validator:
    return Validator(Path(__file__).parent / Path("projection.json"), json_suffix)


def projection_cli():
    parser = argparse.ArgumentParser(
        description="JSON THD Projection Geometry Validator CLI with uv."
    )
    parser.add_argument("folder", help="Folder to check.", type=str)
    parser.add_argument(
        "suffix", help="Projection suffix.", default="*.json", type=Path, nargs="?"
    )
    args = parser.parse_args()

    suffix = str(args.suffix)
    if not suffix.startswith("*"):
        raise ValueError(f'The suffix must always start with: "*". \nIt is: {suffix}')

    validator = get_projection_validator(suffix)

    folder = Path(args.folder)
    if not folder.exists():
        raise FileNotFoundError(f"Folder: {folder} does not exist")

    validator.folder(Path(args.folder))


def get_projection_dict(
    image_path: Path,
    focal_spot_position_mm: np.ndarray,
    detector_center_position_mm: np.ndarray,
    detector_center_orientation_quat: np.ndarray,
    image_dimensions_px: np.ndarray,
    pixel_pitch_mm: np.ndarray,
    header: JsonHeader | None = None,
    focal_spot_orientation_quat: np.ndarray | None = None,
):
    if header is None:
        header = generate_header()

    projection = dict()
    projection["projection_geometry"] = get_projection_geometry_dict(
        focal_spot_position_mm,
        detector_center_position_mm,
        detector_center_orientation_quat,
        header,
        focal_spot_orientation_quat,
    )

    projection["detector"] = get_detector_dict(image_dimensions_px, pixel_pitch_mm)
    projection["image"] = {"image_path": str(image_path)}

    return projection


if __name__ == "__main__":
    projection_cli()
  • add the CLI script to the pyproject.toml
[project.scripts]
projection_validator = "thd_json.projection:projection_cli"
...
new_data_typ_validator = "thd_json.new_data_typ:new_data_typ_cli"