Skip to content

Commit

Permalink
Merge pull request #594 from kif/593_Eiger_from_Dectris
Browse files Browse the repository at this point in the history
Convert Eiger-master files to CBF
  • Loading branch information
kif authored Oct 7, 2024
2 parents c8b0dd4 + 6558088 commit c0b15f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
28 changes: 25 additions & 3 deletions src/fabio/app/eiger2cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__author__ = "Jerome Kieffer"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__licence__ = "MIT"
__date__ = "03/12/2021"
__date__ = "07/10/2024"
__status__ = "production"

import logging
Expand Down Expand Up @@ -259,7 +259,7 @@ def convert_one(input_filename, options, start_at=0):
if options.pilatus:
shape = select_pilatus_detecor(shape)

pilatus_headers = cbfimage.PilatusHeader("Silicon sensor, thickness 0.001 m")
pilatus_headers = cbfimage.PilatusHeader()
if isinstance(source, limaimage.LimaImage):
# Populate the Pilatus header from the Lima
entry_name = source.h5.attrs.get("default")
Expand Down Expand Up @@ -290,7 +290,27 @@ def convert_one(input_filename, options, start_at=0):
except Exception as e:
logger.warning("Error in searching for exposure time (%s): %s", type(e), e)
elif isinstance(source, eigerimage.EigerImage):
raise NotImplementedError("Please implement Eiger detector data format parsing or at least open an issue")
entry_name = source.h5.attrs.get("default")
if entry_name:
entry = source.h5.get(entry_name)
try:
nxdetector = entry["instrument/detector"]
except:
logger.error("No detector definition in Eiger file, is this a master file ?")
else:
detector = "%s, S/N %s" % (nxdetector["description"][()].decode(),
nxdetector["detector_number"][()].decode())
pilatus_headers["Detector"] = detector
pilatus_headers["Pixel_size"] = (nxdetector["x_pixel_size"][()],
nxdetector["y_pixel_size"][()])
pilatus_headers["Exposure_time"] = nxdetector["count_time"][()]
pilatus_headers["Exposure_period"] = nxdetector["frame_time"][()]
pilatus_headers["Wavelength"] = entry["instrument/beam/incident_wavelength"][()]
pilatus_headers["Detector_distance"] = nxdetector["detector_distance"][()]
pilatus_headers["Beam_xy"] = (nxdetector["beam_center_x"][()],
nxdetector["beam_center_y"][()])
pilatus_headers["sensor"] = (nxdetector["sensor_material"][()].decode(),
nxdetector["sensor_thickness"][()])
else:
raise NotImplementedError("Unsupported format: %s" % source.__class__.__name__)

Expand All @@ -307,6 +327,8 @@ def convert_one(input_filename, options, start_at=0):
pilatus_headers["Alpha"] = options.alpha
if options.kappa:
pilatus_headers["Kappa"] = options.kappa
if "sensor" not in pilatus_headers:
pilatus_headers["sensor"] = ("Silicon", 0.001)
formula = None
destination = None
if options.chi is not None:
Expand Down
12 changes: 9 additions & 3 deletions src/fabio/cbfimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
__author__ = "Jérôme Kieffer"
__contact__ = "[email protected]"
__license__ = "MIT"
__date__ = "04/07/2023"
__date__ = "07/10/2024"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"

import os
Expand Down Expand Up @@ -923,9 +923,12 @@ def clean_string(cls, input_string):
i += 1
return lines

def __init__(self, content, convention="PILATUS_1.2"):
def __init__(self, content=None, convention="PILATUS_1.2"):
assert convention == "PILATUS_1.2"
self._dict = self._parse(content)
if content:
self._dict = self._parse(content)
else:
self._dict = OrderedDict()

def __repr__(self):
lines = []
Expand Down Expand Up @@ -973,3 +976,6 @@ def __setitem__(self, key, value):

def __getitem__(self, key):
return self._dict[key]

def __contains__(self, key):
return key in self._dict

0 comments on commit c0b15f7

Please sign in to comment.