Commit 996e88ef authored by Matias Guijarro's avatar Matias Guijarro
Browse files

Merge branch...

Merge branch '2098-error-in-goto_peak-with-calc-motor-when-the-real-motor-is-not-in-the-session' into 'master'

Resolve "Error in `goto_peak` with Calc Motor when the real motor is not in the session"

Closes #2098

See merge request !2911
parents d16282ef 5d66c1bd
Pipeline #35411 passed with stages
in 4 minutes and 27 seconds
......@@ -5,7 +5,6 @@
# Copyright (c) 2015-2020 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import math
import numpy
from bliss.common.motor_config import MotorConfig
from bliss.common.motor_settings import ControllerAxisSettings, floatOrNone
......@@ -15,8 +14,7 @@ from bliss.common import event
from bliss.physics import trajectory
from bliss.common.utils import set_custom_members, object_method, grouped
from bliss import global_map
from bliss.config.channels import Cache, Channel
from bliss.config import settings
from bliss.config.channels import Cache
from gevent import lock
......@@ -410,18 +408,6 @@ class Controller:
raise NotImplementedError
def remove_real_dependent_of_calc(motors):
"""
remove real motors if depend of a calc axis
"""
realmot = set()
for mot in motors:
ctrl = mot.controller
if isinstance(ctrl, CalcController):
realmot.update(ctrl.reals)
return set(motors) - realmot
class CalcController(Controller):
def __init__(self, *args, **kwargs):
Controller.__init__(self, *args, **kwargs)
......@@ -645,7 +631,7 @@ class CalcController(Controller):
return self._reals_group.state
def set_position(self, axis, new_pos):
if not axis in self.pseudos:
if axis not in self.pseudos:
raise RuntimeError(
"Cannot set dial position on motor '%s` from CalcController" % axis.name
)
......
......@@ -14,7 +14,6 @@ import sys
import time
import datetime
import collections
from functools import wraps
import warnings
from typing import Callable, Any
import typeguard
......@@ -28,12 +27,10 @@ from bliss.common.greenlet_utils import KillMask
from bliss.common.plot import get_flint
from bliss.common.utils import periodic_exec, deep_update
from bliss.scanning.scan_meta import get_user_scan_meta
from bliss.common.axis import Axis
from bliss.common.motor_group import is_motor_group
from bliss.common.utils import Null, update_node_info, round
from bliss.common.profiling import Statistics, time_profile
from bliss.controllers.motor import remove_real_dependent_of_calc
from bliss.config.settings import ParametersWardrobe
from bliss.config.settings import pipeline
from bliss.controllers.motor import Controller
from bliss.config.settings_cache import CacheConnection
from bliss.data.node import _get_or_create_node, _create_node
from bliss.data.scan import get_data
......@@ -954,23 +951,19 @@ class Scan:
else:
self._watchdog_task = None
def _get_data_axes_name(self):
def _get_data_axes(self):
"""
Return all axes in this scan
Return all axes objects in this scan
"""
acq_chain = self._scan_info["acquisition_chain"]
master_axes = []
for top_level_master in acq_chain.keys():
for scalar_master in acq_chain[top_level_master]["master"]["scalars"]:
ma = scalar_master.split(":")[-1]
if ma in self._scan_info["positioners"]["positioners_start"]:
master_axes.append(ma)
if len(master_axes) == 0:
if self._scan_info.get("type") == "timescan":
return ["elapsed_time"]
else:
raise RuntimeError("No axis detected in scan.")
for node in self.acq_chain.nodes_list:
if not isinstance(node, AcquisitionMaster):
continue
if isinstance(node.device, Controller):
master_axes.append(node.device)
if is_motor_group(node.device):
master_axes.extend(node.device.axes.values())
return master_axes
def update_ctrl_params(self, ctrl, new_param_dict):
......@@ -1054,7 +1047,8 @@ class Scan:
return scan_math.cen(*self._get_x_y_data(counter, axis))[0]
def _multimotors(self, func, counter, axis=None, return_axes=False):
axes_names = self._get_data_axes_name()
motors = self._get_data_axes()
axes_names = [axis.name for axis in motors]
res = collections.UserDict()
def info():
......@@ -1071,21 +1065,18 @@ class Scan:
if axis is not None:
if isinstance(axis, str):
assert axis in axes_names or "epoch" in axis or "elapsed_time" in axis
assert axis in axes_names or axis in ["elapsed_time", "epoch"]
else:
assert axis.name in axes_names
res[axis] = func(counter, axis=axis)
elif len(axes_names) == 1 and (
"elapsed_time" in axes_names or "epoch" in axes_names
):
elif len(axes_names) == 1 and axes_names[0] in ["elapsed_time", "epoch"]:
res = {axis: func(counter, axis=axes_names[0])}
else:
##ToDo: does this work for SoftAxis (not always exported)?
motors = [current_session.env_dict[axis_name] for axis_name in axes_names]
# allow "timer axis" for timescan
if self.scan_info.get("type") in ["loopscan", "timescan"]:
motors = ["elapsed_time"]
if len(motors) < 1:
raise
# check if there is some calcaxis with associated real
motors = remove_real_dependent_of_calc(motors)
raise RuntimeError("No axis found in this scan.")
for mot in motors:
res[mot] = func(counter, axis=mot)
......@@ -1096,6 +1087,8 @@ class Scan:
def _goto_multimotors(self, goto):
for key in goto.keys():
if key in ["elapsed_time", "epoch"]:
RuntimeError("Cannot move. Time travel forbidden.")
assert not isinstance(key, str)
with error_cleanup(
*goto.keys(), restore_list=(cleanup_axis.POS,), verbose=True
......
......@@ -79,17 +79,6 @@ def get_selected_counter_name(counter=None):
return alignment_counts.pop()
def last_scan_motor(axis=None):
"""
Return the last motor used in the last scan
"""
if not len(current_session.scans):
raise RuntimeError("No scan available.")
scan = current_session.scans[-1]
axis_name = scan._get_data_axis_name(axis=axis)
return current_session.env_dict[axis_name]
def last_scan_motors():
"""
Return a list of motor used in the last scan
......@@ -97,8 +86,10 @@ def last_scan_motors():
if not len(current_session.scans):
raise RuntimeError("No scan available.")
scan = current_session.scans[-1]
axes_name = scan._get_data_axes_name()
return [current_session.env_dict[axis_name] for axis_name in axes_name]
axes = scan._get_data_axes()
# if not len(axes):
# raise RuntimeError("No axis detected in scan.")
return axes
def _scan_calc(func, counter=None, axis=None, scan=None, marker=True, goto=False):
......@@ -121,6 +112,10 @@ def _scan_calc(func, counter=None, axis=None, scan=None, marker=True, goto=False
label=func + "\n" + str(value),
marker_id=func,
)
if ax in ["elapsed_time", "epoch"]:
continue
# display current position if in scan range
scan_dat = scan.get_data()[ax]
if (
......
......@@ -318,6 +318,29 @@ def test_goto(session):
goto_cen("countername")
def test_issue_2098(default_session):
from bliss.scanning.scan_tools import goto_peak
calc_mot1 = default_session.config.get("calc_mot1")
diode = default_session.config.get("diode")
scans.ascan(calc_mot1, 0, 1, 5, 0.1, diode, save=False)
goto_peak()
def test_softaxis_peak(default_session):
from tests.test_counters import Timed_Diode
from bliss.common.counter import SamplingMode, SoftCounter
from bliss.common.soft_axis import SoftAxis
from bliss.scanning.scan_tools import goto_peak
o = Timed_Diode()
ax = SoftAxis("test-sample-pos", o)
c = SoftCounter(o, "read_last", name="test", mode=SamplingMode.LAST)
scans.ascan(ax, 1, 9, 8, .1, c, save=False)
goto_peak()
def test_com_with_neg_y(default_session):
ob = FixedShapeCounter()
ob.signal = "sawtooth"
......
Supports Markdown
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