From 81e8c2b7c54372c06ab4c3d1cdb653e365bb8bee Mon Sep 17 00:00:00 2001 From: Alexander Steppke Date: Sat, 12 Jul 2025 23:11:19 +0200 Subject: [PATCH] added shift function to ROI --- src/cristallina/utils.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/cristallina/utils.py b/src/cristallina/utils.py index cc866aa..138c447 100644 --- a/src/cristallina/utils.py +++ b/src/cristallina/utils.py @@ -103,12 +103,12 @@ def collect_runs_metadata(pgroup_data_dir: str | os.PathLike): return df -def scan_info(run_number, base_path=None, small_data=True): +def scan_info(run_number, base_path=None, small_data=True, pgroup=None): """Returns SFScanInfo object for a given run number. If there is are small data channels, they will be added (small_data=False to suppress their loading). """ if base_path == None: - base_path = heuristic_extract_base_path() + base_path = heuristic_extract_base_path(pgroup) scan = SFScanInfo(f"{base_path}run{run_number:04}/meta/scan.json") @@ -275,6 +275,11 @@ def process_run( det_pids[only_shots], data[detector][only_shots, bottom:top, left:right].std(axis=(1, 2)), ) + if "max" in calculate: + sd[roi.name + "_max"] = ( + det_pids[only_shots], + data[detector][only_shots, bottom:top, left:right].max(axis=(1, 2)), + ) if "img" in calculate: sd[f"{roi.name}_img"] = ( det_pids[only_shots], @@ -447,6 +452,25 @@ class ROI: @property def height(self): return self.top - self.bottom + + def shift(self, x: float, y: float, inplace=False): + """ Returns a new ROI that is shifted + by x to the left and by y pixels up. + + If `inplace=True` shifts the existing ROI instead. + """ + if not inplace: + return ROI(left=self.left+x, + right=self.right+x, + bottom = self.bottom+y, + top=self.top+y, + name=self.name) + else: + self.left = self.left + x + self.right = self.right + x + self.bottom = self.bottom + y + self.top = self.top + y + def __repr__(self): if hasattr(self, "name"): @@ -539,9 +563,10 @@ def heuristic_extract_pgroup(path=None): raise KeyError("Automatic p-group extraction from the current working directory didn't work.") -def heuristic_extract_base_path(): +def heuristic_extract_base_path(p_number=None): """The function tries to guess the full path where the raw data is saved.""" - p_number = heuristic_extract_pgroup() + if p_number is None: + p_number = heuristic_extract_pgroup() base_path = f"/sf/cristallina/data/p{p_number}/raw/" return base_path