Skip to content

Commit

Permalink
Merge pull request #3030 from pieleric/feat-settingsobserver-should-a…
Browse files Browse the repository at this point in the history
…lso-store-axes-user-friendly-info-if-available

[feat] SettingsObserver should also store axes "user-friendly" info if available
  • Loading branch information
pieleric authored Feb 17, 2025
2 parents 2473651 + a232b07 commit e5e4d59
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/odemis/acq/acqmng.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import logging
import os
import threading
from typing import Set
from typing import Set, Dict

from odemis import model
from odemis.acq import _futures
Expand Down Expand Up @@ -731,11 +731,31 @@ def __init__(self, microscope: model.HwComponent, components: Set[model.HwCompon
continue
# Store current value of VA (calling .value might take some time)
self._all_settings[comp.name][va_name] = [va.value, va.unit]

if va_name == "position" and hasattr(comp, "axes") and isinstance(comp.axes, dict):
# For the .position, the axes definition may contain also the "user-friendly" name
# of the axis, so we can add it to the metadata.
def update_settings(value: Dict[str, float], comp_name=comp.name, va_name=va_name, comp=comp):
try:
axes_def: Dict[str, model.Axis] = comp.axes
value = value.copy()
for axis_name, p in value.items():
if (axis_name in axes_def and hasattr(axes_def[axis_name], "choices")
and isinstance(axes_def[axis_name].choices, dict)
and p in axes_def[axis_name].choices
):
value[axis_name] = f"{p} ({axes_def[axis_name].choices[p]})"
except Exception:
logging.exception("Failed to interpret user-friendly axis info for %s.position", comp_name)

self._all_settings[comp_name][va_name][0] = value
else: # Standard version: just store the VA value as-is
def update_settings(value, comp_name=comp.name, va_name=va_name):
self._all_settings[comp_name][va_name][0] = value

# Subscribe to VA, update dictionary on callback
def update_settings(value, comp_name=comp.name, va_name=va_name):
self._all_settings[comp_name][va_name][0] = value
self._va_updaters.append(update_settings)
va.subscribe(update_settings)
va.subscribe(update_settings, init=True)

def get_all_settings(self):
return copy.deepcopy(self._all_settings)

0 comments on commit e5e4d59

Please sign in to comment.