Skip to content

Commit bf179e2

Browse files
committed
Suggestions from code review:
- Define sizes at the top of the file for visibility - Fail if size is not as expected after any manipulation
1 parent ab03857 commit bf179e2

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/dxtbx/format/FormatNXmxEigerFilewriter.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212

1313
DATA_FILE_RE = re.compile(r"data_\d{6}")
1414

15+
KNOWN_MODULE_SLOW_FAST_DIMS = {
16+
(4362, 4148),
17+
(3262, 3108),
18+
(2162, 2068),
19+
(1062, 1028),
20+
(512, 4148),
21+
(512, 2068),
22+
(512, 1028),
23+
}
24+
KNOWN_MODULE_FAST_SLOW_DIMS = {shape[::-1] for shape in KNOWN_MODULE_SLOW_FAST_DIMS}
25+
1526

1627
class FormatNXmxEigerFilewriter(FormatNXmx):
1728
_cached_file_handle = None
@@ -51,19 +62,13 @@ def _get_nxmx(self, fh: h5py.File):
5162
# Some firmware versions had the detector dimensions swapped. The correct way
5263
# is the number of pixels along the slow axis first, then the fast axis. Here
5364
# swap any that look like they are (fast, slow) instead.
54-
swapped_dims = {
55-
(4148, 4362),
56-
(3108, 3262),
57-
(2068, 2162),
58-
(1028, 1062),
59-
(4148, 512),
60-
(2068, 512),
61-
(1028, 512),
62-
}
6365
for module in nxdetector.modules:
64-
if (tuple(module.data_size)) in swapped_dims:
66+
if (tuple(module.data_size)) in KNOWN_MODULE_FAST_SLOW_DIMS:
6567
module.data_size = module.data_size[::-1]
6668

69+
# Fail if we find an unknown Eiger module size
70+
assert tuple(module.data_size) in KNOWN_MODULE_SLOW_FAST_DIMS
71+
6772
return nxmx_obj
6873

6974
def get_raw_data(self, index):

0 commit comments

Comments
 (0)