Add more complete Capture object schemas
This commit is contained in:
parent
2d6ead5f80
commit
f2588a506e
2 changed files with 32 additions and 8 deletions
|
|
@ -14,6 +14,28 @@ from labthings.server.find import find_component
|
|||
from marshmallow import pre_dump
|
||||
|
||||
|
||||
class InstrumentSchema(Schema):
|
||||
id = fields.UUID()
|
||||
configuration = fields.Dict()
|
||||
settings = fields.Dict()
|
||||
state = fields.Dict()
|
||||
|
||||
class CaptureMetadataImageSchema(Schema):
|
||||
id = fields.UUID()
|
||||
acquisitionDate = fields.String(format="date")
|
||||
format = fields.String()
|
||||
name = fields.String()
|
||||
tags = fields.List(fields.String())
|
||||
annotations = fields.Dict()
|
||||
|
||||
|
||||
class CaptureMetadataSchema(Schema):
|
||||
experimenter = fields.Dict() # TODO: Make schema
|
||||
experimenterGroup = fields.Dict() # TODO: Make schema
|
||||
dataset = fields.Dict() # TODO: Make schema
|
||||
image = fields.Nested(CaptureMetadataImageSchema())
|
||||
instrument = fields.Nested(InstrumentSchema())
|
||||
|
||||
class CaptureSchema(Schema):
|
||||
id = fields.String()
|
||||
file = fields.String(
|
||||
|
|
@ -21,7 +43,7 @@ class CaptureSchema(Schema):
|
|||
)
|
||||
exists = fields.Bool(data_key="available")
|
||||
name = fields.String()
|
||||
metadata = fields.Dict()
|
||||
metadata = fields.Nested(CaptureMetadataSchema())
|
||||
|
||||
links = fields.Dict()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import os
|
|||
import shutil
|
||||
import glob
|
||||
import datetime
|
||||
import yaml
|
||||
import json
|
||||
import logging
|
||||
from PIL import Image
|
||||
|
|
@ -35,11 +34,9 @@ def pull_usercomment_dict(filepath):
|
|||
try:
|
||||
return json.loads(exif_dict["Exif"][37510].decode())
|
||||
except json.decoder.JSONDecodeError:
|
||||
# TODO: Remove YAML support in a later version
|
||||
logging.warning(
|
||||
f"Capture {filepath} has metadata stored in YAML format. This is now deprecated in favour of JSON."
|
||||
logging.error(
|
||||
f"Capture {filepath} has old, corrupt, or missing OpenFlexure metadata. Unable to reload to server."
|
||||
)
|
||||
return yaml.load(exif_dict["Exif"][37510].decode())
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
@ -68,7 +65,8 @@ def build_captures_from_exif(capture_path):
|
|||
exif = pull_usercomment_dict(f)
|
||||
if exif:
|
||||
capture = capture_from_exif(f, exif)
|
||||
captures.append(capture)
|
||||
if capture:
|
||||
captures.append(capture)
|
||||
else:
|
||||
logging.error("Invalid data at {}. Skipping.".format(f))
|
||||
|
||||
|
|
@ -95,7 +93,11 @@ def capture_from_exif(path, exif_dict):
|
|||
capture.split_file_path(capture.file)
|
||||
|
||||
# Image metadata
|
||||
image_metadata = exif_dict.pop("image")
|
||||
try:
|
||||
image_metadata = exif_dict.pop("image")
|
||||
except KeyError as e:
|
||||
logging.error(f"Unable to obtain OpenFlexure metadata from file {path}")
|
||||
return None
|
||||
|
||||
# Populate capture parameters
|
||||
capture.id = image_metadata.get("id")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue