Store encoded LST in microscope system metadata
This commit is contained in:
parent
abff27fd47
commit
309b34810c
4 changed files with 43 additions and 14 deletions
|
|
@ -87,13 +87,7 @@ class CaptureAPI(MicroscopeView):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Inject system metadata
|
# Inject system metadata
|
||||||
system_metadata = {
|
output.system_metadata.update(self.microscope.metadata)
|
||||||
"microscope_settings": self.microscope.read_settings(),
|
|
||||||
"microscope_state": self.microscope.state,
|
|
||||||
"microscope_id": self.microscope.id,
|
|
||||||
"microscope_name": self.microscope.name,
|
|
||||||
}
|
|
||||||
output.system_metadata.update(system_metadata)
|
|
||||||
|
|
||||||
# Insert custom metadata
|
# Insert custom metadata
|
||||||
output.put_metadata(metadata)
|
output.put_metadata(metadata)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ from openflexure_microscope.stage.base import BaseStage
|
||||||
from openflexure_microscope.stage.mock import MockStage
|
from openflexure_microscope.stage.mock import MockStage
|
||||||
from openflexure_microscope.camera.base import BaseCamera
|
from openflexure_microscope.camera.base import BaseCamera
|
||||||
from openflexure_microscope.camera.mock import MockStreamer
|
from openflexure_microscope.camera.mock import MockStreamer
|
||||||
|
from openflexure_microscope.camera.pi import PiCameraStreamer
|
||||||
|
|
||||||
|
from openflexure_microscope.utilities import serialise_array_b64
|
||||||
from openflexure_microscope.plugins import PluginLoader
|
from openflexure_microscope.plugins import PluginLoader
|
||||||
from openflexure_microscope.task import TaskOrchestrator
|
from openflexure_microscope.task import TaskOrchestrator
|
||||||
from openflexure_microscope.common.lock import CompositeLock
|
from openflexure_microscope.common.lock import CompositeLock
|
||||||
|
|
@ -270,3 +272,30 @@ class Microscope:
|
||||||
Please use apply_settings method instead."
|
Please use apply_settings method instead."
|
||||||
)
|
)
|
||||||
self.apply_settings(config)
|
self.apply_settings(config)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def metadata(self):
|
||||||
|
"""
|
||||||
|
Microscope system metadata, to be applied to basically all captures
|
||||||
|
"""
|
||||||
|
system_metadata = {
|
||||||
|
"microscope_settings": self.read_settings(),
|
||||||
|
"microscope_state": self.state,
|
||||||
|
"microscope_id": self.id,
|
||||||
|
"microscope_name": self.name,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Store an encoded copy of the PiCamera lens shading table, if it exists
|
||||||
|
if self.camera and isinstance(self.camera, PiCameraStreamer):
|
||||||
|
# Read LST. Returns None if no LST is active
|
||||||
|
lst_arr = self.camera.read_lens_shading_table()
|
||||||
|
|
||||||
|
b64_string, dtype, shape = serialise_array_b64(lst_arr)
|
||||||
|
|
||||||
|
system_metadata["lens_shading_table"] = {
|
||||||
|
"b64_string": b64_string,
|
||||||
|
"dtype": dtype,
|
||||||
|
"shape": shape
|
||||||
|
}
|
||||||
|
|
||||||
|
return system_metadata
|
||||||
|
|
@ -100,13 +100,7 @@ class ScanPlugin(MicroscopePlugin):
|
||||||
tags.append("scan")
|
tags.append("scan")
|
||||||
|
|
||||||
# Inject system metadata
|
# Inject system metadata
|
||||||
system_metadata = {
|
output.system_metadata.update(self.microscope.metadata)
|
||||||
"microscope_settings": self.microscope.read_settings(),
|
|
||||||
"microscope_state": self.microscope.state,
|
|
||||||
"microscope_id": self.microscope.id,
|
|
||||||
"microscope_name": self.microscope.name,
|
|
||||||
}
|
|
||||||
output.system_metadata.update(system_metadata)
|
|
||||||
|
|
||||||
# Insert custom metadata
|
# Insert custom metadata
|
||||||
output.put_metadata(metadata)
|
output.put_metadata(metadata)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,23 @@
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
import operator
|
import operator
|
||||||
|
import base64
|
||||||
|
import numpy as np
|
||||||
from collections import abc
|
from collections import abc
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
|
||||||
|
def deserialise_array_b64(b64_string, dtype, shape):
|
||||||
|
flat_arr = np.fromstring(base64.b64decode(b64_string), dtype)
|
||||||
|
return flat_arr.reshape(shape)
|
||||||
|
|
||||||
|
def serialise_array_b64(npy_arr):
|
||||||
|
b64_string = base64.b64encode(npy_arr).decode('ascii')
|
||||||
|
dtype = str(npy_arr.dtype)
|
||||||
|
shape = npy_arr.shape
|
||||||
|
return b64_string, dtype, shape
|
||||||
|
|
||||||
def get_by_path(root, items):
|
def get_by_path(root, items):
|
||||||
"""Access a nested object in root by item sequence."""
|
"""Access a nested object in root by item sequence."""
|
||||||
return reduce(operator.getitem, items, root)
|
return reduce(operator.getitem, items, root)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue