Skip to content
Snippets Groups Projects
Commit 39a4dafe authored by Simon Wittl's avatar Simon Wittl
Browse files

Merge branch 'header' into 'main'

Header

See merge request roboct/definitions/json_schemas!8
parents 3cc4d96d 1fc7159f
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ 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 |
......@@ -40,6 +41,13 @@ This schema defines the properties for projection data in THD JSON format.
| `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
......
{
"header":
{
"uuid": "b83d81a1-333f-448e-af75-7c7db317fd96",
"timestamp": "2018-11-13T20:20:39+00:00"
},
"focal_spot_position_mm": [
2724.71682,
1690.5,
......
......@@ -13,6 +13,7 @@ dependencies = [
[project.scripts]
projection_validator = "thd_json.projection:projection_cli"
header_validator = "thd_json.header:header_cli"
[build-system]
requires = ["hatchling"]
......
from thd_json import Validator
from pathlib import Path
import argparse
def get_header_validator(json_suffix: str = '*.json') -> Validator:
return Validator(Path(__file__).parent / Path('header.json'), json_suffix)
def header_cli():
parser = argparse.ArgumentParser(description='JSON THD Header 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_header_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__":
header_cli()
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "THD Projection File Schema",
"type": "object",
"version": 0.2,
"date": "14.11.2024",
"properties": {
"timestamp": {
"type": "string",
"description": "Timestamp, e.g. 2018-11-13T20:20:39+00:00",
"format": "date-time"
},
"uuid": {
"type": "string",
"description": "Unique identifier",
"format": "uuid"
}
},
"required": [
"timestamp",
"uuid"
],
"additionalProperties": false
}
\ No newline at end of file
......@@ -2,9 +2,12 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "THD Projection File Schema",
"type": "object",
"version": 0.2,
"date": "04.11.2024",
"version": 0.3,
"date": "14.11.2024",
"properties": {
"header": {
"$ref": "./header/header.json"
},
"focal_spot_position_mm": {
"type": "array",
"description": "Position of the focal spot in millimeters.",
......
import os
import json
from pathlib import Path
from jsonschema import validate, ValidationError
from jsonschema import ValidationError, RefResolver
from jsonschema.validators import Draft202012Validator
import os
class Validator():
......@@ -14,7 +17,12 @@ class Validator():
schema = json.load(schema_file)
data = json.load(data_file)
try:
validate(instance=data, schema=schema)
schema_path = self.json_schema.parent.absolute().as_uri()
resolver = RefResolver(base_uri=schema_path,
referrer=schema)
Draft202012Validator(schema=schema,
format_checker=Draft202012Validator.FORMAT_CHECKER,
resolver=resolver).validate(data)
print(f"Validate file: {file_path.parent} / {file_path.name}\n")
except ValidationError as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment