Commit 623540e2 authored by Valentin Valls's avatar Valentin Valls
Browse files

Normalize with up-to-date spectrum branch

parent ceee7510
......@@ -495,7 +495,7 @@ def get_plot(
print("Argument plot_type uses an invalid value: '%s'." % plot_type)
def convert_roi_to_flint(roi, mode=None):
def convert_roi_to_flint(roi):
"""Convert a received ROI from BLISS to Flint
FIXME: Remove it, the interaction between flint and bliss should use pickle
......@@ -503,7 +503,6 @@ def convert_roi_to_flint(roi, mode=None):
Arguments:
roi: A ROI object from BLISS
mode: A mode used by roi2spectrum
"""
# Avoid cyclic import
from bliss.controllers.lima import roi as lima_roi
......@@ -515,8 +514,9 @@ def convert_roi_to_flint(roi, mode=None):
size=(roi.width, roi.height),
label=roi.name,
)
if mode is not None:
result["reduction"] = mode
if isinstance(roi, lima_roi.RoiProfile):
assert roi.mode in ["horizontal", "vertical"]
result["reduction"] = roi.mode + "_profile"
elif isinstance(roi, lima_roi.ArcRoi):
result = dict(kind="Arc", label=roi.name)
result.update(roi.to_dict())
......@@ -538,11 +538,13 @@ def convert_roi_to_bliss(roi) -> Optional[Tuple[str, Any, Optional[str]]]:
x, y = map(int, map(round, roi["origin"]))
w, h = map(int, map(round, roi["size"]))
mode = roi.get("reduction", None)
if mode not in [None, "vertical", "horizontal"]:
if mode not in [None, "vertical_profile", "horizontal_profile"]:
FLINT_LOGGER.warning(
"ROI %s with unknown reduction mode %s. Skipped.", label, mode
)
return None
if mode is not None:
mode = mode.replace("_profile", "")
return label, (x, y, w, h), mode
elif kind == "arc":
keys = ("cx", "cy", "r1", "r2", "a1", "a2")
......
......@@ -588,7 +588,7 @@ class FlintApi:
- For a rectangle it contains "kind" (which is "Rectangle"), and "label",
"origin" and "size"
- A rectangle can also contain a "reduction" key, which can be one of
"vertical" or "horizontal"
"vertical_profile" or "horizontal_profile"
- For an arc it contains "kind" (which is "Arc"), and "label",
"c1", "c2", "r1", "r2", "a1", "a2" (clockwise, in degree)
......@@ -598,7 +598,7 @@ class FlintApi:
Only rectangles and arcs are supported.
timeout: A timeout to enforce the user to do a selection
kinds: List or ROI kind which can be created (for now, "rectangle",
"arc", "rectangle-vreduction", "rectangle-hreduction")
"arc", "rectangle-vertical-profile", "rectangle-horizontal-profile")
Return:
This method returns an event name which have to be registered to
......
......@@ -451,8 +451,8 @@ class ShapesSelector(Selector):
self.__mapping = {
"rectangle": RectangleROI,
"arc": ArcROI,
"rectangle-vreduction": extra_rois.VerticalReductionLimaRoi,
"rectangle-hreduction": extra_rois.HorizontalReductionLimaRoi,
"rectangle-vertical-profile": extra_rois.HorizontalReductionLimaRoi,
"rectangle-horizontal-profile": extra_rois.VerticalReductionLimaRoi,
}
def setKinds(self, kinds=typing.List[str]):
......@@ -477,9 +477,9 @@ class ShapesSelector(Selector):
reduction = shape.get("reduction", None)
if reduction is None:
roi = RectangleROI()
elif reduction == "vertical":
elif reduction == "horizontal_profile":
roi = extra_rois.VerticalReductionLimaRoi()
elif reduction == "horizontal":
elif reduction == "vertical_profile":
roi = extra_rois.HorizontalReductionLimaRoi()
roi.setGeometry(origin=shape["origin"], size=shape["size"])
roi.setName(shape["label"])
......@@ -510,9 +510,9 @@ class ShapesSelector(Selector):
kind="Rectangle",
)
if isinstance(roi, extra_rois.VerticalReductionLimaRoi):
shape["reduction"] = "vertical"
shape["reduction"] = "horizontal_profile"
elif isinstance(roi, extra_rois.HorizontalReductionLimaRoi):
shape["reduction"] = "horizontal"
shape["reduction"] = "vertical_profile"
shapes.append(shape)
elif isinstance(roi, ArcROI):
shape = dict(
......
......@@ -912,37 +912,42 @@ def edit_roi_counters(detector: Lima, acq_time: Optional[float] = None):
)
roi_counters = detector.roi_counters
roi2spectrum_counters = detector.roi2spectrum_counters
roi_profiles = detector.roi_profiles
# Retrieve all the ROIs
selections = []
for roi in roi_counters.get_rois():
roi_dict = plot_module.convert_roi_to_flint(roi)
selections.append(roi_dict)
config = roi2spectrum_counters.get_roi_modes()
for roi in roi2spectrum_counters.get_rois():
mode = config[roi.name]
roi_dict = plot_module.convert_roi_to_flint(roi, mode)
for roi in roi_profiles.get_rois():
roi_dict = plot_module.convert_roi_to_flint(roi)
selections.append(roi_dict)
deviceName = f"{detector.name} [{roi_counters.config_name}, {roi2spectrum_counters.config_name}]"
deviceName = (
f"{detector.name} [{roi_counters.config_name}, {roi_profiles.config_name}]"
)
print(f"Waiting for ROI edition to finish on {deviceName}...")
selections = plot_proxy.select_shapes(
selections,
kinds=["rectangle", "arc", "rectangle-vreduction", "rectangle-hreduction"],
kinds=[
"rectangle",
"arc",
"rectangle-vertical-profile",
"rectangle-horizontal-profile",
],
)
result = [plot_module.convert_roi_to_bliss(r) for r in selections]
result = [r for r in result if r is not None]
roi_counters.clear()
roi2spectrum_counters.clear()
roi_profiles.clear()
for name, roi, mode in result:
if mode is None:
roi_counters[name] = roi
else:
roi2spectrum_counters[name] = roi
roi2spectrum_counters.set_roi_modes(mode, [name])
roi_profiles[name] = roi
roi_profiles.set_roi_mode(mode, name)
roi_string = ", ".join(sorted([r[0] for r in result]))
print(f"Applied ROIS {roi_string} to {deviceName}")
......
......@@ -122,7 +122,7 @@ def test_select_shapes__rect_reduction(flint_session):
context = []
def active_gui():
result = p.select_shapes(kinds=["rectangle-vreduction"])
result = p.select_shapes(kinds=["rectangle-vertical-profile"])
context.append(result)
def do_actions():
......
......@@ -340,12 +340,12 @@ def test_edit_roi_counters(
cam = beacon.get("lima_simulator")
cam.roi_counters.clear()
cam.roi2spectrum_counters.clear()
cam.roi_profiles.clear()
cam.roi_counters["foo1"] = [20, 20, 18, 20]
cam.roi2spectrum_counters["foo1"] = [20, 20, 18, 20]
cam.roi_profiles["foo1"] = [20, 20, 18, 20]
standard.edit_roi_counters(cam)
assert "roi1" in cam.roi_counters
assert cam.roi_counters["roi1"].width == 100
assert "roi1" in cam.roi2spectrum_counters
assert cam.roi2spectrum_counters["roi1"].width == 200
assert cam.roi2spectrum_counters.get_roi_modes()["roi1"] == "vertical"
assert "roi1" in cam.roi_profiles
assert cam.roi_profiles["roi1"].width == 200
assert cam.roi_profiles.get_roi_modes()["roi1"] == "vertical"
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