AngleCalibration

Class to calibrate the mythen detector parameters used for conversion. For the calibration the “Best computing” parameters are used. However, as initial parameters or for conversion it expects the “historic detector group” parameters. See Different Parameter Sets for a more detail description of the different detector parameters.

Example Usage for Conversion:

from angcal import MythenDetector, FlatField, AngleCalibration, EpicsMythenFileReader, MythenFrame
from pathlib import Path
import numpy as np

data_path = Path("/path/to/your/data/files")  # adjust this path

# setup mythen detector specifications - stores all relevant parameters of the detector setup
mythen_detector = MythenDetector()

# setup flatfield
flatfield = FlatField(mythen_detector)

flatfield.normalized_flatfield = np.loadtxt(data_path / "Flatfield_E17p5keV_T12500eV_up_AUGCAL2_Sep2023_open_WS_C_X_X.raw", dtype=np.double, usecols=[1,2])

# setup mythen data file reader to read EPICS mythen hdf5 files
mythenfilereader = EpicsMythenFileReader()

# setup angle calibration - has everything to do conversion and calibration
anglecalibration = AngleCalibration(mythen_detector, flatfield, mythenfilereader)

anglecalibration.read_initial_calibration_from_file(str(data_path / "Angcal_2E_Feb2023_P29.off"))

anglecalibration.read_bad_channels_from_file(str(data_path / "bc2023_003_RING.chans"))

#set scale factor to get reasonable scales
frame = mythenfilereader.read_frame(str(data_path / "Fructose_0p2_60_0060.h5"))
anglecalibration.scale_factor = frame.incident_intensity

file_list = [str(data_path / f"Fructose_0p2_60_006{i}.h5") for i in range(0,4)]

redistributed_photon_counts = anglecalibration.convert(file_list)

API:

Note

The method read_bad_channels_from_file expects a text file using the format below. Each line denotes the index of a bad channel. Consecutive bad channels can be stored on one line e.g. channels with 20-42 are bad channels.

1
2
20-42
100
1002-1004

If youre file format deviates from the above format read your file into a boolean np.ndarray and set bad_channels directly.

class angcal._angcal.AngleCalibration

Bases: pybind11_object

__init__(self: angcal._angcal.AngleCalibration, MythenDetector: angcal::MythenDetector, FlatField: angcal::FlatField) → None
Parameters:
  • MythenDetector (MythenDetector) – storing all mythen specific parameters

  • FlatField (FlatField) – class storing inverse normalized flatfield

base_peak_is_in_module(self: angcal._angcal.AngleCalibration, module_index: int, detector_angle: float) → bool

check if base peak ROI is contained within module region

Parameters:
  • module_index (int) – Index of the module.

  • detector_angle (double) – Detector position, measured as the offset of the first strip from the default detector position [degrees].

Returns:

True if the base peak ROI lies inside the module region, False otherwise.

Return type:

bool

calibrate(*args, **kwargs)

Overloaded function.

  1. calibrate(self: angcal._angcal.AngleCalibration, frames: numpy.ndarray[numpy.uint32], detector_angles: numpy.ndarray[numpy.float64], base_peak_angle: float, module_index: int, plot_calibration_process: bool = False) -> None

    calibrates BC parameters for respective module

    frames: numpy.ndarray of uint32, shape (n_frames, n_channels)

    Array of photon counts for each acquisition frame and channel. (acquisitions need to be ordered by motor position)

    detector_angles: numpy.ndarray of double, shape (n_frames,)

    Array of motor positions corresponding to each frame.

    base_peak_angle: float

    Angle of base peak center [degree].

    module_index: int

    Index of module

    plot_calibration_process: bool, default: false

    Whether to plot the calibration process

  2. calibrate(self: angcal._angcal.AngleCalibration, frames: numpy.ndarray[numpy.uint32], detector_angles: numpy.ndarray[numpy.float64], base_peak_angle: float, plot_calibration_process: bool = False) -> None

    calibrates BC parameters for all modules

    framesnumpy.ndarray of uint32, shape (n_frames, n_channels)

    Array of photon counts for each acquisition frame and channel. (acquisitions need to be ordered by motor position)

    detector_anglesnumpy.ndarray of double, shape (n_frames,)

    Array of motor positions corresponding to each frame.

    base_peak_angledouble

    angle of base peak center [degree]

    plot_calibration_process: bool, default: false

    Whether to plot the calibration process

module_is_disconnected(self: angcal._angcal.AngleCalibration, module_index: int) → bool

check if a module only has bad channels or is disconnected

Parameters:

module_index (int) – Index of the module.

Returns:

True if module is disconnected, False otherwise.

Return type:

bool

read_bad_channels_from_file(self: angcal._angcal.AngleCalibration, filename: str) → None

reads bad channels from file

property DGparameters

DG parameters for each module

Returns:

Each row corresponds to a module and contains the parameters: [center, conversion, offset]

Return type:

numpy.ndarray of float, shape (n_modules, 3)

property angular_range

angular range for conversion [degrees]

Returns:

(min_angle, max_angle)

Return type:

tuple of float

property bad_channels

numpy.ndarray of bool, shape (n_channels,) Expected size: number of channels/strips in the detector. Each element is True if the channel is bad, otherwise False.

Type:

bad_channels

property base_peak_ROI_num_bins

number of bins covered by base peak region of interest default: ‘101’ bins

property base_peak_ROI_width

width of base peak region of interest [degrees] e.g. [base_peak - base_peak_ROI_width, base_peak + base_peak_ROI_width] given in angles default: ‘0.05°’

property base_peak_angle

center of chosen base peak for calibration [degrees]

property histogram_bin_width

bin width of fixed angle width histogram [degrees] default: ‘0.0036°’

property num_fixed_angle_width_bins

number of bins in fixed angle width histogram