From 619d88bb7a96deed6b7d1d77fe077890b4be06bb Mon Sep 17 00:00:00 2001 From: Alexander Steppke Date: Thu, 7 Dec 2023 10:05:36 +0100 Subject: [PATCH] added copy constructor to ROI --- src/cristallina/utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index 9c90d4c..072f617 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -363,6 +363,7 @@ class ROI: width: int = None, height: int = None, name: str = None, + from_ROI: "ROI" = None, ): if None not in (left, right, bottom, top): ( @@ -378,6 +379,12 @@ class ROI: ) elif None not in (center_x, center_y, width, height): self.from_centers_widths(center_x, center_y, width, height) + elif isinstance(from_ROI, ROI): + self.left = from_ROI.left + self.right = from_ROI.right + self.top = from_ROI.top + self.bottom = from_ROI.bottom + name = from_ROI.name else: raise ValueError("No valid ROI definition.") @@ -416,7 +423,10 @@ class ROI: return self.top - self.bottom def __repr__(self): - return f"ROI(bottom={self.bottom},top={self.top},left={self.left},right={self.right})" + if hasattr(self, "name"): + return f"ROI(bottom={self.bottom},top={self.top},left={self.left},right={self.right},name='{self.name}')" + else: + return f"ROI(bottom={self.bottom},top={self.top},left={self.left},right={self.right})" def __eq__(self, other): # we disregard the name for comparisons @@ -428,7 +438,7 @@ class ROI: ) def __ne__(self, other): - return not self == other + return not self == other def check_pid_offset(step, ch1, ch2, offsets_to_try=[-2, -1, 0, 1, 2], plot=False):