GID Class
The GID class provides a framework for analyzing Grazing Incidence Diffraction data taken with a linear detector and Soller collimator.
The class manages data loading, normalization, and transformation into reciprocal space, providing an interface for simple analysis.
This is complimented by a simple peak fitting procedure to quickly estimate peak parameters.
Overview
Grazing Incidence Diffraction (GID) involves directing X-rays at a surface at a very shallow angle, typically below the critical angle for total external reflection. This configuration maximizes surface sensitivity and minimizes background signal from the bulk substrate. The scattered intensity is recorded as a function of the in-plane scattering angle and the out-of-plane angle, providing information about the lateral organization of molecules or atoms at the interface.
The GID class is designed to facilitate analysis of these measurements at the ID10-SURF beamline at ESRF. It automates the following steps:
Data Loading: Reads raw data from HDF5 files generated by the beamline control system. It handles single or multiple scans, concatenating them as needed.
Normalization: Corrects raw counts for monitor intensity and filter transmission.
Reciprocal Space Conversion: Converts detector pixel coordinates and motor angles into scattering vectors (\(q_{xy}\) and \(q_z\)). This conversion takes into account a gap between two modules of the Mythen detector, typically used for these experiments.
Visualization: Provides built-in methods to plot 2D maps of intensity in reciprocal space, as well as 1D cuts (profiles) along specific directions (\(q_{xy}\) or \(q_z\)).
Analysis: Includes methods for fitting peaks using various lineshapes (Gaussian, Lorentzian, Voigt) to extract structural parameters like lattice spacing and coherence length.
Key Features
Flexible ROI Integration: Easily extract 1D intensity profiles by integrating over a region of interest (ROI) in the q-space.
Automated Plotting: Quick “standard analysis” plots allow for immediate data inspection during or after an experiment.
Data Export: Save processed data (cuts, 2D maps) in standard formats (ASCII .dat, HDF5, images) for publication or further analysis with external tools.
- class ESRF_ID10_SURF.GID.GID(file, scans, alpha_i_name='chi', detector_name='mythen2', monitor_name='mon', transmission_name='autof_eh1_transm', att_name='autof_eh1_curratt', cnttime_name='sec', PX0=50, mythen_gap=120, PPD=198.5, pixel_size_qxz=0.055, angle_name='delta', energy_name='monoe', I0=1000000000000.0, saving_dir=None, *args, **kwargs)[source]
Bases:
objectMain class for processing GID (Grazing Incidence Diffraction) data.
This class handles loading data from HDF5 files, processing it (normalization, conversion to reciprocal space), and visualizing/saving the results.
- file
Path to the HDF5 data file.
- Type:
str
- scans
Array of scan numbers to be processed.
- Type:
np.ndarray
- alpha_i_name
Name of the incident angle motor/counter.
- Type:
str
- detector_name
Name of the detector dataset.
- 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 counter.
- Type:
str
- cnttime_name
Name of the counting time counter.
- Type:
str
- angle_name
Name of the angle motor (e.g., ‘delta’).
- Type:
str
- energy_name
Name of the energy motor.
- Type:
str
- PX0
Pixel index of the direct beam (or reference pixel).
- Type:
float
- mythen_gap
Gap size in pixels between detector modules.
- Type:
int
- PPD
Pixels per degree calibration factor.
- Type:
float
- I0
Incident intensity normalization factor.
- Type:
float
- saving_dir
Directory where output files will be saved.
- Type:
str
- data
Raw detector data.
- Type:
np.ndarray
- angle
Array of angles corresponding to the data.
- Type:
np.ndarray
- alpha_i
Incident angle values.
- Type:
np.ndarray
- monitor
Monitor counts.
- Type:
np.ndarray
- transmission
Transmission values.
- Type:
np.ndarray
- attenuator
Attenuator values.
- Type:
np.ndarray
- cnttime
Counting times.
- Type:
np.ndarray
- energy
Beam energy in keV.
- Type:
float
- sample_name
Name of the sample extracted from metadata.
- Type:
str
- Pi
Surface pressure (Pi) value if available.
- Type:
int or str
- data_gap
Processed 2D data map with gap handling.
- Type:
np.ndarray
- qz
Array of qz values.
- Type:
np.ndarray
- qxy
Array of qxy values.
- Type:
np.ndarray
- analyze_peak(x, y, model='voigt', background='linear', limits=None, save=False, filename_prefix='fit_result', **kwargs)[source]
Wrapper for fit_profile to perform analysis, plotting, and saving.
- Parameters:
x (np.ndarray) – The independent variable array.
y (np.ndarray) – The dependent variable array.
model (str, optional) – Fitting model. Defaults to ‘voigt’.
background (str, optional) – Background model. Defaults to ‘linear’.
limits (tuple, optional) – Fitting limits (min, max). Defaults to None.
save (bool, optional) – Whether to save plots and reports. Defaults to False.
filename_prefix (str, optional) – Prefix for saved files. Defaults to ‘fit_result’.
**kwargs – Extra arguments for fit_profile or lmfit.
- Returns:
The result object from fit_profile.
- Return type:
lmfit.model.ModelResult
- fit_profile(x, y, model='gaussian', background='linear', limits=None, **kwargs)[source]
Fit a profile to the specified model with background using lmfit.
- Parameters:
x (np.ndarray) – The independent variable array (e.g., q).
y (np.ndarray) – The dependent variable array (e.g., Intensity).
model (str, optional) – The peak model to use. Options are ‘gaussian’, ‘lorentzian’, ‘voigt’, ‘pseudo_voigt’. Defaults to ‘gaussian’.
background (str, optional) – The background model. Options are ‘linear’, ‘constant’, or None. Defaults to ‘linear’.
limits (tuple, optional) – A tuple (min, max) to restrict the fitting range. Defaults to None (use full range).
**kwargs – Additional keyword arguments passed to mod.fit.
- Returns:
The result of the fit.
- Return type:
lmfit.model.ModelResult
- Raises:
ValueError – If an unknown model is specified.
- get_qxy(angle)[source]
Calculate the horizontal scattering vector qxy.
- Parameters:
angle (float or np.ndarray) – In-plane scattering angle in degrees.
- Returns:
qxy value(s) in inverse Angstroms.
- Return type:
float or np.ndarray
- get_qxy_cut(qz_min, qz_max)[source]
Extract a 1D cut along qxy by integrating over a range of qz.
- Parameters:
qz_min (float) – Minimum qz value.
qz_max (float) – Maximum qz value.
- Returns:
- A list containing [qxy, intensity_profile].
intensity_profile is sum of counts in the qz range.
- Return type:
list
- get_qz(pixels)[source]
Calculate the vertical scattering vector qz.
- Parameters:
pixels (np.ndarray) – Array of pixel indices (vertical position on detector).
- Returns:
Array of qz values in inverse Angstroms.
- Return type:
np.ndarray
- get_qz_cut(qxy_min, qxy_max)[source]
Extract a 1D cut along qz by integrating over a range of qxy.
- Parameters:
qxy_min (float) – Minimum qxy value.
qxy_max (float) – Maximum qxy value.
- Returns:
A list containing [qz, intensity_profile].
- Return type:
list
- plot_2D_image(ax=None, save=False, **kwargs)[source]
Plot the 2D GID map in reciprocal space (qxy vs qz).
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure is created.
save (bool, optional) – Whether to save the figure to disk. Defaults to False.
**kwargs – Additional arguments passed to imshow.
- Returns:
The axes containing the plot.
- Return type:
matplotlib.axes.Axes
- plot_quick_analysis(save=False, fig=None)[source]
Perform a quick standard analysis plot including the 2D map and representative qxy cuts.
- Parameters:
save (bool, optional) – Whether to save the figure. Defaults to False.
- plot_qxy_cut(qz_min, qz_max, ax=None, save=False, **kwargs)[source]
Plot the qxy cut.
- Parameters:
qz_min (float) – Minimum qz value.
qz_max (float) – Maximum qz value.
ax (matplotlib.axes.Axes, optional) – Axes to plot on.
save (bool, optional) – Whether to save the figure. Defaults to False.
**kwargs – Additional arguments.
- plot_qz_cut(qxy_min, qxy_max, ax=None, save=False, **kwargs)[source]
Plot the qz cut.
- Parameters:
qxy_min (float) – Minimum qxy value.
qxy_max (float) – Maximum qxy value.
ax (matplotlib.axes.Axes, optional) – Axes to plot on.
save (bool, optional) – Whether to save the figure. Defaults to False.
**kwargs – Additional arguments.
- save_image_dat(filename=None)[source]
Save the intensity map, qxy axis, and qz axis.
- Parameters:
filename (str, optional) – The name of the file to save. If None, it is auto-generated.
- save_image_h5(filename=None)[source]
Save the 2D image data to an HDF5 file in q-coordinates.
This saves the intensity map, qxy axis, and qz axis, along with metadata.
- Parameters:
filename (str, optional) – The name of the file to save. If None, it is auto-generated.