From c3b396548d05f619485fb4d9e59e65ec6d907101 Mon Sep 17 00:00:00 2001 From: Simon Wittl <simon.wittl@th-deg.de> Date: Thu, 20 Mar 2025 16:11:41 +0100 Subject: [PATCH] Public --- examples/generated/example_header.json | 2 +- examples/generated/example_joint.json | 3 + examples/generated/example_projection.json | 2 +- examples/generated/example_roi.json | 2 +- pyproject.toml | 2 +- scripts/generate_example_data.py | 2 + src/thd_json/detector/detector.json | 2 +- src/thd_json/header/header.json | 2 +- src/thd_json/image/image.json | 2 +- src/thd_json/joint/__init__.py | 35 +++++++++ src/thd_json/joint/joint.json | 18 +++++ src/thd_json/projection/projection.json | 2 +- .../projection_geometry.json | 2 +- src/thd_json/roi/roi.json | 2 +- src/thd_json/source/source.json | 2 +- src/thd_json/thd_joint_states/__init__.py | 35 +++++++++ .../thd_joint_states/thd_joint_states.json | 75 +++++++++++++++++++ src/thd_json/volume/volume.json | 2 +- uv.lock | 2 +- 19 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 examples/generated/example_joint.json create mode 100644 src/thd_json/joint/__init__.py create mode 100644 src/thd_json/joint/joint.json create mode 100644 src/thd_json/thd_joint_states/__init__.py create mode 100644 src/thd_json/thd_joint_states/thd_joint_states.json diff --git a/examples/generated/example_header.json b/examples/generated/example_header.json index 0013cf5..935eea3 100644 --- a/examples/generated/example_header.json +++ b/examples/generated/example_header.json @@ -1,3 +1,3 @@ { - "uuid": "0060361f-056d-11f0-b60b-f46d3febaf36" + "uuid": "06f48f47-059d-11f0-b60b-f46d3febaf36" } \ No newline at end of file diff --git a/examples/generated/example_joint.json b/examples/generated/example_joint.json new file mode 100644 index 0000000..0f05187 --- /dev/null +++ b/examples/generated/example_joint.json @@ -0,0 +1,3 @@ +{ + "q": 0.0 +} \ No newline at end of file diff --git a/examples/generated/example_projection.json b/examples/generated/example_projection.json index 4f67582..98003fd 100644 --- a/examples/generated/example_projection.json +++ b/examples/generated/example_projection.json @@ -36,7 +36,7 @@ "z": 0.0 }, "header": { - "uuid": "005f11bd-056d-11f0-b60b-f46d3febaf36" + "uuid": "06f352d6-059d-11f0-b60b-f46d3febaf36" } } } \ No newline at end of file diff --git a/examples/generated/example_roi.json b/examples/generated/example_roi.json index 9472b2c..d343267 100644 --- a/examples/generated/example_roi.json +++ b/examples/generated/example_roi.json @@ -1,6 +1,6 @@ { "header": { - "uuid": "00670fe0-056d-11f0-b60b-f46d3febaf36" + "uuid": "06fe834b-059d-11f0-b60b-f46d3febaf36" }, "roi_center_position_mm": [ 0.0, diff --git a/pyproject.toml b/pyproject.toml index fe481c2..529f067 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "thd-json" -version = "0.1.11" +version = "0.1.12" description = "THD JSON schema and validation tools." authors = [ { name = "swittl", email = "simon.wittl@th-deg.de" } diff --git a/scripts/generate_example_data.py b/scripts/generate_example_data.py index b9a62e6..9e7e24a 100644 --- a/scripts/generate_example_data.py +++ b/scripts/generate_example_data.py @@ -4,6 +4,7 @@ from thd_json.header import get_header_validator, generate_header from thd_json.source import get_source_validator from thd_json.detector import get_detector_validator from thd_json.roi import get_roi_validator +from thd_json.joint import get_joint_validator from hypothesis import given, settings import json from pathlib import Path @@ -29,6 +30,7 @@ def main(): ("source", get_source_validator), ("detector", get_detector_validator), ("roi", get_roi_validator), + ("joint", get_joint_validator), ]: validator = get_validator() schema = validator.get_schema() diff --git a/src/thd_json/detector/detector.json b/src/thd_json/detector/detector.json index 2eb3f6d..07c7700 100644 --- a/src/thd_json/detector/detector.json +++ b/src/thd_json/detector/detector.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD Detector File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "pixel_pitch_mm": { diff --git a/src/thd_json/header/header.json b/src/thd_json/header/header.json index 38f1ba0..5917ce3 100644 --- a/src/thd_json/header/header.json +++ b/src/thd_json/header/header.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD Data Metadata Header File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "timestamp": { diff --git a/src/thd_json/image/image.json b/src/thd_json/image/image.json index 00462f8..4c1a018 100644 --- a/src/thd_json/image/image.json +++ b/src/thd_json/image/image.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD Projection Image File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "header": { diff --git a/src/thd_json/joint/__init__.py b/src/thd_json/joint/__init__.py new file mode 100644 index 0000000..e781336 --- /dev/null +++ b/src/thd_json/joint/__init__.py @@ -0,0 +1,35 @@ +from thd_json import Validator + +from pathlib import Path +import argparse + + +def get_joint_validator(json_suffix: str = "*.json") -> Validator: + return Validator(Path(__file__).parent / Path("joint.json"), json_suffix) + + +def joint_cli(): + parser = argparse.ArgumentParser( + description="JSON THD Joint 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_joint_validator(suffix) + + folder = Path(args.folder) + if not folder.exists(): + raise FileNotFoundError(f"Folder: {folder} does not exist") + + validator.folder(Path(args.folder)) + + +if __name__ == "__main__": + joint_cli() diff --git a/src/thd_json/joint/joint.json b/src/thd_json/joint/joint.json new file mode 100644 index 0000000..83c5378 --- /dev/null +++ b/src/thd_json/joint/joint.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "THD Data Metadata Joint File Schema", + "type": "object", + "version": "0.1.12", + "date": "20.03.2025", + "properties": { + "q": { + "type": "number", + "description": "Current angle of one joint.", + "format": "uuid" + } + }, + "required": [ + "q" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/thd_json/projection/projection.json b/src/thd_json/projection/projection.json index 338f5b1..1bd1162 100644 --- a/src/thd_json/projection/projection.json +++ b/src/thd_json/projection/projection.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD Projection File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "image": { diff --git a/src/thd_json/projection_geometry/projection_geometry.json b/src/thd_json/projection_geometry/projection_geometry.json index 6db5d1a..67da1d8 100644 --- a/src/thd_json/projection_geometry/projection_geometry.json +++ b/src/thd_json/projection_geometry/projection_geometry.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD Projection Geometry File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "header": { diff --git a/src/thd_json/roi/roi.json b/src/thd_json/roi/roi.json index 93ef935..16235de 100644 --- a/src/thd_json/roi/roi.json +++ b/src/thd_json/roi/roi.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD ROI File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "header": { diff --git a/src/thd_json/source/source.json b/src/thd_json/source/source.json index 0920090..165f6a4 100644 --- a/src/thd_json/source/source.json +++ b/src/thd_json/source/source.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD X-Ray Source File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "voltage_kv": { diff --git a/src/thd_json/thd_joint_states/__init__.py b/src/thd_json/thd_joint_states/__init__.py new file mode 100644 index 0000000..a7f7293 --- /dev/null +++ b/src/thd_json/thd_joint_states/__init__.py @@ -0,0 +1,35 @@ +from thd_json import Validator + +from pathlib import Path +import argparse + + +def get_thd_joint_states_validator(json_suffix: str = "*.json") -> Validator: + return Validator(Path(__file__).parent / Path("thd_joint_states.json"), json_suffix) + + +def thd_joint_states_cli(): + parser = argparse.ArgumentParser( + description="JSON THD Joint 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_thd_joint_states_validator(suffix) + + folder = Path(args.folder) + if not folder.exists(): + raise FileNotFoundError(f"Folder: {folder} does not exist") + + validator.folder(Path(args.folder)) + + +if __name__ == "__main__": + thd_joint_states_cli() diff --git a/src/thd_json/thd_joint_states/thd_joint_states.json b/src/thd_json/thd_joint_states/thd_joint_states.json new file mode 100644 index 0000000..c667f9c --- /dev/null +++ b/src/thd_json/thd_joint_states/thd_joint_states.json @@ -0,0 +1,75 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "THD Data Metadata Joint States File Schema", + "type": "object", + "version": "0.1.12", + "date": "20.03.2025", + "properties": { + "header": { + "$ref": "../header/header.json" + }, + "master_joint_e1": { + "$ref": "../joint/joint.json" + }, + "master_joint_a1": { + "$ref": "../joint/joint.json" + }, + "master_joint_a2": { + "$ref": "../joint/joint.json" + }, + "master_joint_a3": { + "$ref": "../joint/joint.json" + }, + "master_joint_a4": { + "$ref": "../joint/joint.json" + }, + "master_joint_a5": { + "$ref": "../joint/joint.json" + }, + "master_joint_a6": { + "$ref": "../joint/joint.json" + }, + "slave_joint_e1": { + "$ref": "../joint/joint.json" + }, + "slave_joint_a1": { + "$ref": "../joint/joint.json" + }, + "slave_joint_a2": { + "$ref": "../joint/joint.json" + }, + "slave_joint_a3": { + "$ref": "../joint/joint.json" + }, + "slave_joint_a4": { + "$ref": "../joint/joint.json" + }, + "slave_joint_a5": { + "$ref": "../joint/joint.json" + }, + "salve_joint_a6": { + "$ref": "../joint/joint.json" + }, + "table_joint_a1": { + "$ref": "../joint/joint.json" + } + }, + "required": [ + "master_joint_e1", + "master_joint_a1", + "master_joint_a2", + "master_joint_a3", + "master_joint_a4", + "master_joint_a5", + "master_joint_a6", + "slave_joint_e1", + "slave_joint_a1", + "slave_joint_a2", + "slave_joint_a3", + "slave_joint_a4", + "slave_joint_a5", + "slave_joint_a6", + "table_joint_a1" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/thd_json/volume/volume.json b/src/thd_json/volume/volume.json index 135ff14..6c7f51d 100644 --- a/src/thd_json/volume/volume.json +++ b/src/thd_json/volume/volume.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "THD Projection Volume File Schema", "type": "object", - "version": "0.1.11", + "version": "0.1.12", "date": "20.03.2025", "properties": { "header": { diff --git a/uv.lock b/uv.lock index 5cb9495..b601f3e 100644 --- a/uv.lock +++ b/uv.lock @@ -356,7 +356,7 @@ wheels = [ [[package]] name = "thd-json" -version = "0.1.11" +version = "0.1.12" source = { editable = "." } dependencies = [ { name = "hatchling" }, -- GitLab