Further fixes after introducing scan workflow selection
This commit is contained in:
parent
23426ae12c
commit
57b20782a0
3 changed files with 23 additions and 12 deletions
|
|
@ -13,7 +13,8 @@
|
||||||
"smart_scan": {
|
"smart_scan": {
|
||||||
"class": "openflexure_microscope_server.things.smart_scan:SmartScanThing",
|
"class": "openflexure_microscope_server.things.smart_scan:SmartScanThing",
|
||||||
"kwargs": {
|
"kwargs": {
|
||||||
"scans_folder": "/var/openflexure/scans/"
|
"scans_folder": "/var/openflexure/scans/",
|
||||||
|
"default_workflow": "histo_scan_workflow"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"histo_scan_workflow": "openflexure_microscope_server.things.scan_workflows:HistoScanWorkflow",
|
"histo_scan_workflow": "openflexure_microscope_server.things.scan_workflows:HistoScanWorkflow",
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ class SmartScanThing(lt.Thing):
|
||||||
self,
|
self,
|
||||||
thing_server_interface: lt.ThingServerInterface,
|
thing_server_interface: lt.ThingServerInterface,
|
||||||
scans_folder: str,
|
scans_folder: str,
|
||||||
default_workflow: Optional[str],
|
default_workflow: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialise a SmartScanThing saving to and loading from the input directory.
|
"""Initialise a SmartScanThing saving to and loading from the input directory.
|
||||||
|
|
||||||
|
|
@ -147,21 +147,27 @@ class SmartScanThing(lt.Thing):
|
||||||
self._scan_dir_manager = scan_directories.ScanDirectoryManager(scans_folder)
|
self._scan_dir_manager = scan_directories.ScanDirectoryManager(scans_folder)
|
||||||
self._scan_lock = threading.Lock()
|
self._scan_lock = threading.Lock()
|
||||||
self._default_workflow = default_workflow
|
self._default_workflow = default_workflow
|
||||||
self._workflow_name: Optional[str] = None
|
self._workflow_name = default_workflow
|
||||||
|
|
||||||
def __enter__(self) -> Self:
|
def __enter__(self) -> Self:
|
||||||
"""Open hardware connection when the Thing context manager is opened."""
|
"""Open hardware connection when the Thing context manager is opened."""
|
||||||
self._workflow_name = coerce_thing_selector(
|
valid_name = coerce_thing_selector(
|
||||||
thing_mapping=self._all_workflows,
|
thing_mapping=self._all_workflows,
|
||||||
selected=self.workflow_name,
|
selected=self.workflow_name,
|
||||||
default=self._default_workflow,
|
default=self._default_workflow,
|
||||||
)
|
)
|
||||||
|
if valid_name is None:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Could not set Scan Workflow. A Scan Workflow must be present in your "
|
||||||
|
"configuration."
|
||||||
|
)
|
||||||
|
self._workflow_name = valid_name
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Note that the default detector name is set at init. This is over written if
|
# Note that the default detector name is set at init. This is over written if
|
||||||
# setting is loaded from disk.
|
# setting is loaded from disk.
|
||||||
@lt.setting
|
@lt.setting
|
||||||
def workflow_name(self) -> Optional[str]:
|
def workflow_name(self) -> str:
|
||||||
"""The name of the scan workflow selector."""
|
"""The name of the scan workflow selector."""
|
||||||
return self._workflow_name
|
return self._workflow_name
|
||||||
|
|
||||||
|
|
@ -222,13 +228,14 @@ class SmartScanThing(lt.Thing):
|
||||||
if not got_lock:
|
if not got_lock:
|
||||||
raise RuntimeError("Trying to run scan while scan is already running!")
|
raise RuntimeError("Trying to run scan while scan is already running!")
|
||||||
|
|
||||||
|
try:
|
||||||
# `scan_data` should already be None. This is added as a precaution as
|
# `scan_data` should already be None. This is added as a precaution as
|
||||||
# the presence of `scan_data` is used during error handling to
|
# the presence of `scan_data` is used during error handling to
|
||||||
# determine whether the scan started.
|
# determine whether the scan started.
|
||||||
self._scan_data = None
|
self._scan_data = None
|
||||||
# probably make workflow a context manager with a lock?
|
# probably make workflow a context manager with a lock?
|
||||||
workflow = self._workflow
|
workflow = self._workflow
|
||||||
try:
|
|
||||||
workflow.check_before_start(scan_name)
|
workflow.check_before_start(scan_name)
|
||||||
self._ongoing_scan = self._scan_dir_manager.new_scan_dir(scan_name)
|
self._ongoing_scan = self._scan_dir_manager.new_scan_dir(scan_name)
|
||||||
self._latest_scan_name = self.ongoing_scan.name
|
self._latest_scan_name = self.ongoing_scan.name
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,10 @@ def _clear_scan_dir() -> None:
|
||||||
def smart_scan_thing():
|
def smart_scan_thing():
|
||||||
"""Return a smart scan thing as a fixture."""
|
"""Return a smart scan thing as a fixture."""
|
||||||
return create_thing_without_server(
|
return create_thing_without_server(
|
||||||
SmartScanThing, scans_folder=SCAN_DIR, mock_all_slots=True
|
SmartScanThing,
|
||||||
|
scans_folder=SCAN_DIR,
|
||||||
|
default_workflow="mock-_all_workflows",
|
||||||
|
mock_all_slots=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue