Skip to content

Commit 5a7aa96

Browse files
authored
Merge pull request #35 from European-XFEL/dssc-aspect-auto
Get aspect ratio automatically for given detector in notebook
2 parents a409987 + 888c183 commit 5a7aa96

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

geoAssembler/geometry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class GeometryAssembler:
4242
frag_ss_pixels = None
4343
frag_fs_pixels = None
4444
pixel_size = None
45+
pixel_aspect_ratio = 1.
4546
detector_name = 'generic'
4647

4748
def __init__(self, exgeom_obj):
@@ -261,6 +262,7 @@ def quad_pos(self):
261262
class DSSCGeometry(GeometryAssembler):
262263
"""Detector layout for DSSC."""
263264
detector_name = 'DSSC'
265+
pixel_aspect_ratio = 1.5/np.sqrt(3)
264266

265267
def __init__(self, exgeom_obj, filename):
266268
"""Set the properties for DSSC detector.

geoAssembler/nb/notebook.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CircleShape(Ellipse):
2525
type = 'circle'
2626

2727
def __str__(self):
28-
return "Circle(%i)"%self.width
28+
return f"Circle({self.height})"
2929

3030
def __init__(self, centre, diameter, ax, aspect, **kwargs):
3131
"""Create an circle on top of an image with a given aspect ratio.
@@ -45,10 +45,9 @@ def __init__(self, centre, diameter, ax, aspect, **kwargs):
4545
Aspect ratio (width / height)
4646
"""
4747

48-
a = diameter * aspect
49-
b = diameter
48+
width = diameter * aspect
5049
self.aspect = aspect
51-
super().__init__(centre[::-1], a, b,
50+
super().__init__(centre[::-1], width, diameter,
5251
facecolor='none', edgecolor='r', lw=1)
5352

5453
def set_size(self, diameter):
@@ -66,14 +65,14 @@ def get_angle(self):
6665
return 0
6766

6867
def get_size(self):
69-
return self.width
68+
return self.height
7069

7170
class SquareShape(Rectangle):
7271
"""Circular Shape that supporting different aspect ratios."""
7372
type = 'square'
7473

7574
def __str__(self):
76-
return "Square(%i)"%self.get_width()
75+
return f"Square({self.get_height()})"
7776

7877
def __init__(self, centre, size, ax, aspect, angle=0):
7978
"""Create an square on top of an image with a given aspect ratio.
@@ -127,7 +126,7 @@ def set_size(self, size):
127126
self.stale = True
128127

129128
def get_size(self):
130-
return self.get_width()
129+
return self.get_height()
131130

132131
def set_angle(self, angle):
133132
"""Rotate the square by a given angle."""
@@ -145,7 +144,7 @@ class MainWidget:
145144
"""Ipython Widget version of the Calibration Class."""
146145

147146
def __init__(self, raw_data, geometry=None, det='AGIPD', vmin=None,
148-
vmax=None, figsize=None, bg=None, aspect=1, frontview=False,
147+
vmax=None, figsize=None, bg=None, aspect=None, frontview=False,
149148
**kwargs):
150149
"""Display detector data and arrange panels.
151150
@@ -188,7 +187,6 @@ def __init__(self, raw_data, geometry=None, det='AGIPD', vmin=None,
188187
self.data = raw_data
189188
Defaults.check_detector(det)
190189
self.im = None
191-
self.aspect = aspect
192190
self.vmin = vmin or np.nanmin(self.data)
193191
self.vmax = vmax or np.nanmax(self.data)
194192
self.raw_data = np.clip(raw_data, self.vmin, self.vmax)
@@ -207,6 +205,7 @@ def __init__(self, raw_data, geometry=None, det='AGIPD', vmin=None,
207205
self.geom = read_geometry(det, geometry)
208206
else:
209207
self.geom = GeometryAssembler.wrap_extra_geom(geometry)
208+
self.aspect = aspect or self.geom.pixel_aspect_ratio
210209

211210
data, _ = self.geom.position_all_modules(self.raw_data)
212211
# Create a canvas

geoAssembler/nb/tabs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ def _update_navi(self, pos):
199199
"""Add navigation buttons."""
200200
if pos is not None:
201201
quad_offset = self.parent.geom.quad_offsets[pos - 1]
202-
posx_sel = widgets.BoundedIntText(value=quad_offset[1],
202+
posx_sel = widgets.BoundedIntText(value=quad_offset[0],
203203
min=-1000,
204204
max=1000,
205205
step=1,
206206
disabled=False,
207207
continuous_update=True,
208208
description='Horz.')
209-
posy_sel = widgets.BoundedIntText(value=quad_offset[0],
209+
posy_sel = widgets.BoundedIntText(value=quad_offset[1],
210210
min=-1000,
211211
max=1000,
212212
step=1,

0 commit comments

Comments
 (0)