Moved system metadata into 'system' key. Fixed reloading.
This commit is contained in:
parent
309b34810c
commit
37c514dacb
3 changed files with 10 additions and 7 deletions
|
|
@ -87,7 +87,7 @@ class CaptureAPI(MicroscopeView):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Inject system metadata
|
# Inject system metadata
|
||||||
output.system_metadata.update(self.microscope.metadata)
|
output.put_metadata(self.microscope.metadata, system=True)
|
||||||
|
|
||||||
# Insert custom metadata
|
# Insert custom metadata
|
||||||
output.put_metadata(metadata)
|
output.put_metadata(metadata)
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,11 @@ def capture_from_exif(path, exif_dict):
|
||||||
|
|
||||||
# Populate capture parameters
|
# Populate capture parameters
|
||||||
capture.id = exif_dict["id"]
|
capture.id = exif_dict["id"]
|
||||||
|
|
||||||
capture.timestring = exif_dict["time"]
|
capture.timestring = exif_dict["time"]
|
||||||
capture.format = exif_dict["format"]
|
capture.format = exif_dict["format"]
|
||||||
|
|
||||||
capture.custom_metadata = exif_dict["custom"]
|
capture.custom_metadata = exif_dict["custom"]
|
||||||
|
capture.system_metadata = exif_dict["system"]
|
||||||
capture.tags = exif_dict["tags"]
|
capture.tags = exif_dict["tags"]
|
||||||
|
|
||||||
return capture
|
return capture
|
||||||
|
|
@ -200,14 +200,17 @@ class CaptureObject(object):
|
||||||
|
|
||||||
# HANDLE METADATA
|
# HANDLE METADATA
|
||||||
|
|
||||||
def put_metadata(self, data: dict) -> None:
|
def put_metadata(self, data: dict, system: bool=False) -> None:
|
||||||
"""
|
"""
|
||||||
Merge metadata from a passed dictionary into the capture metadata, and saves.
|
Merge metadata from a passed dictionary into the capture metadata, and saves.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (dict): Dictionary of metadata to be added
|
data (dict): Dictionary of metadata to be added
|
||||||
"""
|
"""
|
||||||
self.custom_metadata.update(data)
|
if system:
|
||||||
|
self.system_metadata.update(data)
|
||||||
|
else:
|
||||||
|
self.custom_metadata.update(data)
|
||||||
self.save_metadata()
|
self.save_metadata()
|
||||||
|
|
||||||
def save_metadata(self) -> None:
|
def save_metadata(self) -> None:
|
||||||
|
|
@ -222,6 +225,7 @@ class CaptureObject(object):
|
||||||
exif_dict = piexif.load(self.file)
|
exif_dict = piexif.load(self.file)
|
||||||
# Serialize metadata
|
# Serialize metadata
|
||||||
metadata_string = json.dumps(self.metadata, cls=JSONEncoder)
|
metadata_string = json.dumps(self.metadata, cls=JSONEncoder)
|
||||||
|
logging.debug(f"Saving metadata string to file: {metadata_string}")
|
||||||
# Insert metadata into exif_dict
|
# Insert metadata into exif_dict
|
||||||
exif_dict["Exif"][piexif.ExifIFD.UserComment] = metadata_string.encode()
|
exif_dict["Exif"][piexif.ExifIFD.UserComment] = metadata_string.encode()
|
||||||
# Convert new exif dict to exif bytes
|
# Convert new exif dict to exif bytes
|
||||||
|
|
@ -241,10 +245,9 @@ class CaptureObject(object):
|
||||||
"format": self.format,
|
"format": self.format,
|
||||||
"tags": self.tags,
|
"tags": self.tags,
|
||||||
"custom": self.custom_metadata,
|
"custom": self.custom_metadata,
|
||||||
|
"system": self.system_metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
d.update(self.system_metadata)
|
|
||||||
|
|
||||||
# Add custom metadata to dictionary
|
# Add custom metadata to dictionary
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ class ScanPlugin(MicroscopePlugin):
|
||||||
tags.append("scan")
|
tags.append("scan")
|
||||||
|
|
||||||
# Inject system metadata
|
# Inject system metadata
|
||||||
output.system_metadata.update(self.microscope.metadata)
|
output.put_metadata(self.microscope.metadata, system=True)
|
||||||
|
|
||||||
# Insert custom metadata
|
# Insert custom metadata
|
||||||
output.put_metadata(metadata)
|
output.put_metadata(metadata)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue