From 1613a072114e404ce6f8240ad6b0050f9546df2a Mon Sep 17 00:00:00 2001
From: Simon Wittl <simon.wittl@th-deg.de>
Date: Wed, 20 Nov 2024 10:49:38 +0100
Subject: [PATCH] switch header

---
 README.md                                        |  2 +-
 examples/generated/example_header.json           |  1 -
 examples/generated/example_projection.json       | 16 ++++++++--------
 examples/generated/example_roi.json              |  1 -
 examples/generated/example_volume.json           |  5 +++--
 scripts/generate_example_data.py                 |  3 +--
 scripts/validate_file.py                         |  2 +-
 src/thd_json/header/header.json                  |  1 -
 src/thd_json/image/image.json                    | 14 +++-----------
 src/thd_json/projection/projection.json          |  7 +++----
 .../projection_geometry/projection_geometry.json |  4 ++++
 src/thd_json/validation.py                       |  3 ++-
 src/thd_json/volume/volume.json                  | 14 +++-----------
 13 files changed, 29 insertions(+), 44 deletions(-)

diff --git a/README.md b/README.md
index c19e28d..bf94b38 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ from thd_json.projection import get_projection_validator
 from pathlib import Path
 
 
-FILE = Path("./examples/thd_json/test_thd.json")
+FILE = Path("./examples/generated/example_projection.json")
 
 
 def main():
diff --git a/examples/generated/example_header.json b/examples/generated/example_header.json
index 4fbfdd4..ea5c26e 100644
--- a/examples/generated/example_header.json
+++ b/examples/generated/example_header.json
@@ -1,4 +1,3 @@
 {
-    "timestamp": "2000-01-01T00:00:00Z",
     "uuid": ""
 }
\ No newline at end of file
diff --git a/examples/generated/example_projection.json b/examples/generated/example_projection.json
index e6f1976..116f088 100644
--- a/examples/generated/example_projection.json
+++ b/examples/generated/example_projection.json
@@ -5,14 +5,11 @@
         "pixel_pitch_height_mm": 0.001,
         "pixel_pitch_width_mm": 0.001
     },
-    "header": {
-        "timestamp": "2000-01-01T00:00:00Z",
-        "uuid": ""
-    },
     "image": {
-        "image_path": ".tif",
-        "timestamp": "2000-01-01T00:00:00Z",
-        "uuid": ""
+        "header": {
+            "uuid": ""
+        },
+        "image_path": ".tif"
     },
     "projection_geometry": {
         "detector_center_orientation_quat": [
@@ -30,6 +27,9 @@
             0.0,
             0.0,
             0.0
-        ]
+        ],
+        "header": {
+            "uuid": ""
+        }
     }
 }
\ No newline at end of file
diff --git a/examples/generated/example_roi.json b/examples/generated/example_roi.json
index d724047..8a3fe38 100644
--- a/examples/generated/example_roi.json
+++ b/examples/generated/example_roi.json
@@ -1,6 +1,5 @@
 {
     "header": {
-        "timestamp": "2000-01-01T00:00:00Z",
         "uuid": ""
     },
     "roi_center_position_mm": [
diff --git a/examples/generated/example_volume.json b/examples/generated/example_volume.json
index 84956ac..fc969be 100644
--- a/examples/generated/example_volume.json
+++ b/examples/generated/example_volume.json
@@ -1,5 +1,6 @@
 {
-    "timestamp": "2000-01-01T00:00:00Z",
-    "uuid": "",
+    "header": {
+        "uuid": ""
+    },
     "volume_path": ".tif"
 }
\ No newline at end of file
diff --git a/scripts/generate_example_data.py b/scripts/generate_example_data.py
index f364274..e7bd7a0 100644
--- a/scripts/generate_example_data.py
+++ b/scripts/generate_example_data.py
@@ -3,7 +3,6 @@ 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 thd_json.detector import get_detector_validator
-from thd_json.image import get_image_validator
 from thd_json.roi import get_roi_validator
 from thd_json.volume import get_volume_validator
 from hypothesis import given, settings
@@ -20,7 +19,7 @@ def main():
         ("header", get_header_validator),
         ("source", get_source_validator),
         ("detector", get_detector_validator),
-        ("image", get_image_validator),
+        # ("image", get_image_validator),
         ("roi", get_roi_validator),
         ("volume", get_volume_validator),
     ]:
diff --git a/scripts/validate_file.py b/scripts/validate_file.py
index 2b27d3a..cb1c100 100644
--- a/scripts/validate_file.py
+++ b/scripts/validate_file.py
@@ -2,7 +2,7 @@ from thd_json.projection import get_projection_validator
 from pathlib import Path
 
 
-FILE = Path("./examples/thd_json/test_thd.json")
+FILE = Path("./examples/generated/example_projection.json")
 
 
 def main():
diff --git a/src/thd_json/header/header.json b/src/thd_json/header/header.json
index 73ef475..091c90f 100644
--- a/src/thd_json/header/header.json
+++ b/src/thd_json/header/header.json
@@ -17,7 +17,6 @@
         }
     },
     "required": [
-        "timestamp",
         "uuid"
     ],
     "additionalProperties": false
