Source code for ewokstomo.tasks.online.utils
"""
Preprocessing utilities for tomography reconstruction.
This module provides classes and functions for flat field correction
and phase retrieval operations commonly used in tomography.
"""
import logging
import h5py
from silx.io.dictdump import h5todict
from nabu.io.utils import get_first_hdf5_entry
logger = logging.getLogger(__name__)
[docs]
def get_image_stream_name(scan) -> str:
"""Return the name of the detector image stream in a scan."""
for name in scan.streams:
if ":image" in name:
return name
raise ValueError("No image stream found in scan")
[docs]
def load_reduced_frames(filename, frame_type, hdf5_entry=None):
"""Load reduced frames (darks/flats) from a HDF5 file."""
hdf5_entry = hdf5_entry or get_first_hdf5_entry(filename)
with h5py.File(filename, "r") as f:
res_keys_str = h5todict(
f[hdf5_entry][frame_type],
exclude_names=["count_time", "machine_current", "machine_electric_current"],
)
# In the above dict keys are str, eg. "30". Convert them into integers.
res = {int(k): v for k, v in res_keys_str.items()}
return res