Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source_id updates and rewriting points of SubscriberScanModel #381

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions ndscan/plots/model/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def d(name):
if schema_revision is None:
return

if not self._title_set:
fqn = d("fragment_fqn")
fqn = d("fragment_fqn")
if not self._title_set or self._context.get_title() != fqn:
if fqn:
self._context.set_title(fqn)
self._title_set = True

if not self._source_id_set:
source_id = d("source_id")
source_id = d("source_id")
if not self._source_id_set or self._context.get_source_id() != source_id:
if source_id:
self._context.set_source_id(source_id)
self._source_id_set = True
Expand Down Expand Up @@ -194,10 +194,21 @@ 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()]):
self._point_data[name] = values.get(self._prefix + "points." + name, [])
self.points_appended.emit(self._point_data)
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]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never accidentally end up with the lists being ndarrays here, right? (Then this would give a bool array.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, they are lists, but it wouldn't hurt using np.array_equal here to avoid issues in the future.

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)

def get_annotations(self) -> list[Annotation]:
return self._annotations
Expand Down
1 change: 0 additions & 1 deletion ndscan/plots/xy_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ 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)
Expand Down