diff --git a/src/thd_json/image/image.json b/src/thd_json/image/image.json
index ff2f882..e7cdec4 100644
--- a/src/thd_json/image/image.json
+++ b/src/thd_json/image/image.json
@@ -5,15 +5,8 @@
     "version": 0.6,
     "date": "19.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"
+        "header": {
+            "$ref": "../header/header.json"
         },
         "image_path": {
             "type": "string",
@@ -22,8 +15,7 @@
         }
     },
     "required": [
-        "timestamp",
-        "uuid",
+        "header",
         "image_path"
     ],
     "additionalProperties": false
diff --git a/src/thd_json/projection/projection.json b/src/thd_json/projection/projection.json
index 7868d0b..2bc9dcb 100644
--- a/src/thd_json/projection/projection.json
+++ b/src/thd_json/projection/projection.json
@@ -5,15 +5,15 @@
     "version": 0.6,
     "date": "19.11.2024",
     "properties": {
-      "header": {
-        "$ref": "./header/header.json"
-      },
       "image": {
         "$ref": "./image/image.json"
       },
       "projection_geometry": {
         "$ref": "./projection_geometry/projection_geometry.json"
       },
+      "projection_geometry_nominal": {
+        "$ref": "./projection_geometry/projection_geometry.json"
+      },
       "detector": {
         "$ref": "./detector/detector.json"
       },
@@ -22,7 +22,6 @@
       }
     },
     "required": [
-      "header",
       "projection_geometry",
       "detector",
       "image"
diff --git a/src/thd_json/projection_geometry/projection_geometry.json b/src/thd_json/projection_geometry/projection_geometry.json
index bc376b5..bb7d2c0 100644
--- a/src/thd_json/projection_geometry/projection_geometry.json
+++ b/src/thd_json/projection_geometry/projection_geometry.json
@@ -5,6 +5,9 @@
     "version": 0.6,
     "date": "19.11.2024",
     "properties": {
+      "header": {
+        "$ref": "../header/header.json"
+      },
       "focal_spot_position_mm": {
         "type": "array",
         "description": "Position of the focal spot in millimeters.",
@@ -61,6 +64,7 @@
       }
     },
     "required": [
+      "header",
       "focal_spot_position_mm",
       "detector_center_position_mm",
       "detector_center_orientation_quat"
diff --git a/src/thd_json/validation.py b/src/thd_json/validation.py
index 40cf875..c1829ae 100644
--- a/src/thd_json/validation.py
+++ b/src/thd_json/validation.py
@@ -39,9 +39,10 @@ class Validator:
         return True
 
     def get_schema(self):
+        schema_path = self.json_schema.parent.absolute().as_uri()
         with open(str(self.json_schema)) as schema_file:
             schema = json.load(schema_file)
-            schema_path = self.json_schema.parent.absolute().as_uri()
+
             resolver = RefResolver(base_uri=schema_path, referrer=schema)
 
             return self.resolve_ref(resolver, schema)
diff --git a/src/thd_json/volume/volume.json b/src/thd_json/volume/volume.json
index 122db50..3fe7ff1 100644
--- a/src/thd_json/volume/volume.json
+++ b/src/thd_json/volume/volume.json
@@ -5,15 +5,8 @@
     "version": 0.6,
     "date": "20.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"
+        "header": {
+            "$ref": "./header/header.json"
         },
         "volume_path": {
             "type": "string",
@@ -22,8 +15,7 @@
         }
     },
     "required": [
-        "timestamp",
-        "uuid",
+        "header",
         "volume_path"
     ],
     "additionalProperties": false
-- 
GitLab