hexrd.instrument.detector module
- class hexrd.instrument.detector.Detector(rows=2048, cols=2048, pixel_size=(0.2, 0.2), tvec=array([0., 0., -1000.]), tilt=array([0., 0., 0.]), name='default', bvec=array([-0., -0., -1.]), xrs_dist=None, evec=array([1., 0., 0.]), saturation_level=None, panel_buffer=None, tth_distortion=None, roi=None, group=None, distortion=None, max_workers=1, detector_filter: Filter | None = None, detector_coating: Coating | None = None, phosphor: Phosphor | None = None)[source]
Bases:
objectBase class for 2D detectors with functions and properties common to planar and cylindrical detectors. This class will be inherited by both those classes.
- abstract angles_to_cart(tth_eta, rmat_s=None, tvec_s=None, rmat_c=None, tvec_c=None, apply_distortion=False)[source]
Transform angular coordinates to cartesian.
Parameters
- tth_etaarray_like
The (n, 2) array of n (tth, eta) coordinates to be transformed.
- rmat_sarray_like, optional
The (3, 3) COB matrix for the sample frame. The default is None.
- tvec_sarray_like, optional
The (3, ) translation vector for the sample frame. The default is None.
- rmat_carray_like, optional
(3, 3) COB matrix for the crystal frame. The default is None.
- tvec_carray_like, optional
The (3, ) translation vector for the crystal frame. The default is None.
- apply_distortionbool, optional
If True, apply distortion to take cartesian coordinates to the “warped” configuration. The default is False.
Returns
- xy_detarray_like
The (n, 2) array on the n input coordinates in the .
- angularPixelSize(xy, rMat_s=None, tVec_s=None, tVec_c=None)[source]
Notes
!!! assumes xy are in raw (distorted) frame, if applicable
- abstract property beam_position
returns the coordinates of the beam in the cartesian detector frame {Xd, Yd, Zd}. NaNs if no intersection.
- property bvec
- calc_compton_physics_package_transmission(energy: floating, rMat_s: array, physics_package: AbstractPhysicsPackage) ndarray[source]
calculate the attenuation of inelastically scattered photons. since these photons lose energy, the attenuation length is angle dependent ergo a separate routine than elastically scattered absorption.
- calc_compton_transmission(seca: ndarray, secb: ndarray, energy: floating, physics_package: AbstractPhysicsPackage, pp_layer: str) ndarray[source]
- calc_compton_transmission_sample(seca: ndarray, energy: floating, physics_package: AbstractPhysicsPackage) ndarray[source]
- calc_compton_transmission_window(secb: ndarray, energy: floating, physics_package: AbstractPhysicsPackage) ndarray[source]
- calc_compton_window_transmission(energy: floating, rMat_s: ndarray, physics_package: AbstractPhysicsPackage) ndarray[source]
calculate the attenuation of inelastically scattered photons just fropm the window. since these photons lose energy, the attenuation length is angle dependent ergo a separate routine than elastically scattered absorption.
- calc_effective_pinhole_area(physics_package: AbstractPhysicsPackage) array[source]
get the effective pinhole area correction @SS 04/01/25 a modification was made based on the CeO2 data recorded on NIF. An extra factor of sec(beta) was included as compared to RSI 91, 043902 (2020).
- calc_physics_package_transmission(energy: floating, rMat_s: array, physics_package: AbstractPhysicsPackage) float64[source]
get the transmission from the physics package need to consider HED and HEDM samples separately
- calc_transmission_generic(secb: array, thickness: floating, absorption_length: floating) array[source]
- calc_transmission_phosphor(secb: array, thickness: floating, readout_length: floating, absorption_length: floating, energy: floating, pre_U0: floating) array[source]
- calc_transmission_sample(seca: array, secb: array, energy: floating, physics_package: AbstractPhysicsPackage) array[source]
- calc_transmission_window(secb: array, energy: floating, physics_package: AbstractPhysicsPackage) array[source]
- cartToPixel(xy_det, pixels=False, apply_distortion=False)[source]
Coverts cartesian coordinates to pixel coordinates
Parameters
- xy_detarray_like
The (n, 2) vstacked array of (x, y) pairs in the reference cartesian frame (possibly subject to distortion).
- pixelsbool, optional
If True, return discrete pixel indices; otherwise fractional pixel coordinates are returned. The default is False.
- apply_distortionbool, optional
If True, apply self.distortion to the input (if applicable). The default is False.
Returns
- ij_detarray_like
The (n, 2) array of vstacked (i, j) coordinates in the pixel reference frame where i is the (slow) row dimension and j is the (fast) column dimension.
- abstract cart_to_angles(xy_data, rmat_s=None, tvec_s=None, tvec_c=None, apply_distortion=False)[source]
Transform cartesian coordinates to angular.
Parameters
- xy_dataTYPE
The (n, 2) array of n (x, y) coordinates to be transformed in either the raw or ideal cartesian plane (see apply_distortion kwarg below).
- rmat_sarray_like, optional
The (3, 3) COB matrix for the sample frame. The default is None.
- tvec_sarray_like, optional
The (3, ) translation vector for the sample frame. The default is None.
- tvec_carray_like, optional
The (3, ) translation vector for the crystal frame. The default is None.
- apply_distortionbool, optional
If True, apply distortion to the inpout cartesian coordinates. The default is False.
Returns
- tth_etaTYPE
DESCRIPTION.
- g_vecTYPE
DESCRIPTION.
- clip_to_panel(xy, buffer_edges=True)[source]
if self.roi is not None, uses it by default
TODO: check if need shape kwarg TODO: optimize ROI search better than list comprehension below TODO: panel_buffer can be a 2-d boolean mask, but needs testing
- property col_dim
- property col_edge_vec
- property col_pixel_vec
- property cols
- compute_compton_scattering_intensity(energy: floating, rMat_s: array, physics_package: AbstractPhysicsPackage, origin: array = array([0., 0., 0.])) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]
compute the theoretical compton scattering signal on the detector. this value is corrected for the transmission of compton scattered photons and normlaized before getting subtracting from the raw intensity
Parameters
- energy: float
energy of incident photon
- rMat_s: np.ndarray
rotation matrix of sample orientation
- physics_package: AbstractPhysicsPackage
physics package information
Returns
- compton_intensity: np.ndarray
transmission corrected compton scattering intensity
- config_dict(chi=0, tvec=array([0., 0., 0.]), beam_energy=65.351, beam_vector=array([-0., -0., -1.]), sat_level=None, panel_buffer=None, style='yaml')[source]
Return a dictionary of detector parameters.
Optional instrument level parameters. This is a convenience function to work with the APIs in several functions in xrdutil.
Parameters
- chifloat, optional
DESCRIPTION. The default is 0.
- tvecarray_like (3,), optional
DESCRIPTION. The default is ct.zeros_3.
- beam_energyfloat, optional
DESCRIPTION. The default is beam_energy_DFLT.
- beam_vectoraray_like (3,), optional
DESCRIPTION. The default is ct.beam_vec.
- sat_levelscalar, optional
DESCRIPTION. The default is None.
- panel_bufferscalar, array_like (2,), optional
DESCRIPTION. The default is None.
Returns
- config_dictdict
DESCRIPTION.
- property corner_ll
- property corner_lr
- property corner_ul
- property corner_ur
- abstract property detector_type
- property distortion
- property evec
- property extra_config_kwargs
- interpolate_bilinear(xy: ndarray, img: ndarray, pad_with_nans: bool = True)[source]
Interpolate an image array at the specified cartesian points.
Parameters
- xyarray_like, (n, 2)
Array of cartesian coordinates in the image plane at which to evaluate intensity.
- imgarray_like
2-dimensional image array. The shape must match (rows, cols).
- pad_with_nansbool, optional
Toggle for assigning NaN to points that fall off the detector. The default is True.
Returns
- int_xyarray_like, (n,)
The array of interpolated intensities at each of the n input coordinates.
Notes
TODO: revisit normalization in here?
- property lmfit_name
- lorentz_factor()[source]
calculate the lorentz factor for every pixel
Parameters
None
Raises
None
Returns
- numpy.ndarray
returns an array the same size as the detector panel with each element containg the lorentz factor of the corresponding pixel
- make_powder_rings(pd, merge_hkls=False, delta_tth=None, delta_eta=10.0, eta_period=None, eta_list=None, rmat_s=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), tvec_s=array([0., 0., 0.]), tvec_c=array([0., 0., 0.]), full_output=False, tth_distortion=None)[source]
Generate points on Debye_Scherrer rings over the detector.
- !!! it is assuming that rmat_s is built from (chi, ome) as it the case
for HEDM!
Parameters
- pdTYPE
DESCRIPTION.
- merge_hklsTYPE, optional
DESCRIPTION. The default is False.
- delta_tthTYPE, optional
DESCRIPTION. The default is None.
- delta_etaTYPE, optional
DESCRIPTION. The default is 10..
- eta_periodTYPE, optional
DESCRIPTION. The default is None.
- eta_listTYPE, optional
DESCRIPTION. The default is None.
- rmat_sTYPE, optional
DESCRIPTION. The default is ct.identity_3x3.
- tvec_sTYPE, optional
DESCRIPTION. The default is ct.zeros_3.
- tvec_cTYPE, optional
DESCRIPTION. The default is ct.zeros_3.
- full_outputTYPE, optional
DESCRIPTION. The default is False.
- tth_distortionspecial class, optional
Special distortion class. The default is None.
Raises
- RuntimeError
DESCRIPTION.
Returns
- TYPE
DESCRIPTION.
- map_to_plane(pts, rmat, tvec)[source]
Map detctor points to specified plane.
Parameters
- ptsTYPE
DESCRIPTION.
- rmatTYPE
DESCRIPTION.
- tvecTYPE
DESCRIPTION.
Returns
- TYPE
DESCRIPTION.
Notes
by convention:
n * (u*pts_l - tvec) = 0
[pts]_l = rmat*[pts]_m + tvec
- property name
- property normal
- property panel_buffer
- pixelToCart(ij_det)[source]
Convert vstacked array or list of [i,j] pixel indices (or UL corner-based points) and convert to (x,y) in the cartesian frame {Xd, Yd, Zd}
- pixel_Q(energy: floating, origin: ndarray = array([0., 0., 0.])) ndarray[source]
get the equivalent momentum transfer for the angles.
Parameters
- energy: float
incident photon energy in keV
- origin: np.ndarray
origin of diffraction volume
Returns
- np.ndarray
pixel wise Q in A^-1
- property pixel_area
- pixel_compton_attenuation_length(energy: floating, density: floating, formula: str, origin: ndarray = array([0., 0., 0.])) ndarray[source]
each pixel intercepts inelastically scattered photons of different energy. the attenuation length and the transmission for these photons are different. this function calculate attenuatin length for each pixel on the detector.
Parameters
- energy: float
incident photon energy in keV
- density: float
density of material in g/cc
- formula: str
formula of the material scattering
- origin: np.ndarray
origin of diffraction volume
Returns
- np.ndarray
pixel wise attentuation length of compton scattered photons
- pixel_compton_energy_loss(energy: floating, origin: ndarray = array([0., 0., 0.])) ndarray[source]
inelastic compton scattering leads to energy loss of the incident photons. compute the final energy of the photons for each pixel.
Parameters
- energy: float
incident photon energy in keV
- origin: np.ndarray
origin of diffraction volume
Returns
- np.ndarray
pixel wise energy of inelastically scatterd photons in keV
- property pixel_coords
- property pixel_size_col
- property pixel_size_row
- property pixel_solid_angles: ndarray
- polarization_factor(f_hor, f_vert, unpolarized=False)[source]
Calculated the polarization factor for every pixel.
Parameters
- f_horfloat
the fraction of horizontal polarization. for XFELs this is close to 1.
- f_vertTYPE
the fraction of vertical polarization, which is ~0 for XFELs.
Raises
- RuntimeError
DESCRIPTION.
Returns
- TYPE
DESCRIPTION.
- property rmat
- property roi
- property row_dim
- property row_edge_vec
- property row_pixel_vec
- property rows
- property saturation_level
- property shape
- simulate_laue_pattern(crystal_data, minEnergy=5.0, maxEnergy=35.0, rmat_s=None, tvec_s=None, grain_params=None, beam_vec=None)[source]
- simulate_rotation_series(plane_data, grain_param_list, eta_ranges=[(-3.141592653589793, 3.141592653589793)], ome_ranges=[(-3.141592653589793, 3.141592653589793)], ome_period=(-3.141592653589793, 3.141592653589793), chi=0.0, tVec_s=array([0., 0., 0.]), wavelength=None, energy_correction=None)[source]
Simulate a monochromatic rotation series for a list of grains.
Parameters
- plane_dataTYPE
DESCRIPTION.
- grain_param_listTYPE
DESCRIPTION.
- eta_rangesTYPE, optional
DESCRIPTION. The default is [(-np.pi, np.pi), ].
- ome_rangesTYPE, optional
DESCRIPTION. The default is [(-np.pi, np.pi), ].
- ome_periodTYPE, optional
DESCRIPTION. The default is (-np.pi, np.pi).
- chiTYPE, optional
DESCRIPTION. The default is 0..
- tVec_sTYPE, optional
DESCRIPTION. The default is ct.zeros_3.
- wavelengthTYPE, optional
DESCRIPTION. The default is None.
Returns
- valid_idsTYPE
DESCRIPTION.
- valid_hklsTYPE
DESCRIPTION.
- valid_angsTYPE
DESCRIPTION.
- valid_xysTYPE
DESCRIPTION.
- ang_pixel_sizeTYPE
DESCRIPTION.
- property tilt
- property tth_distortion
- property tvec
- property xrs_dist