Commit 03503be8 authored by Matias Guijarro's avatar Matias Guijarro Committed by Sebastien Petitdemange
Browse files

Fix issue #704 and #874

parent 015c91e5
......@@ -8,9 +8,6 @@
"""
Most common scan procedures (:func:`~bliss.common.scans.ascan`, \
:func:`~bliss.common.scans.dscan`, :func:`~bliss.common.scans.timescan`, etc)
TODO LIST:
* to make ascan a2scan dscan d2scan coherent by using anscan / dnscan ?
"""
__all__ = [
......@@ -115,7 +112,7 @@ def ascan(motor, start, stop, npoints, count_time, *counter_args, **kwargs):
}
if scan_info["title"] is None:
args = scan_info["type"], motor.name, start, stop, npoints, count_time
args = (scan_info["type"], motor.name, start, stop, npoints, count_time)
template = " ".join(["{{{0}}}".format(i) for i in range(len(args))])
scan_info["title"] = template.format(*args)
......@@ -208,7 +205,7 @@ def dscan(motor, start, stop, npoints, count_time, *counter_args, **kwargs):
run = kwargs.pop("run", True)
kwargs["run"] = False
kwargs.setdefault("name", "dscan")
args = kwargs.get("type", "dscan"), motor.name, start, stop, npoints, count_time
args = (kwargs.get("type", "dscan"), motor.name, start, stop, npoints, count_time)
template = " ".join(["{{{0}}}".format(i) for i in range(len(args))])
title = template.format(*args)
kwargs.setdefault("title", title)
......@@ -411,21 +408,6 @@ def dmesh(
kwargs.setdefault("name", "dmesh")
run = kwargs.pop("run", True)
kwargs["run"] = False
if kwargs.get("title") is None:
args = (
kwargs["type"],
motor1.name,
start1,
stop1,
npoints1,
motor2.name,
start2,
stop2,
npoints2,
count_time,
)
template = " ".join(["{{{0}}}".format(i) for i in range(len(args))])
kwargs["title"] = template.format(*args)
start1 += motor1.position
stop1 += motor1.position
......@@ -685,7 +667,14 @@ def anscan(count_time, npoints, *motors_positions, **kwargs):
kwargs.setdefault("start", starts_list)
kwargs.setdefault("stop", stops_list)
scan_type = kwargs.setdefault("type", "a%dscan" % (len(title_list) / 3))
# scan type is forced to be either aNscan or dNscan
scan_type = kwargs.pop("type", None)
if scan_type == "dscan":
scan_type = f"d{len(title_list)//3}scan"
else:
scan_type = f"a{len(title_list)//3}scan"
kwargs["type"] = scan_type
scan_name = kwargs.setdefault("name", scan_type)
if "title" not in kwargs:
args = [scan_type]
......@@ -711,7 +700,6 @@ def dnscan(count_time, npoints, *motors_positions, **kwargs):
counter_list = list()
tmp_l, motors_positions = list(motors_positions), list()
title_list = list()
starts_list = [] # absolute start values.
stops_list = [] # absolute stop values.
old_pos_list = [] # absolute original motor positions.
......@@ -721,29 +709,21 @@ def dnscan(count_time, npoints, *motors_positions, **kwargs):
val = tmp_l.pop(0)
if isinstance(val, Axis):
motors_list.append(val)
oldpos = val.position()
oldpos = val.position
old_pos_list.append(oldpos)
start = tmp_l.pop(0)
starts_list.append(start)
stop = tmp_l.pop(0)
stops_list.append(stop)
title_list.extend((val.name, start, stop))
motors_positions.extend((val, oldpos + start, oldpos + stop))
else:
counter_list.append(val)
run = kwargs.pop("run", True)
kwargs["run"] = False
kwargs["type"] = "dscan"
kwargs.setdefault("start", starts_list)
kwargs.setdefault("stop", stops_list)
scan_type = kwargs.setdefault("type", "d%dscan" % (len(title_list) / 3))
scan_name = kwargs.setdefault("name", scan_type)
if "title" not in kwargs:
args = [scan_type]
args += title_list
args += [npoints, count_time]
template = " ".join(["{{{0}}}".format(i) for i in range(len(args))])
kwargs["title"] = template.format(*args)
motors_positions += counter_list
......@@ -1048,9 +1028,6 @@ def d2scan(
npoints,
count_time,
)
template = " ".join(["{{{0}}}".format(i) for i in range(len(args))])
title = template.format(*args)
kwargs.setdefault("title", title)
kwargs.setdefault("name", "d2scan")
oldpos1 = motor1.position
......
......@@ -764,7 +764,7 @@ class Config:
instance_object = name2items.get(name)
if add_axes_counters:
update_map_for_object(instance_object) # , add_axes_counters)
update_map_for_object(instance_object)
return instance_object
......
......@@ -121,6 +121,49 @@ def test_alias_included_session(alias_session):
assert env_dict["mot0"] is m0
def test_alias_scan_title(alias_session):
env_dict, session = alias_session
robyy = env_dict["robyy"]
m1 = env_dict["m1"]
mot0 = env_dict["mot0"]
diode = session.config.get("diode")
s = scans.ascan(robyy, 0, 1, 3, .1, diode, run=False)
assert "ascan" in s.scan_info["type"]
assert "robyy" in s.scan_info["title"]
s = scans.dmesh(robyy, 0, 1, 3, m1, 0, 1, 3, 0.1, diode, run=False)
assert "dmesh" in s.scan_info["type"]
assert "robyy" in s.scan_info["title"]
assert "m1" in s.scan_info["title"]
s = scans.a2scan(robyy, 0, 1, m1, 0, 1, 3, 0.1, diode, run=False)
assert "a2scan" in s.scan_info["type"]
assert "robyy" in s.scan_info["title"]
assert "m1" in s.scan_info["title"]
s = scans.d2scan(robyy, 0, 1, m1, 0, 1, 3, 0.1, diode, run=False)
assert "d2scan" in s.scan_info["type"]
assert "robyy" in s.scan_info["title"]
assert "m1" in s.scan_info["title"]
# starting from 3, the underlying scan function is 'anscan',
# so it does not need to test aNscan,dNscan with N>3 it is all the
# same code
s = scans.a3scan(robyy, 0, 1, m1, 0, 1, mot0, 0, 1, 3, 0.1, diode, run=False)
assert "a3scan" in s.scan_info["type"]
assert "robyy" in s.scan_info["title"]
assert "m1" in s.scan_info["title"]
assert "mot0" in s.scan_info["title"]
s = scans.d3scan(robyy, 0, 1, m1, 0, 1, mot0, 0, 1, 3, 0.1, diode, run=False)
assert "d3scan" in s.scan_info["type"]
assert "robyy" in s.scan_info["title"]
assert "m1" in s.scan_info["title"]
assert "mot0" in s.scan_info["title"]
def test_alias_add_remove_set_get(alias_session):
env_dict = alias_session.env_dict
roby = alias_session.config.get("roby")
......
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