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)[source]

Bases: object

Base 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
property calibration_flags
property calibration_flags_to_lmfit_names
property calibration_parameters
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.

abstract cart_to_dvecs(xy_data)[source]

Convert cartesian coordinates to dvectors

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
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
static increase_memoization_sizes(funcs, min_size)[source]
interpolate_bilinear(xy, img, pad_with_nans=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.

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?

interpolate_nearest(xy, img, pad_with_nans=True)[source]

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}

abstract pixel_angles(origin=array([0., 0., 0.]))[source]
property pixel_area
property pixel_coords
abstract pixel_eta_gradient(origin=array([0., 0., 0.]))[source]
property pixel_size_col
property pixel_size_row
abstract pixel_tth_gradient(origin=array([0., 0., 0.]))[source]
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)[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
static update_memoization_sizes(all_panels)[source]
property xrs_dist