jungfrau_utils package¶
jungfrau_utils.data_handler module¶
- class JFDataHandler(detector_name: str)[source]¶
Bases:
objectA class to perform jungfrau detector data handling like pedestal correction, gain conversion, pixel mask, module map, etc.
- Parameters:
detector_name (str) – name of a detector in the form
JF<id>T<nmod>V<version>
- can_convert() bool[source]¶
Whether all data for gain/pedestal conversion is present.
- Returns:
Return true if all data for gain/pedestal conversion is present.
- Return type:
bool
- get_dtype_out(dtype_in: dtype, *, conversion: bool = True) dtype[source]¶
Return resulting image dtype of a detector.
- Parameters:
dtype_in (dtype) – dtype of an input data.
conversion (bool, optional) – Whether data is expected to be converted to keV (apply gain and pedestal corrections). Defaults to True.
- Returns:
dtype of a resulting image.
- Return type:
dtype
- get_gains(images: ndarray[tuple[Any, ...], dtype[_ScalarT]], *, mask: bool = True, gap_pixels: bool = True, double_pixels: str = 'keep', module_edge_pixels: str = 'keep', geometry: bool = True) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]¶
Return gain values of images.
- Parameters:
images (ndarray) – Images to be processed.
mask (bool, optional) – Perform masking of bad pixels (set those values to 0). Defaults to True.
gap_pixels (bool, optional) – Add gap pixels between detector chips. Defaults to True.
double_pixels (str, optional) – A method to handle double pixels in-between ASICs. Can be “keep”, “mask”, or “interp” (resolves into “keep”). Defaults to “keep”.
geometry (bool, optional) – Apply detector geometry corrections. Defaults to True.
- Returns:
Gain values of pixels.
- Return type:
ndarray
- get_pixel_coordinates() tuple[source]¶
Return arrays (x, y, z) of final coordinates for pixels in raw data.
The shape of the result is the same as the raw input data (equivalently, gap_pixels=False, geometry=False), but the coordinates represent pixel positions after gap_pixel and geometry corrections (gap_pixels=True, double_pixels=”keep”, geometry=True).
- get_pixel_mask(*, gap_pixels: bool = True, double_pixels: str = 'keep', module_edge_pixels: str = 'keep', geometry: bool = True) ndarray[tuple[Any, ...], dtype[_ScalarT]] | None[source]¶
Return pixel mask.
- Parameters:
gap_pixels (bool, optional) – Add gap pixels between detector chips. Defaults to True.
double_pixels (str, optional) – A method to handle double pixels in-between ASICs. Can be “keep”, “mask”, or “interp”. Defaults to “keep”.
geometry (bool, optional) – Apply detector geometry corrections. Defaults to True.
- Returns:
Resulting pixel mask, where True values correspond to valid pixels.
- Return type:
ndarray
- get_saturated_pixels(images: ndarray[tuple[Any, ...], dtype[_ScalarT]], *, mask: bool = True, gap_pixels: bool = True, double_pixels: str = 'keep', module_edge_pixels: str = 'keep', geometry: bool = True) tuple[source]¶
Return coordinates of saturated pixels.
- Parameters:
images (ndarray) – Images to be processed.
mask (bool, optional) – Perform masking of bad pixels (set those values to 0). Defaults to True.
gap_pixels (bool, optional) – Add gap pixels between detector chips. Defaults to True.
double_pixels (str, optional) – A method to handle double pixels in-between ASICs. Can be “keep”, “mask”, or “interp” (resolves into “keep”). Defaults to “keep”.
geometry (bool, optional) – Apply detector geometry corrections. Defaults to True.
- Returns:
Indices of saturated pixels.
- Return type:
tuple
- get_shape_out(*, gap_pixels: bool = True, geometry: bool = True) tuple[int, int][source]¶
Return the final image shape of a detector.
- Parameters:
gap_pixels (bool, optional) – Add gap pixels between detector chips. Defaults to True.
geometry (bool, optional) – Apply detector geometry corrections. Defaults to True.
- Returns:
Height and width of a resulting image.
- Return type:
tuple
- process(images: ndarray[tuple[Any, ...], dtype[_ScalarT]], *, conversion: bool = True, mask: bool = True, gap_pixels: bool = True, double_pixels: str = 'keep', module_edge_pixels: str = 'keep', geometry: bool = True, parallel: bool = False, out: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]¶
Perform jungfrau detector data processing like pedestal correction, gain conversion, applying pixel mask, module map, etc.
- Parameters:
images (ndarray) – Image stack or single image to be processed
conversion (bool, optional) – Convert to keV (apply gain and pedestal corrections). Defaults to True.
mask (bool, optional) – Perform masking of bad pixels (set those values to 0). Defaults to True.
gap_pixels (bool, optional) – Add gap pixels between detector chips. Defaults to True.
double_pixels (str, optional) – A method to handle double pixels in-between ASICs. Can be “keep”, “mask”, or “interp”. Defaults to “keep”.
module_edge_pixels (str, optional) – A method to handle pixels at the module edges. Can be “keep” or “mask”. Defaults to “keep”.
geometry (bool, optional) – Apply detector geometry corrections. Defaults to True.
parallel (bool, optional) – Parallelize image stack processing. Defaults to False.
out (ndarray, optional) – If provided, the destination to place the result. The shape must be correct, matching that of what the function would have returned if no out argument were specified. Defaults to None.
- Returns:
Resulting image stack or single image
- Return type:
ndarray
- property detector: NamedTuple¶
A namedtuple of detector parameters extracted from its name (readonly).
- property detector_geometry: DetectorGeometry¶
Detector geometry configuration (readonly).
- property detector_name: str¶
Detector name (readonly).
- property factor: float | None¶
A factor value.
If conversion is True, use this factor to divide converted values. The output values are also rounded and casted to np.int32 dtype. Keep the original values if None.
- property gain: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None¶
Current gain values.
- property gain_file: str¶
Return current gain filepath.
- property highgain: bool¶
Current flag for highgain.
- property module_map: ndarray[tuple[Any, ...], dtype[_ScalarT]]¶
Current module map.
- property pedestal: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None¶
Current pedestal values.
- property pedestal_file: str¶
Return current pedestal filepath.
- property pixel_mask: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None¶
Current raw pixel mask values.
jungfrau_utils.file_adapter module¶
- class File(file_path: str, *, detector_name: str = '', gain_file: str = '', pedestal_file: str = '', conversion: bool = True, mask: bool = True, gap_pixels: bool = True, double_pixels: str = 'keep', module_edge_pixels: str = 'keep', geometry: bool = True, parallel: bool = True)[source]¶
Bases:
objectJungfrau file wrapper.
- Parameters:
file_path (str) – Path to Jungfrau file
detector_name (str, optional) – Name of a detector, which data should be processed if there are multiple detectors’ data present in the file. If empty, the file must contain data for a single detector only. Defaults to ‘’.
gain_file (str, optional) – Path to gain file. Auto-locate if empty. Defaults to ‘’.
pedestal_file (str, optional) – Path to pedestal file. Auto-locate if empty. Defaults to ‘’.
conversion (bool, optional) – Apply gain conversion and pedestal correction. Defaults to True.
mask (bool, optional) – Perform masking of bad pixels (assign them to 0). Defaults to True.
gap_pixels (bool, optional) – Add gap pixels between detector chips. Defaults to True.
double_pixels (str, optional) – A method to handle double pixels in-between ASICs. Can be “keep”, “mask”, or “interp”. Defaults to “keep”.
module_edge_pixels (str, optional) – A method to handle pixels at the module edges. Can be “keep” or “mask”. Defaults to “keep”.
geometry (bool, optional) – Apply geometry correction. Defaults to True.
parallel (bool, optional) – Use parallelized processing. Defaults to True.
- export(dest: str, *, disabled_modules: tuple = (), index: Iterable | None = None, roi: tuple | dict | None = None, downsample: tuple | None = None, compression: bool = False, factor: float | None = None, dtype: dtype | None = None, batch_size: int = 100) None[source]¶
Export processed data into a separate hdf5 file.
- Parameters:
dest (str) – Destination hdf5 file path.
disabled_modules (iterable, optional) – Exclude data of provided module indices from processing. Defaults to ().
index (iterable, optional) – An iterable with indexes of images to be exported. Export all images if None. Defaults to None.
roi (tuple or dict, optional) – A single tuple, or a tuple of tuples with image ROIs in a form (bottom, top, left, right), or a dict where each key is a ROI label and a corresponding value is a tuple with ROI coordinates. Export whole images if None. Defaults to None.
downsample (tuple, optional) – A tuple of 2 integers (N, M). Reduce image size in NxM pixel blocks, resulting in an average of valid pixel values within a block. Effectively no downsampling is happening in case of (1, 1) or None. Defaults to None.
compression (bool, optional) – Apply bitshuffle+lz4 compression. Defaults to False.
factor (float, optional) – If conversion is True, use this factor to divide converted values. The output values are also rounded and casted to np.int32 dtype. Keep the original values if None. Defaults to None.
dtype (np.dtype, optional) – Resulting image data type. Use dtype of the processed data if None. Defaults to None.
batch_size (int, optional) – Process images in batches of that size in order to avoid running out of memory. Defaults to 100.
- get_dtype_out() dtype[source]¶
Return resulting image dtype of a detector.
- Returns:
dtype of a resulting image.
- Return type:
dtype
- get_pixel_mask() ndarray[tuple[Any, ...], dtype[_ScalarT]] | None[source]¶
Return pixel mask, shaped according to gap_pixel and geometry flags.
- Returns:
Resulting pixel mask, where True values correspond to valid pixels.
- Return type:
ndarray
- get_shape_out() tuple[int, int][source]¶
Return the final image shape of a detector, based on gap_pixel and geometry flags.
- Returns:
Height and width of a resulting image.
- Return type:
tuple
- property conversion: bool¶
A flag for applying pedestal correction and gain conversion.
- property detector_name: str¶
Detector name (readonly).
- property double_pixels: str¶
A parameter for making modifications to double pixels.
- property file_path: str¶
- property gain_file: str¶
Gain file path (readonly).
- property gap_pixels: bool¶
A flag for adding gap pixels.
- property geometry: bool¶
A flag for applying geometry.
- property mask: bool¶
A flag for masking bad pixels.
- property module_edge_pixels: str¶
A parameter for making modifications to module edge pixels.
- property parallel: bool¶
A flag for using parallelization.
- property pedestal_file: str¶
Pedestal file path (readonly).
jungfrau_utils.stream_adapter module¶
- class StreamAdapter[source]¶
Bases:
object- process(image: ndarray[tuple[Any, ...], dtype[_ScalarT]], metadata: dict, **kwargs) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]¶
Perform jungfrau detector data processing on an image received via stream.
- Parameters:
image (ndarray) – An image to be processed.
metadata (dict) – A corresponding image metadata.
**kwargs – Extra arguments for JFDataHandler.process() call.
- Returns:
Resulting image.
- Return type:
ndarray
jungfrau_utils.escape_adapter module¶
- class EscapeAdapter(file_path: str, *, detector_name: str = '', gain_file: str = '', pedestal_file: str = '')[source]¶
Bases:
objectAdapter to interface jungfrau data handler with escape library.
- Parameters:
file_path (str) – Path to Jungfrau file, which metadata should be used for jungfrau data handler setup.
detector_name (str, optional) – Name of a detector, which data should be processed if there are multiple detectors’ data present in the file. If empty, the file must contain data for a single detector only. Defaults to ‘’.
gain_file (str, optional) – Path to gain file. Auto-locate if empty. Defaults to “”.
pedestal_file (str, optional) – Path to pedestal file. Auto-locate if empty. Defaults to “”.
- property gain_file: str¶
Gain file path (readonly).
- property pedestal_file: str¶
Pedestal file path (readonly).
- property process: Callable¶
Escape represents jungfrau files as a single array and only needs the process function.
jungfrau_utils.helpers module¶
- reverse_pixel_mask(detector_name: str, mask: ndarray[tuple[Any, ...], dtype[_ScalarT]], gap_pixels: bool = True, geometry: bool = True) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]¶
Get raw pixel mask from processed mask.
- Parameters:
detector_name (str) – Name of the detector.
mask (ndarray) – A processed pixel mask to reverse.
gap_pixels (bool, optional) – Whether processed pixel mask has gap_pixels applied. Defaults to True.
geometry (bool, optional) – Whether processed pixel mask has geometry applied. Defaults to True.
- Returns:
Raw pixel mask.
- Return type:
raw_mask (ndarray)
jungfrau_utils.swissfel_helpers module¶
- get_single_detector_name(file_path: str) str[source]¶
Get detector name from file that contains only single detector data.
- Parameters:
file_path (str) – File path of a jungfrau data file.
- Returns:
Name of single detector in file.
- Return type:
str
- locate_gain_file(file_path: str, *, detector_name: str = '', verbose: bool = True) str[source]¶
Locate gain file in default location at swissfel.
The default gain file location is /sf/jungfrau/config/gainMaps/<detector>/gains.h5`.
- Parameters:
file_path (str) – File path of a jungfrau data file.
detector_name (str, optional) – Name of a detector, which gain file should be located if there are multiple detectors’ data present in the file. If empty, the file must contain data for a single detector only. Defaults to ‘’.
verbose (bool, optional) – Print info about located gain file.
- Returns:
A path to the located gain file.
- Return type:
str
- locate_pedestal_file(file_path: str, *, detector_name: str = '', verbose: bool = True) str[source]¶
Locate pedestal file in default location at swissfel.
The default pedestal file paths for a particula p-group are
<prefix_path>/sf/<beamline>/data/<p-group>/res/JF_pedestals/(old daq) or<prefix_path>/sf/<beamline>/data/<p-group>/raw/JF_pedestals/(new daq), where <prefix_path> is a non-empty string in case of data retrieved from archive.- Parameters:
file_path (str) – File path of a jungfrau data file.
detector_name (str, optional) – Name of a detector, which pedestal file should be located if there are multiple detectors’ data present in the file. If empty, the file must contain data for a single detector only. Defaults to ‘’.
verbose (bool, optional) – Print info about located pedestal file.
- Returns:
A path to the located pedestal file.
- Return type:
str