AngleCalibration¶
Class to perform angular conversionand 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 MythenDetectorSpecifications, 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
mythendetectorspecifications = MythenDetectorSpecifications(offset=0, num_counters=1)
# setup flatfield
flatfield = FlatField(mythendetectorspecifications)
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(mythendetectorspecifications, 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_initial_calibration_from_file expects a text file in the format below. Each line denotes the DG parameters for each module.
module 0 center 643.320033188550 +- 0.0000 conversion 0.657661167459868E-04 +- 0.0000 offset 0.00000000000000 +- 0.0000
module 1 center 633.044070300816 +- 0.0000 conversion 0.657618957538105E-04 +- 0.0000 offset 5.00486981153634 +- 0.0000
If youre file format deviates from the above format read your file into a np.ndarray(,3) where the first dimension stores the centers the second the conversions and the third the offsets and set DGparameters directly.
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, MythenDetectorSpecifications: angcal::MythenDetectorSpecifications, FlatField: angcal::FlatField, MythenFileReader: angcal::MythenFileReader) None¶
- Parameters:
MythenDetectorSpecifications (MythenDetectorSpecifications) – storing all mythen specific parameters
FlatField (FlatField) – class storing inverse normalized flatfield
MythenFileReader (File Reader to read Mythen acquisition files)
- 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.
calibrate(self: angcal._angcal.AngleCalibration, file_list: list[str], base_peak_angle: float, module_index: int) -> None
calibrates BC parameters for respective module
- file_list: list
List of paths to acquisition files.
- base_peak_angle: float
Angle of base peak center [degree].
- module_index: int
Index of module
calibrate(self: angcal._angcal.AngleCalibration, file_list: list[str], base_peak_angle: float, output_filename: Optional[str]) -> None
calibrates BC parameters for all modules
- file_listlist
list of paths to acquisition files
- base_peak_angledouble
angle of base peak center [degree]
output_filename : str, optional
- convert(self: angcal._angcal.AngleCalibration, file_list: list[str]) numpy.ndarray¶
performs angular conversion e.g. calculates diffraction pattern from raw photon counts
- Parameters:
file_list (list) – list of paths to acquisition files
- Returns:
photon counts redistributed to fixed angle width bins, flatfield corrected and variance scaled photon counts
- Return type:
numpy.ndarray (,num_fixed_angle_width_bins)
- 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
- rate_correction(self: angcal._angcal.AngleCalibration, photon_count: float, photon_count_error: float, exposure_time: float) tuple[float, float]¶
performs rate correction
- Parameters:
photon_count (float) – measured photon counts
photon_count_error (float) – propagated error of measured photon counts
exposure_time (float) – exposure time of acquisition [s]
- Returns:
pair {rate corrected photon counts, propagated_error}
- Return type:
tuple of float
- read_bad_channels_from_file(self: angcal._angcal.AngleCalibration, filename: str) None¶
reads bad channels from file
- read_initial_calibration_from_file(self: angcal._angcal.AngleCalibration, arg0: str) None¶
- reads the historical Detector Group (DG) parameters from file and
transforms them to Best Computing parameters
- write_DG_parameters_to_file(self: angcal._angcal.AngleCalibration, filename: str, parameters: angcal::DGParameters) None¶
writes DG parameters to file
- Parameters:
- filename: str
path to output file
- parameters: DGParameters
DGParameters object containing the parameters to write to file
- property BCparameters¶
current “Best Computing” BC parameters
- property DGparameters¶
historic DG parameters
- property angular_range¶
angular range for conversion [degrees] :returns: (min_angle, max_angle) :rtype: 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
Trueif the channel is bad, otherwiseFalse.- Type:
bad_channels
- 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
- property scale_factor¶
scale factor to scale correction to reasonable values