From 3bafb6dbe6bb6e19d8ba23fff77d7ea0318092b1 Mon Sep 17 00:00:00 2001 From: Peter Drmota <49479443+pmldrmota@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:30:18 +0100 Subject: [PATCH 1/6] plots.rolling_1d: always add_source_id_label --- ndscan/plots/rolling_1d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndscan/plots/rolling_1d.py b/ndscan/plots/rolling_1d.py index f227b699..5dc951bb 100644 --- a/ndscan/plots/rolling_1d.py +++ b/ndscan/plots/rolling_1d.py @@ -136,7 +136,7 @@ def _initialise_series(self): if len(self.panes) > 1: self.link_x_axes() - add_source_id_label(self.panes[-1].getViewBox(), self.model.context) + add_source_id_label(self.panes[-1].getViewBox(), self.model.context) self.ready.emit() From 9a3b7e500ab0dfe876a963cf9a4a4a8977cb5606 Mon Sep 17 00:00:00 2001 From: Peter Drmota Date: Fri, 19 Apr 2024 20:31:16 +0100 Subject: [PATCH 2/6] Revert "plots.model.subscriber: emit source_id_changed and points_rewritten" This reverts commit 751752c3b01281bfcbdca78c7dbe67d3698aca0b. --- ndscan/plots/model/subscriber.py | 23 ++++++----------------- ndscan/plots/xy_1d.py | 1 + 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/ndscan/plots/model/subscriber.py b/ndscan/plots/model/subscriber.py index 92d3e8a7..0bf60afb 100644 --- a/ndscan/plots/model/subscriber.py +++ b/ndscan/plots/model/subscriber.py @@ -37,14 +37,14 @@ def d(name): if schema_revision is None: return - fqn = d("fragment_fqn") - if not self._title_set or self._context.get_title() != fqn: + if not self._title_set: + fqn = d("fragment_fqn") if fqn: self._context.set_title(fqn) self._title_set = True - source_id = d("source_id") - if not self._source_id_set or self._context.get_source_id() != source_id: + if not self._source_id_set: + source_id = d("source_id") if source_id: self._context.set_source_id(source_id) self._source_id_set = True @@ -194,21 +194,10 @@ def data_changed(self, values: dict[str, Any], mods: Iterable[dict[str, for name, source in self._analysis_result_sources.items(): source.set(values.get(self._prefix + "analysis_result." + name)) - point_data_changed = False for name in ([f"axis_{i}" for i in range(len(self.axes))] + ["channel_" + c for c in self._channel_schemata.keys()]): - point_values = values.get(self._prefix + "points." + name, []) - if not point_data_changed: - # Check if points were appended or rewritten. - if name in self._point_data: - imax = min(len(point_values), len(self._point_data[name])) - if point_values[:imax] != self._point_data[name][:imax]: - point_data_changed = True - self._point_data[name] = point_values - if point_data_changed: - self.points_rewritten.emit(self._point_data) - else: - self.points_appended.emit(self._point_data) + self._point_data[name] = values.get(self._prefix + "points." + name, []) + self.points_appended.emit(self._point_data) def get_annotations(self) -> list[Annotation]: return self._annotations diff --git a/ndscan/plots/xy_1d.py b/ndscan/plots/xy_1d.py index 2b7d4674..c762cfad 100644 --- a/ndscan/plots/xy_1d.py +++ b/ndscan/plots/xy_1d.py @@ -171,6 +171,7 @@ def __init__(self, model: ScanModel, get_alternate_plot_names): self.model.channel_schemata_changed.connect(self._initialise_series) self.model.points_appended.connect(self._update_points) self.model.annotations_changed.connect(self._update_annotations) + # FIXME: Just re-set values instead of throwing away everything. self.model.points_rewritten.connect(self._rewrite) self.selected_point_model = SelectPointFromScanModel(self.model) From 317477406c7bf6b6adc40cefca71d6357f6bea67 Mon Sep 17 00:00:00 2001 From: Peter Drmota Date: Fri, 19 Apr 2024 20:57:28 +0100 Subject: [PATCH 3/6] plots.model.subscriber: clear applet if source_id changed --- ndscan/plots/model/subscriber.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ndscan/plots/model/subscriber.py b/ndscan/plots/model/subscriber.py index 0bf60afb..4bcd6a17 100644 --- a/ndscan/plots/model/subscriber.py +++ b/ndscan/plots/model/subscriber.py @@ -37,6 +37,14 @@ def d(name): if schema_revision is None: return + source_id = d("source_id") + if self._context.get_source_id() != source_id: + # If the source_id changed, clear the applet. + self._model = None + self._title_set = False + self._source_id_set = False + self._axes_initialised = False + if not self._title_set: fqn = d("fragment_fqn") if fqn: @@ -44,7 +52,6 @@ def d(name): self._title_set = True if not self._source_id_set: - source_id = d("source_id") if source_id: self._context.set_source_id(source_id) self._source_id_set = True From e6fef59e87a18e6ffdf6157dba87818320bb9b21 Mon Sep 17 00:00:00 2001 From: Peter Drmota Date: Fri, 19 Apr 2024 21:21:41 +0100 Subject: [PATCH 4/6] test_plots_model_subscriber: initialise source_id --- test/test_plots_model_subscriber.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_plots_model_subscriber.py b/test/test_plots_model_subscriber.py index be48d29b..363c428f 100644 --- a/test/test_plots_model_subscriber.py +++ b/test/test_plots_model_subscriber.py @@ -13,6 +13,7 @@ def setUp(self): self.context = Context() self.root = SubscriberRoot("ndscan.", self.context) self.datasets = Notifier({ + "ndscan.source_id": (False, "rid_0", {}), "ndscan.axes": (False, "[]", {}), "ndscan.channels": (False, json.dumps({ From ab3a904083ee973f6d72bed8692b5a00b3a84732 Mon Sep 17 00:00:00 2001 From: Peter Drmota Date: Sat, 20 Apr 2024 18:39:11 +0100 Subject: [PATCH 5/6] entry_point: clear points at start of a new scan --- ndscan/experiment/entry_point.py | 11 +++++++++-- ndscan/experiment/result_channels.py | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ndscan/experiment/entry_point.py b/ndscan/experiment/entry_point.py index a79ac6dd..d3caad06 100644 --- a/ndscan/experiment/entry_point.py +++ b/ndscan/experiment/entry_point.py @@ -319,17 +319,18 @@ def build(self, def run(self): """Run the (possibly trivial) scan.""" - self._broadcast_metadata() - if not self.spec.axes and not self._is_time_series: + self._broadcast_metadata() self._run_continuous() return None, {c: s.get_last() for c, s in self._scan_result_sinks.items()} if self._is_time_series: self._timestamp_sink = AppendingDatasetSink( self, self.dataset_prefix + "points.axis_0") + self._timestamp_sink.clear() self._coordinate_sinks = [self._timestamp_sink] self._time_series_start = time.monotonic() + self._broadcast_metadata() self._run_continuous() else: runner = select_runner_class(self.fragment)( @@ -342,6 +343,9 @@ def run(self): AppendingDatasetSink(self, self.dataset_prefix + f"points.axis_{i}") for i in range(len(self.spec.axes)) ] + for sink in self._coordinate_sinks: + sink.clear() + self._broadcast_metadata() runner.run(self.fragment, self.spec, self._coordinate_sinks) self._set_completed() @@ -499,6 +503,9 @@ def push(name, value): else: push(name, ds_value) + for sink in self._scan_result_sinks.values(): + sink.clear() + def create_applet(self, title: str, group: str = "ndscan"): cmd = [ "${python}", "-m ndscan.applet", "--server=${server}", diff --git a/ndscan/experiment/result_channels.py b/ndscan/experiment/result_channels.py index 36b597d5..bbd4bace 100644 --- a/ndscan/experiment/result_channels.py +++ b/ndscan/experiment/result_channels.py @@ -122,6 +122,9 @@ def get_all(self) -> list[Any]: """Read back the previously pushed values from the target dataset (if any).""" return [] if (self.last_value is None) else self.get_dataset(self.key) + def clear(self): + self.set_dataset(self.key, [], broadcast=self.broadcast) + class ScalarDatasetSink(ResultSink, HasEnvironment): """Sink that writes pushed results to a dataset, overwriting its previous value @@ -143,6 +146,9 @@ def get_last(self) -> Any: """Return the last pushed value, or ``None`` if none yet.""" return self.get_dataset(self.key) if self.has_pushed else None + def clear(self): + pass + class ResultChannel: """ From f3b132a9ab0fc10ed75ee74201e37b1c5658ab62 Mon Sep 17 00:00:00 2001 From: Peter Drmota Date: Sat, 20 Apr 2024 18:39:45 +0100 Subject: [PATCH 6/6] plots.model.subscriber: clear points at start of a new scan --- ndscan/plots/model/subscriber.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ndscan/plots/model/subscriber.py b/ndscan/plots/model/subscriber.py index 4bcd6a17..cfdabf59 100644 --- a/ndscan/plots/model/subscriber.py +++ b/ndscan/plots/model/subscriber.py @@ -44,6 +44,10 @@ def d(name): self._title_set = False self._source_id_set = False self._axes_initialised = False + keys = list(values.keys()) + for key in keys: + if "points." in key: + del values[key] if not self._title_set: fqn = d("fragment_fqn")