Area detectors save binary image formats: TIFF, EDF, CBF, HDF5, MAR, Pilatus, and many more. The Python package Fabio decodes some 35 such formats, including their metadata conventions. It is not installed with BornAgain; install it once with
pip install fabio
import fabio
import numpy as np
img = fabio.open("detector_image.tif.gz")
image = np.asarray(img.data, dtype=float)
or, equivalently:
import fabio
img = fabio.open("detector_image.tif.gz")
image = img.data.astype(float)
fabio.open handles compression (.gz, .bz2) transparently and
returns an image object:
img.data — the pixel matrix as a 2D NumPy array of shape
(rows, columns), with the dtype stored in the file (often integer
counts — hence the conversion to float);img.header — a dict with the file’s metadata.The array shape must match the detector pixel layout used by the
simulation, namely (n_alpha, n_phi) for SphericalDetector
intensities, with row 0 at the smallest alpha_f. Verify the row
orientation once per instrument against a known feature — for instance,
the specular peak must sit at alpha_f = alpha_i; if it does not, flip
the image:
image = np.flipud(image)
For a worked example, see expfit_galaxi.py, which fits a GISAS pattern to a TIFF image from the GALAXI instrument.