From dbe157fe00be8b6e66f4f87e664c751f5d374967 Mon Sep 17 00:00:00 2001 From: Dusten Hubbard Date: Thu, 15 Oct 2026 14:17:13 -0500 Subject: [PATCH 1/2] fix(objects): keep an object's alignment when it is renamed Renaming an object makes a new one under the new name, and the first section saved with it reset its alignment to the series alignment. That section was measured in the old alignment and every later one in the series alignment. A new object now takes the series alignment only when it has none of its own, so a renamed object keeps the one it had. --- PyReconstruct/modules/datatypes/series_data.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PyReconstruct/modules/datatypes/series_data.py b/PyReconstruct/modules/datatypes/series_data.py index 7f79d964f..40298c633 100644 --- a/PyReconstruct/modules/datatypes/series_data.py +++ b/PyReconstruct/modules/datatypes/series_data.py @@ -285,8 +285,10 @@ def updateSection(self, section : Section, update_traces=False, all_traces=True, for obj_name in added_objects: self.series.addLog(obj_name, None, "Create object") - ## Set the fixed alignment of the object to creation - self.series.setAttr(obj_name, "alignment", self.series.alignment) + ## Set the fixed alignment of the object to creation, + ## unless it already has one (a renamed object brings its own) + if self.series.getAttr(obj_name, "alignment") is None: + self.series.setAttr(obj_name, "alignment", self.series.alignment) for obj_name in removed_objects: From 08af2719f9ce1b043f5b54999a3e034186728a0d Mon Sep 17 00:00:00 2001 From: Dusten Hubbard Date: Thu, 15 Oct 2026 14:17:13 -0500 Subject: [PATCH 2/2] test(objects): cover the alignment an object keeps when renamed A renamed object keeps its alignment and is measured in it on every section, and a new object still takes the series alignment. --- tests/test_rename_object_alignment.py | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/test_rename_object_alignment.py diff --git a/tests/test_rename_object_alignment.py b/tests/test_rename_object_alignment.py new file mode 100644 index 000000000..d5144921f --- /dev/null +++ b/tests/test_rename_object_alignment.py @@ -0,0 +1,74 @@ +"""Renaming an object keeps the alignment it is measured in. + +The data is a new series of eight sections with one circular object, traced +under a "default" alignment that rotates and scales each section, plus an +"alt" alignment rotated and scaled against it. +""" + +import math + +import pytest + +from PyReconstruct.modules.datatypes.transform import Transform + + +OBJ = "dend" + + +@pytest.fixture +def series(qapp, tmp_path): + from PyReconstruct.modules.datatypes.series import Series + from PyReconstruct.modules.datatypes.trace import Trace + + images = [str(tmp_path / f"img{i}.tif") for i in range(8)] + s = Series.new(images, "rename", 0.002, 0.05) + + for snum, section in s.enumerateSections(show_progress=False): + a = math.radians(3 + snum) + section.tforms["default"] = Transform([ + 1.05 * math.cos(a), -1.05 * math.sin(a), 0.1 * snum, + 1.05 * math.sin(a), 1.05 * math.cos(a), -0.05 * snum, + ]) + section.tforms["alt"] = section.tforms["default"] * Transform([0.9, -0.1, 0.2, 0.1, 0.9, -0.1]) + trace = Trace(OBJ, (255, 0, 0)) + trace.points = [ + (1 + 0.02 * snum + 0.1 * math.cos(t), 1 + 0.1 * math.sin(t)) + for t in (2 * math.pi * i / 12 for i in range(12)) + ] + section.addTrace(trace) + section.save() + + yield s + s.close() + + +def centroids(data, name): + return {s: [t.getCentroid() for t in traces] for s, traces in data["objects"][name].traces.items()} + + +def test_renaming_keeps_the_object_alignment(series): + from PyReconstruct.modules.datatypes.series_data import SeriesData + + series.setAttr(OBJ, "alignment", "alt") + series.data.refresh() + before = centroids(series.data, OBJ) + + series.editObjectAttributes([OBJ], name="axon", sections=list(series.sections)) + + assert series.getAttr("axon", "alignment") == "alt" + # every section, the first included, is measured in the kept alignment + fresh = SeriesData(series) + fresh.refresh() + assert centroids(series.data, "axon") == centroids(fresh, "axon") == before + + +def test_a_new_object_takes_the_series_alignment(series): + from PyReconstruct.modules.datatypes.trace import Trace + + section = series.loadSection(0) + trace = Trace("spine", (0, 255, 0)) + trace.points = [(2, 2), (2.2, 2), (2.2, 2.2)] + section.addTrace(trace) + section.save() + + assert series.getAttr("spine", "alignment") == series.alignment