From 54bad0d5d98cde6ef7bfaacf28f35d37aa8b0634 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 9 Mar 2021 13:57:08 +0100 Subject: [PATCH] made detectors more flexible (allow: one dict or list of strings and/or dicts) --- slic/core/acquisition/broker_client.py | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/slic/core/acquisition/broker_client.py b/slic/core/acquisition/broker_client.py index 96d73338..c9f33810 100644 --- a/slic/core/acquisition/broker_client.py +++ b/slic/core/acquisition/broker_client.py @@ -130,8 +130,7 @@ class BrokerConfig: detectors = self.detectors if detectors: - if isinstance(detectors, list): - detectors = {d: {} for d in detectors} # currently the dicts are empty, thus allow giving just a list as argument + detectors = flatten_detectors(detectors) config["detectors"] = detectors if self.channels: @@ -164,6 +163,37 @@ def split_channels(channels): +def flatten_detectors(dets): + if isinstance(dets, dict): + return harmonize_detector_dict(dets) + + if isinstance(dets, (list, tuple)): + res = {} + for d in dets: + if isinstance(d, dict): + d = harmonize_detector_dict(d) + res.update(d) + elif isinstance(d, str): + res[d] = {} # defaults via empty dict + else: + raise ValueError(f"Cannot interpret \"{d}\" as detector") + return res + + raise ValueError(f"Cannot interpret \"{dets}\" as detector(s)") + + +def harmonize_detector_dict(d): + if "name" in d: + name = d["name"] + d = { + name: { + k: v for k, v in d.items() if k != "name" + } + } + return d + + + def aligned_pids(start, n, rm): """ return start/stop pids aligned to rep rate