From a1d2e3687e62e8be508b32d10f27dc12f936b166 Mon Sep 17 00:00:00 2001
From: Egor Sobolev <egor.sobolev@xfel.eu>
Date: Sat, 1 Jun 2024 20:44:09 +0200
Subject: [PATCH] Add function which returns detector shape

---
 src/geomtools/sfx/__init__.py |  4 ++--
 src/geomtools/sfx/misc.py     | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/geomtools/sfx/__init__.py b/src/geomtools/sfx/__init__.py
index e58dfa8..a9c1675 100644
--- a/src/geomtools/sfx/__init__.py
+++ b/src/geomtools/sfx/__init__.py
@@ -6,7 +6,7 @@ from .draw import (plot_cell_parameters, plot_center_shift,
 from .lattice import (cell_volume, get_min_bragg_dist, get_q_from_xyz,
                       ph_en_to_lambda, read_crystfel_cell, spacing)
 from .misc import (avg_pixel_displacement, badpixels_mask, ellipse,
-                   gauss2d_fit, get_peak_position, pixels_to_image,
-                   rmsd_per_group)
+                   gauss2d_fit, get_detector_shape, get_peak_position,
+                   pixels_to_image, rmsd_per_group)
 from .refine import refine_geometry
 from .xwizio import parse_xwiz_summary
diff --git a/src/geomtools/sfx/misc.py b/src/geomtools/sfx/misc.py
index 60f7a89..e3ef0a6 100644
--- a/src/geomtools/sfx/misc.py
+++ b/src/geomtools/sfx/misc.py
@@ -118,6 +118,19 @@ def badpixels_mask(pe, panels, snr=6, min_peak_count=4):
     return px
 
 
+def get_detector_shape(panels):
+    """Returns the shape of detector image array."""
+    ixmax = (
+        panels[['modno', 'orig_max_ss', 'orig_max_fs']].max()
+        .rename({'orig_max_fs': 'fs', 'orig_max_ss': 'ss'})
+    )
+    ixmin = (
+        panels[['modno', 'orig_min_ss', 'orig_min_fs']].min()
+        .rename({'orig_min_fs': 'fs', 'orig_min_ss': 'ss'})
+    )
+    return tuple((ixmax - ixmin + 1).tolist())
+
+
 def pixels_to_image(shape, px, attr='msk'):
     """Transforms dataset of pixels to the image array."""
     img = np.zeros(shape, px[attr].dtype)
-- 
GitLab