Skip to content

Commit 8c16fde

Browse files
WIP: Feature/fcl workshop changes (#53)
* Rename all mentions of diagnostics --> instruments * Create lens schema and remove from camera schema * Run new jsonschema fmt --indentation 4 * Rename instruments to equipment * Add lens to equipment list in equipment.schema.json * Change all IDs to UUIDs explicitly and add configurationUUID to pulse.schema.json * Add examples for camera and lens equipment * Move 'comment' and 'pulseQuality' into 'pulseInformation'. * move required fields to correct place. * Add pre-pulse flag to signify fields that are set in the UI. * Update heating to coil information and add required fields. * Add back coolant-related fields * Re-add fields * Remove pre-pulse flag and add AC/DC logic to coilInformation. * Make all coolInformation fields required. * Refactor pulse schema: update date fields, rename coilInformation to heatingInformation, and adjust required properties. * Add thermocouple summary fields. * Add new JSON and JQ files for pulse and dataset mapping, and update schema definitions * Refactor dataset and experiment schemas: remove unnecessary fields, update required properties, and add new schema for experiments. * Remove superfluous additionalProperties from ukaea-dataset caught by the linter, and add an ID field * Move ukaea-experiment placeholder to ukaea-schema * Add sampleID to schema * Fix dataset.jq to correctly reference pulseStart, comment, and experimentID; update sourceFolder and additional fields. * First draft of mapping script. * Move comment * Fleshing out experiment bits. * update urls * This should (might) perform a one-to-many mapping so that a dataset gets produced for each diagnostic. * Allow diagnostics to be a single instrument or a combination (expressed as an array). * Fix typo in description of contactPerson property in experiment schema * Fix pulse.schema.json required fields at the wrong level * Fix typo in OutputCurrent, now passes linter and metaschema (minux x- prefix) * Reformat the new files created by NC --------- Co-authored-by: Nathan Cummings <nathan.cummings@hotmail.co.uk>
1 parent fd642ee commit 8c16fde

33 files changed

Lines changed: 659 additions & 277 deletions
File renamed without changes.
File renamed without changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
from pathlib import Path
3+
4+
import jq
5+
import requests
6+
from jsonschema import validate, ValidationError
7+
8+
9+
# Read in pulse json file
10+
with open("pulse.json") as file:
11+
pulse_data = json.load(file)
12+
13+
pulse_directory = Path(
14+
f"/mnt/HIVE/{pulse_data['experimentID']}/{pulse_data['sampleID']}/{pulse_data['pulseID']}"
15+
)
16+
17+
# Query metacat using experimentID to get contactEmail, ownerGroup and owner
18+
contact_email = "<contactEmail>"
19+
owner_group = "<ownerGroup>"
20+
owner = "<owner>"
21+
22+
# Map data to ukaea-dataset schema using dataset.jq
23+
jq_url = "https://ukaea.github.io/ukaea-metadata/metacat-mapping/hive/dataset.jq"
24+
jq_spec = requests.get(jq_url).text
25+
26+
hive_pulse = jq.compile(jq_spec).input(pulse_data).all()
27+
28+
for dataset in hive_pulse:
29+
dataset["contactEmail"] = contact_email
30+
dataset["ownerGroup"] = owner_group
31+
dataset["owner"] = owner
32+
33+
# Validate against ukaea-dataset.schema.json
34+
schema_url = (
35+
"https://ukaea.github.io/ukaea-metadata/ukaea-schema/ukaea-dataset.schema.json"
36+
)
37+
schema = requests.get(schema_url).json()
38+
39+
try:
40+
validate(instance=dataset, schema=schema)
41+
except ValidationError as e:
42+
print(f"Validation error: {e.message}")
43+
44+
output_file = (
45+
pulse_directory
46+
/ Path(f"{dataset['diagnosticID']}")
47+
/ f"{dataset['diagnosticID']}-metadata.json"
48+
)
49+
50+
output_file.parent.mkdir(parents=True, exist_ok=True)
51+
52+
with open(output_file, "w") as file:
53+
json.dump(dataset, file, indent=4)

metacat-mapping/hive/dataset.jq

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
. as $parent
2+
| .diagnostics[]
3+
| {
4+
"creationTime" : $parent.pulseStart,
5+
"type": "raw",
6+
"sourceFolder": "/mnt/HIVE/\(.experimentID)/\(.sampleID)/\(.pulseID)",
7+
"description": $parent.comment,
8+
"experimentID": $parent.experimentID,
9+
"diagnosticID": .diagnosticID,
10+
"additional": (del($parent.comment, $parent.experimentID, $parent.diagnostics))
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import json
2+
3+
import jq
4+
import requests
5+
from jsonschema import validate, ValidationError
6+
7+
8+
# Read in experiment json file
9+
with open("experiment.json") as file:
10+
experiment_data = json.load(file)
11+
12+
# Map data to ukaea-dataset schema using dataset.jq
13+
jq_url = "https://ukaea.github.io/ukaea-metadata/metacat-mapping/hive/experiment.jq"
14+
jq_spec = requests.get(jq_url).text
15+
16+
hive_experiment = jq.compile(jq_spec).input(experiment_data).first()
17+
18+
# Validate against ukaea-dataset.schema.json
19+
schema_url = "https://ukaea.github.io/ukaea-metadata/ukaea-schema/ukaea-experiment.schema.json"
20+
schema = requests.get(schema_url).json()
21+
22+
try:
23+
validate(instance=hive_experiment, schema=schema)
24+
except ValidationError as e:
25+
print(f"Validation error: {e.message}")

metacat-mapping/hive/experiment.jq

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"facility": "HIVE",
3+
"facilityExperimentID": .ID,
4+
"startDate": .startDate,
5+
"endDate": .endDate?,
6+
"description": .description,
7+
"leadInvestigator": .leadInvestigator,
8+
"customer": .customer?
9+
}

ukaea-schema/diagnostics/dic.schema.json

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://w3id.org/fusion/schemas/1.0.0/diagnostics/camera",
4-
"description": "Metadata to describe camera diagnostics",
3+
"$id": "https://w3id.org/fusion/schemas/1.0.0/equipment/camera",
4+
"description": "Metadata to describe camera equipment",
55
"type": "object",
6-
"required": [ "cameraInformation", "lensInformation" ],
6+
"required": [ "deviceInformation" ],
77
"properties": {
8-
"cameraInformation": {
8+
"deviceInformation": {
99
"type": "object",
1010
"required": [ "make", "model", "resolution" ],
1111
"properties": {
@@ -39,49 +39,6 @@
3939
}
4040
}
4141
},
42-
"lensInformation": {
43-
"type": "object",
44-
"required": [ "make", "model", "aperture", "focalLength" ],
45-
"properties": {
46-
"make": {
47-
"type": "string",
48-
"description": "The manufacturer or brand of the lens (e.g., Canon, Nikon, Sigma, Tamron)."
49-
},
50-
"model": {
51-
"type": "string",
52-
"description": "The specific product designation given by the manufacturer, identifying the lens type or version (e.g., EF 24–70mm f/2.8L II USM)."
53-
},
54-
"serialNumber": {
55-
"type": "string",
56-
"description": "A unique identifier assigned by the manufacturer to distinguish an individual lens unit."
57-
},
58-
"aperture": {
59-
"type": "string",
60-
"description": "The maximum aperture size of the lens, usually expressed as an f-number (e.g., f/1.8, f/2.8)."
61-
},
62-
"focalLength": {
63-
"type": "number",
64-
"unit": "qudt:MilliM",
65-
"description": "The focal length or range of the lens in millimeters, determining its angle of view (e.g., 50)."
66-
},
67-
"fieldOfView": {
68-
"type": "object",
69-
"required": [ "x", "y" ],
70-
"properties": {
71-
"x": {
72-
"description": "The field of view in pixels, represented as width.",
73-
"type": "integer",
74-
"unit": "qudt:px"
75-
},
76-
"y": {
77-
"description": "The field of view in pixels, represented as height.",
78-
"type": "integer",
79-
"unit": "qudt:px"
80-
}
81-
}
82-
}
83-
}
84-
},
8542
"captureSettings": {
8643
"type": "object",
8744
"required": [ "imageAcquisitionRate", "imageNoise" ],
@@ -103,4 +60,4 @@
10360
}
10461
}
10562
}
106-
}
63+
}

0 commit comments

Comments
 (0)