Skip to content

Commit c0b15f7

Browse files
authored
Merge pull request #594 from kif/593_Eiger_from_Dectris
Convert Eiger-master files to CBF
2 parents c8b0dd4 + 6558088 commit c0b15f7

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/fabio/app/eiger2cbf.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
__author__ = "Jerome Kieffer"
3838
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
3939
__licence__ = "MIT"
40-
__date__ = "03/12/2021"
40+
__date__ = "07/10/2024"
4141
__status__ = "production"
4242

4343
import logging
@@ -259,7 +259,7 @@ def convert_one(input_filename, options, start_at=0):
259259
if options.pilatus:
260260
shape = select_pilatus_detecor(shape)
261261

262-
pilatus_headers = cbfimage.PilatusHeader("Silicon sensor, thickness 0.001 m")
262+
pilatus_headers = cbfimage.PilatusHeader()
263263
if isinstance(source, limaimage.LimaImage):
264264
# Populate the Pilatus header from the Lima
265265
entry_name = source.h5.attrs.get("default")
@@ -290,7 +290,27 @@ def convert_one(input_filename, options, start_at=0):
290290
except Exception as e:
291291
logger.warning("Error in searching for exposure time (%s): %s", type(e), e)
292292
elif isinstance(source, eigerimage.EigerImage):
293-
raise NotImplementedError("Please implement Eiger detector data format parsing or at least open an issue")
293+
entry_name = source.h5.attrs.get("default")
294+
if entry_name:
295+
entry = source.h5.get(entry_name)
296+
try:
297+
nxdetector = entry["instrument/detector"]
298+
except:
299+
logger.error("No detector definition in Eiger file, is this a master file ?")
300+
else:
301+
detector = "%s, S/N %s" % (nxdetector["description"][()].decode(),
302+
nxdetector["detector_number"][()].decode())
303+
pilatus_headers["Detector"] = detector
304+
pilatus_headers["Pixel_size"] = (nxdetector["x_pixel_size"][()],
305+
nxdetector["y_pixel_size"][()])
306+
pilatus_headers["Exposure_time"] = nxdetector["count_time"][()]
307+
pilatus_headers["Exposure_period"] = nxdetector["frame_time"][()]
308+
pilatus_headers["Wavelength"] = entry["instrument/beam/incident_wavelength"][()]
309+
pilatus_headers["Detector_distance"] = nxdetector["detector_distance"][()]
310+
pilatus_headers["Beam_xy"] = (nxdetector["beam_center_x"][()],
311+
nxdetector["beam_center_y"][()])
312+
pilatus_headers["sensor"] = (nxdetector["sensor_material"][()].decode(),
313+
nxdetector["sensor_thickness"][()])
294314
else:
295315
raise NotImplementedError("Unsupported format: %s" % source.__class__.__name__)
296316

@@ -307,6 +327,8 @@ def convert_one(input_filename, options, start_at=0):
307327
pilatus_headers["Alpha"] = options.alpha
308328
if options.kappa:
309329
pilatus_headers["Kappa"] = options.kappa
330+
if "sensor" not in pilatus_headers:
331+
pilatus_headers["sensor"] = ("Silicon", 0.001)
310332
formula = None
311333
destination = None
312334
if options.chi is not None:

src/fabio/cbfimage.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
__author__ = "Jérôme Kieffer"
3939
__contact__ = "[email protected]"
4040
__license__ = "MIT"
41-
__date__ = "04/07/2023"
41+
__date__ = "07/10/2024"
4242
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
4343

4444
import os
@@ -923,9 +923,12 @@ def clean_string(cls, input_string):
923923
i += 1
924924
return lines
925925

926-
def __init__(self, content, convention="PILATUS_1.2"):
926+
def __init__(self, content=None, convention="PILATUS_1.2"):
927927
assert convention == "PILATUS_1.2"
928-
self._dict = self._parse(content)
928+
if content:
929+
self._dict = self._parse(content)
930+
else:
931+
self._dict = OrderedDict()
929932

930933
def __repr__(self):
931934
lines = []
@@ -973,3 +976,6 @@ def __setitem__(self, key, value):
973976

974977
def __getitem__(self, key):
975978
return self._dict[key]
979+
980+
def __contains__(self, key):
981+
return key in self._dict

0 commit comments

Comments
 (0)