XRR Class
The XRR class is a tool for processing X-ray Reflectivity data obtained with a 2D detector.
This class provides a robust pipeline for converting raw detector images into quantitative reflectivity curves.
Overview
X-ray Reflectivity (XRR) measures the intensity of X-rays reflected from a surface as a function of the incidence angle. The resulting reflectivity curve contains interference fringes (Kiessig fringes) that are characteristic of the Scattering Length Density (SLD) profile perpendicular to the surface.
The XRR class simplifies the analysis of ID10 data by handling the full reduction process:
Data loading Class instance loads the 2D detector images and metadata from file.
2D Data Reduction: The class processes 2D detector images for each point in the XRR scan. It defines regions of interest (ROI) for the specular signal and the background, performing integration and subtraction to obtain the reflected intensity.
Normalization: Intensities are normalized by the direct beam monitor and transmission to account for flux variations and attenuators used during the scan.
Corrections: * Footprint Correction: Corrects for the geometric effect where the beam footprint on the sample exceeds the sample size at low angles. * Attenuator Calibration: Automatically corrects for discrepancies in transmission factors by analyzing overlapping data points (doubles) measured with different attenuator settings.
Data Representation: Calculates the scattering vector $q_z$ and generates the reflectivity curve $R(q_z)$.
Visualization: Offers methods to plot the reflectivity curve (log scale), \(R \cdot q_z^4\), and 2D reciprocal space maps (\(q_x\) vs \(q_z\)) to inspect off-specular scattering.
ORSO Support: Supports saving data in the ORSO (Open Reflectometry Standards Organization) format, ensuring long-term data preservation and interoperability.
Key Features
Automatic Attenuation Handling: Detects and corrects for mismatches between attenuator steps, ensuring a smooth and continuous reflectivity curve.
Footprint Correction: Built-in geometric correction for finite sample sizes, crucial for accurate low-angle data.
q-space Map Generation: Visualizes the intensity distribution in ($q_x, q_z$) space, allowing for the detection of diffuse scattering or sample misalignment.
Standardized Output: Save results in simple ASCII formats or the rich ORSO standard format.
- class ESRF_ID10_SURF.XRR.XRR(file, scans, alpha_i_name='chi', detector_name='mpx_cdte_22_eh1', monitor_name='mon', transmission_name='autof_eh1_transm', att_name='autof_eh1_curratt', cnttime_name='sec', PX0=404, PY0=165, dPX=5, dPY=5, bckg_gap=1, pixel_size_qxz=0.055, pixel_size_qy=0.055, energy_name='monoe', I0=10000000000000.0, saving_dir=None)[source]
Bases:
objectClass for the processing of Surface X-ray Scattering data.
This class handles loading h5 files, region-of-interest based integration of 2D detector data, corrections (footprint, transmission), and plotting.
- Parameters:
file (str)
scans (List[int] | ndarray)
alpha_i_name (str)
detector_name (str)
monitor_name (str)
transmission_name (str)
att_name (str)
cnttime_name (str)
PX0 (int)
PY0 (int)
dPX (int)
dPY (int)
pixel_size_qxz (float)
pixel_size_qy (float)
energy_name (str)
I0 (float)
- file
Path to the HDF5 file containing the data.
- Type:
str
- scans
Array of scan numbers to process.
- Type:
np.ndarray
- alpha_i_name
Name of the incident angle motor/counter.
- Type:
str
- detector_name
Name of the detector data entry.
- Type:
str
- monitor_name
Name of the monitor counter.
- Type:
str
- transmission_name
Name of the transmission counter.
- Type:
str
- att_name
Name of the attenuator positioner.
- Type:
str
- energy_name
Name of the energy positioner.
- Type:
str
- cnttime_name
Name of the counting time counter.
- Type:
str
- PX0
Direct beam X pixel coordinate on detector.
- Type:
int
- PY0
Direct beam Y pixel coordinate on detector.
- Type:
int
- dPX
Half-width of the ROI in X direction.
- Type:
int
- dPY
Half-width of the ROI in Y direction.
- Type:
int
- pixel_size_qxz
Pixel size in reciprocal space (x/z).
- Type:
float
- pixel_size_qy
Pixel size in reciprocal space (y).
- Type:
float
- I0
Incident intensity normalization factor.
- Type:
float
- footprint_correction_applied
Flag if footprint correction was applied.
- Type:
bool
- corrected_doubles
Flag if double points were corrected.
- Type:
bool
- replaced_transmission
Flag if transmission was manually replaced.
- Type:
bool
- is_rebinned
Flag if data has been rebinned.
- Type:
bool
- qz
Calculated qz vector.
- Type:
Optional[np.ndarray]
- reflectivity
Calculated reflectivity.
- Type:
Optional[np.ndarray]
- reflectivity_error
Calculated reflectivity error.
- Type:
Optional[np.ndarray]
- Smap2D
List of 2D maps.
- Type:
List
- Smap2D_e
List of 2D map errors.
- Type:
List
- Qx_map
Qx map for 2D plotting.
- Type:
Optional[np.ndarray]
- Qz_map
Qz map for 2D plotting.
- Type:
Optional[np.ndarray]
- sample_name
Name of the sample.
- Type:
str
- static find_i0_from_z_scan(z, I)[source]
Find I0 (direct beam intensity) from a Z-scan.
- Parameters:
z (np.ndarray) – Z positions.
I (np.ndarray) – Intensity.
- Returns:
I0 value and index of maximum intensity.
- Return type:
Tuple[float, int]
- apply_auto_corrections(sample_size, beam_size, z_scan)[source]
- Parameters:
sample_size (float)
beam_size (float)
z_scan (XRR)
- assert_i0(zgH_scan)[source]
Assert I0 from a zgH scan (direct beam scan).
- Parameters:
zgH_scan (XRR) – Another XRR object representing the direct beam scan.
- calculate_corrected_transmission()[source]
Calculate corrected transmission based on overlapping points (doubles).
- Returns:
Dictionary of corrected transmissions.
- Return type:
Dict[Any, float]
- do_rebin(*args, **kwargs)[source]
Rebin the reflectivity data.
- Parameters:
*args – Arguments passed to rebin function.
**kwargs – Keyword arguments passed to rebin function.
- find_i0(to_print=True)[source]
Find I0, attenuator and transmission at the direct beam.
- Parameters:
to_print (bool, optional) – Whether to print details. Defaults to True.
- Returns:
I0, attenuator value, transmission value.
- Return type:
Tuple[float, Any, float]
- footprint_correction(sample_size=1.0, beam_size=9.6, correct_dir_beam=True)[source]
Apply footprint correction to the reflectivity data.
- Parameters:
sample_size (float, optional) – Sample size in cm. Defaults to 1.
beam_size (float, optional) – Beam size in microns. Defaults to 9.6.
correct_dir_beam (bool, optional) – Whether to correct direct beam region. Defaults to False.
- get_reflectivity()[source]
Get the reflectivity data sorted by qz.
- Returns:
Array containing [qz, reflectivity, reflectivity_error].
- Return type:
np.ndarray
- plot_Qmap(save=False, fig=None, axes=None)[source]
Plot the Q-space map.
- Parameters:
save (bool, optional) – Whether to save the plot. Defaults to False.
fig (Optional[plt.Figure], optional) – Matplotlib figure object. Defaults to None.
axes (Optional[plt.Axes], optional) – Matplotlib axes object. Defaults to None.
- Returns:
The figure and axes objects.
- Return type:
Tuple[plt.Figure, plt.Axes]
- plot_reflectivity(save=False, ax=None, **kwargs)[source]
Plot the reflectivity curve.
- Parameters:
save (bool, optional) – Whether to save the plot. Defaults to False.
ax (Optional[plt.Axes], optional) – Matplotlib axes object. Defaults to None.
- Returns:
The figure and axes objects.
- Return type:
Tuple[plt.Figure, plt.Axes]
- plot_reflectivity_qz4(save=False, ax=None, **kwargs)[source]
Plot reflectivity multiplied by qz^4 (Porod plot).
- Parameters:
save (bool, optional) – Whether to save the plot. Defaults to False.
ax (Optional[plt.Axes], optional) – Matplotlib axes object. Defaults to None.
- Returns:
The figure and axes objects.
- Return type:
Tuple[plt.Figure, plt.Axes]
- produce_Qmap(SDD=900)[source]
Calculate Q-space map.
- Parameters:
SDD (float, optional) – Sample-to-Detector Distance in mm. Defaults to 900.
- replace_transmission(filter_transmission)[source]
Replace transmission values using a dictionary of filter transmissions.
- Parameters:
filter_transmission (Dict[Any, float]) – Mapping of attenuator position to transmission.
- save_Qmap(log_scale=False)[source]
Save the Q-space map to a text file. Format is 3 columns: Q_x, Q_z, Intensity
- Parameters:
log_scale (bool, optional) – Whether to save the logarithm of intensity to the file. Defaults to False.
- save_reflectivity(format='dat', owner='ESRF', creator='opid10', affiliation='Harvard', zgh_scans=None)[source]
Save the reflectivity data to a text file.
- Parameters:
format (str, optional) – Format of the saved file. Options are ‘dat’ and ‘orso’. Defaults to ‘dat’.
owner (str, optional) – Owner of the data. Defaults to ‘ESRF’.
creator (str, optional) – Creator of the reduced file. Defaults to ‘opid10’.
zgh_scans (Optional[List[int]], optional) – List of zgH scan numbers. Defaults to None.
affiliation (str)
- show_detector_image(frame_number=50, ax=None, plot_cross=True)[source]
Show a single frame of the detector image with ROI and background regions.
- Parameters:
frame_number (int, optional) – Frame number to display. Defaults to 50.
ax (Optional[plt.Axes], optional) – Matplotlib axes object. Defaults to None.
plot_cross (bool, optional) – Whether to plot crosshairs at beam center. Defaults to True.