Commit ea2e73f4 authored by Matias Guijarro's avatar Matias Guijarro

Merge branch '1367-modify-ctrl_params-on-scans-in-bliss-common-scans' into 'master'

Resolve "modify ctrl_params on scans in bliss.common.scans"

Closes #1367

See merge request !2050
parents ccc583b7 dd2ddc14
Pipeline #21209 canceled with stages
in 9 minutes and 32 seconds
......@@ -35,7 +35,12 @@ from bliss.config.settings import ParametersWardrobe
from bliss.config.settings import pipeline
from bliss.data.node import _get_or_create_node, _create_node, is_zerod
from bliss.data.scan import get_data
from bliss.scanning.chain import AcquisitionSlave, AcquisitionMaster, StopChain
from bliss.scanning.chain import (
AcquisitionSlave,
AcquisitionMaster,
StopChain,
CompletedCtrlParamsDict,
)
from bliss.scanning.writer.null import Writer as NullWriter
from bliss.scanning.scan_math import peak, cen, com
from bliss.scanning.scan_saving import ScanSaving
......@@ -847,6 +852,40 @@ class Scan:
raise RuntimeError("No axis detected in scan.")
return master_axes
def update_ctrl_params(self, ctrl, new_param_dict):
if self.state != ScanState.IDLE:
raise RuntimeError(
"Scan state is not idle. ctrl_params can only be updated before scan starts running."
)
ctrl_acq_dev = None
for acq_dev in self.acq_chain.nodes_list:
if ctrl is acq_dev.device:
ctrl_acq_dev = acq_dev
break
if ctrl_acq_dev is None:
raise RuntimeError(f"Controller {ctrl} not part of this scan!")
## for Bliss 2 we have to see how to do the part below more systematic
## and to avoid hasattr
potential_new_ctrl_params = ctrl_acq_dev.ctrl_params.copy()
potential_new_ctrl_params.update(new_param_dict)
if hasattr(ctrl_acq_dev, "acq_params"):
potential_new_ctrl_params = CompletedCtrlParamsDict(
potential_new_ctrl_params
)
ctrl_acq_dev.validate_params(
ctrl_acq_dev.acq_params, ctrl_params=potential_new_ctrl_params
)
# at least check that no new keys are added
if set(potential_new_ctrl_params.keys()) == set(
ctrl_acq_dev.ctrl_params.keys()
):
ctrl_acq_dev.ctrl_params.update(new_param_dict)
else:
raise RuntimeError(f"New keys can not be added to ctrl_params of {ctrl}")
def _get_x_y_data(self, counter, axis=None):
axis_name = self._get_data_axis_name(axis)
counter_name = counter.name if not isinstance(counter, str) else counter
......
......@@ -601,3 +601,22 @@ def test_typeguard_scanable(default_session):
check_typeguard(True, m0, diode)
check_typeguard(False, diode, diode)
check_typeguard(False, m0, m0)
def test_update_ctrl_params(default_session, beacon, lima_simulator, scan_tmpdir):
scan_saving = default_session.scan_saving
scan_saving.base_path = str(scan_tmpdir)
lima_sim = beacon.get("lima_simulator")
s = scans.loopscan(1, .1, lima_sim, run=False)
with pytest.raises(RuntimeError):
s.update_ctrl_params(lima_sim, {"unkown_key": "bla"})
s.update_ctrl_params(lima_sim, {"saving_format": "EDFGZ"})
s.run()
lima_data_view = s.get_data()["lima_simulator:image"]
lima_data_view._update()
ref_data = lima_data_view.ref_data[0]
assert lima_data_view._get_filenames(ref_data, *range(0, 1))[0][0][-7:] == ".edf.gz"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment