hexrd.instrument.hedm_instrument module

Created on Fri Dec 9 13:05:27 2016

@author: bernier2

exception hexrd.instrument.hedm_instrument.BufferShapeMismatchError[source]

Bases: RuntimeError

class hexrd.instrument.hedm_instrument.GenerateEtaOmeMaps(image_series_dict, instrument, plane_data, active_hkls=None, eta_step=0.25, threshold=None, ome_period=(0, 360))[source]

Bases: object

eta-ome map class derived from new image_series and YAML config

…for now…

must provide:

self.dataStore self.planeData self.iHKLList self.etaEdges # IN RADIANS self.omeEdges # IN RADIANS self.etas # IN RADIANS self.omegas # IN RADIANS

property dataStore
property etaEdges
property etas
property iHKLList
property omeEdges
property omegas
property planeData
save(filename)[source]
class hexrd.instrument.hedm_instrument.GrainDataWriter(filename=None, array=None)[source]

Bases: object

Class for dumping grain data.

close()[source]
dump_grain(grain_id, completeness, chisq, grain_params)[source]
class hexrd.instrument.hedm_instrument.GrainDataWriter_h5(filename, instr_cfg, grain_params, use_attr=False)[source]

Bases: object

Class for dumping grain results to an HDF5 archive.

TODO: add material spec

close()[source]
dump_patch(panel_id, i_refl, peak_id, hkl_id, hkl, tth_edges, eta_edges, ome_centers, xy_centers, ijs, frame_indices, spot_data, pangs, pxy, mangs, mxy, gzip=1)[source]

to be called inside loop over patches

default GZIP level for data arrays is 1

class hexrd.instrument.hedm_instrument.HEDMInstrument(instrument_config=None, image_series=None, eta_vector=None, instrument_name=None, tilt_calibration_mapping=None, max_workers=1)[source]

Bases: object

Abstraction of XRD instrument.

  • Distortion needs to be moved to a class with registry; tuple unworkable

  • where should reference eta be defined? currently set to default config

property beam_energy
property beam_vector
property beam_wavelength
property calibration_flags
property calibration_flags_to_lmfit_names
property calibration_parameters

Yields concatenated list of instrument parameters.

Returns

array_like

concatenated list of instrument parameters.

property chi
property detector_parameters
property detectors
property eta_vector
extract_line_positions(plane_data, imgser_dict, tth_tol=None, eta_tol=1.0, npdiv=2, eta_centers=None, collapse_eta=True, collapse_tth=False, do_interpolation=True, do_fitting=False, tth_distortion=None, fitting_kwargs=None)[source]

Perform annular interpolation on diffraction images.

Provides data for extracting the line positions from powder diffraction images, pole figure patches from imageseries, or Bragg peaks from Laue diffraction images.

Parameters

plane_datahexrd.crystallography.PlaneData object or array_like

Object determining the 2theta positions for the integration sectors. If PlaneData, this will be all non-excluded reflections, subject to merging within PlaneData.tThWidth. If array_like, interpreted as a list of 2theta angles IN DEGREES.

imgser_dictdict

Dictionary of powder diffraction images, one for each detector.

tth_tolscalar, optional

The radial (i.e. 2theta) width of the integration sectors IN DEGREES. This arg is required if plane_data is array_like. The default is None.

eta_tolscalar, optional

The azimuthal (i.e. eta) width of the integration sectors IN DEGREES. The default is 1.

npdivint, optional

The number of oversampling pixel subdivision (see notes). The default is 2.

eta_centersarray_like, optional

The desired azimuthal sector centers. The default is None. If None, then bins are distrubted sequentially from (-180, 180).

collapse_etabool, optional

Flag for summing sectors in eta. The default is True.

collapse_tthbool, optional

Flag for summing sectors in 2theta. The default is False.

do_interpolationbool, optional

If True, perform bilinear interpolation. The default is True.

do_fittingbool, optional

If True, then perform spectrum fitting, and append the results to the returned data. collapse_eta must also be True for this to have any effect. The default is False.

tth_distortionspecial class, optional

for special case of pinhole camera distortions. See hexrd.xrdutil.phutil.SampleLayerDistortion (only type supported)

fitting_kwargsdict, optional

kwargs passed to hexrd.fitting.utils.fit_ring if do_fitting is True

Raises

RuntimeError

DESCRIPTION.

Returns

panel_datadict
Dictionary over the detctors with the following structure:
[list over (merged) 2theta ranges]
[list over valid eta sectors]
[angle data <input dependent>,

bin intensities <input dependent>, fitting results <input dependent>]

Notes

TODO: May change the array_like input units to degrees. TODO: rename function.

extract_polar_maps(plane_data, imgser_dict, active_hkls=None, threshold=None, tth_tol=None, eta_tol=0.25)[source]

Extract eta-omega maps from an imageseries.

Quick and dirty way to histogram angular patch data for make pole figures suitable for fiber generation

TODO: streamline projection code TODO: normalization !!!: images must be non-negative! !!!: plane_data is NOT a copy!

property has_multi_beam
property id
property multi_beam_dict
property num_panels
pull_spots(plane_data, grain_params, imgser_dict, tth_tol=0.25, eta_tol=1.0, ome_tol=1.0, npdiv=2, threshold=10, eta_ranges=[(-3.141592653589793, 3.141592653589793)], ome_period=None, dirname='results', filename=None, output_format='text', return_spot_list=False, quiet=True, check_only=False, interp='nearest')[source]

Exctract reflection info from a rotation series.

Input must be encoded as an OmegaImageseries object.

Parameters

plane_dataTYPE

DESCRIPTION.

grain_paramsTYPE

DESCRIPTION.

imgser_dictTYPE

DESCRIPTION.

tth_tolTYPE, optional

DESCRIPTION. The default is 0.25.

eta_tolTYPE, optional

DESCRIPTION. The default is 1..

ome_tolTYPE, optional

DESCRIPTION. The default is 1..

npdivTYPE, optional

DESCRIPTION. The default is 2.

thresholdTYPE, optional

DESCRIPTION. The default is 10.

eta_rangesTYPE, optional

DESCRIPTION. The default is [(-np.pi, np.pi), ].

ome_periodTYPE, optional

DESCRIPTION. The default is (-np.pi, np.pi).

dirnameTYPE, optional

DESCRIPTION. The default is ‘results’.

filenameTYPE, optional

DESCRIPTION. The default is None.

output_formatTYPE, optional

DESCRIPTION. The default is ‘text’.

return_spot_listTYPE, optional

DESCRIPTION. The default is False.

quietTYPE, optional

DESCRIPTION. The default is True.

check_onlyTYPE, optional

DESCRIPTION. The default is False.

interpTYPE, optional

DESCRIPTION. The default is ‘nearest’.

Returns

complTYPE

DESCRIPTION.

outputTYPE

DESCRIPTION.

set_calibration_flags_to_lmfit_params(params_dict)[source]
simulate_laue_pattern(crystal_data, minEnergy=5.0, maxEnergy=35.0, rmat_s=None, grain_params=None)[source]

Simulate Laue diffraction over the instrument.

Parameters

crystal_dataTYPE

DESCRIPTION.

minEnergyTYPE, optional

DESCRIPTION. The default is 5..

maxEnergyTYPE, optional

DESCRIPTION. The default is 35..

rmat_sTYPE, optional

DESCRIPTION. The default is None.

grain_paramsTYPE, optional

DESCRIPTION. The default is None.

Returns

resultsTYPE

DESCRIPTION.

xy_det, hkls_in, angles, dspacing, energy

TODO: revisit output; dict, or concatenated list?

simulate_powder_pattern(mat_list, params=None, bkgmethod=None, origin=None, noise=None)[source]

Generate powder diffraction iamges from specified materials.

Parameters

mat_listarray_like (n, )

List of Material classes.

paramsdict, optional

Dictionary of LeBail parameters (see Notes). The default is None.

bkgmethoddict, optional

Background function specification. The default is None.

originarray_like (3,), optional

Vector describing the origin of the diffrction volume. The default is None, wiich is equivalent to [0, 0, 0].

noisestr, optional

Flag describing type of noise to be applied. The default is None.

Returns

img_dictdict

Dictionary of diffraciton images over the detectors.

Notes

TODO: add more controls for noise function. TODO: modify hooks to LeBail parameters. TODO: add optional volume fraction weights for phases in mat_list

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), wavelength=None)[source]

Simulate a monochromatic rotation series over the instrument.

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).

wavelengthTYPE, optional

DESCRIPTION. The default is None.

Returns

resultsTYPE

DESCRIPTION.

TODO: revisit output; dict, or concatenated list?

property source_distance
property tilt_calibration_mapping
property tvec
update_from_parameter_list(p)[source]

Update the instrument class from a parameter list.

Utility function to update instrument parameters from a 1-d master parameter list (e.g. as used in calibration)

!!! Note that angles are reported in DEGREES!

update_memoization_sizes()[source]
write_config(file=None, style='yaml', calibration_dict={})[source]

WRITE OUT YAML FILE

class hexrd.instrument.hedm_instrument.PatchDataWriter(filename)[source]

Bases: object

Class for dumping Bragg reflection data.

close()[source]
dump_patch(peak_id, hkl_id, hkl, spot_int, max_int, pangs, mangs, pxy, mxy)[source]

!!! maybe need to check that last four inputs are arrays

hexrd.instrument.hedm_instrument.angle_in_range(angle, ranges, ccw=True, units='degrees')[source]

Return the index of the first wedge the angle is found in

WARNING: always clockwise; assumes wedges are not overlapping

hexrd.instrument.hedm_instrument.calc_angles_from_beam_vec(bvec)[source]

Return the azimuth and polar angle from a beam vector

hexrd.instrument.hedm_instrument.calc_beam_vec(azim, pola)[source]

Calculate unit beam propagation vector from spherical coordinate spec in DEGREES.

…MAY CHANGE; THIS IS ALSO LOCATED IN XRDUTIL!

hexrd.instrument.hedm_instrument.centers_of_edge_vec(edges)[source]
hexrd.instrument.hedm_instrument.chunk_instrument(instr, rects, labels, use_roi=False)[source]

Generate chunked config fro regularly tiled composite detectors.

Parameters

instrTYPE

DESCRIPTION.

rectsTYPE

DESCRIPTION.

labelsTYPE

DESCRIPTION.

Returns

new_icfg_dictTYPE

DESCRIPTION.

hexrd.instrument.hedm_instrument.generate_chunks(nrows, ncols, base_nrows, base_ncols, row_gap=0, col_gap=0)[source]

Generate chunking data for regularly tiled composite detectors.

Parameters

nrowsint

DESCRIPTION.

ncolsint

DESCRIPTION.

base_nrowsint

DESCRIPTION.

base_ncolsint

DESCRIPTION.

row_gapint, optional

DESCRIPTION. The default is 0.

col_gapint, optional

DESCRIPTION. The default is 0.

Returns

rectsarray_like

The (nrows*ncols, ) list of ROI specs (see Notes).

labelsarray_like

The (nrows*ncols, ) list of ROI (i, j) matrix indexing labels ‘i_j’.

Notes

ProcessedImageSeries needs a (2, 2) array for the ‘rect’ kwarg:
[[row_start, row_stop],

[col_start, col_stop]]

hexrd.instrument.hedm_instrument.histogram(x, bins, weights=None)
hexrd.instrument.hedm_instrument.ims_classes = (<class 'hexrd.imageseries.baseclass.ImageSeries'>, <class 'hexrd.imageseries.process.ProcessedImageSeries'>, <class 'hexrd.imageseries.omega.OmegaImageSeries'>)

Calibration parameter flags

for instrument level, len is 7

[beam energy,

beam azimuth, beam elevation, chi, tvec[0], tvec[1], tvec[2], ]

hexrd.instrument.hedm_instrument.instr_calibration_flags_DFLT = array([False, False, False, False, False, False, False])

for each panel, order is:

[tilt[0],

tilt[1], tilt[2], tvec[0], tvec[1], tvec[2], <dparams>, ]

len is 6 + len(dparams) for each panel by default, dparams are not set for refinement

hexrd.instrument.hedm_instrument.max_resolution(instr)[source]

Return the maximum angular resolution of the instrument.

Parameters

instrHEDMInstrument instance

An instrument.

Returns

max_tthfloat

Maximum tth resolution in radians.

max_etaTYPE

maximum eta resolution in radians.

hexrd.instrument.hedm_instrument.max_tth(instr)[source]

Return the maximum Bragg angle (in radians) subtended by the instrument.

Parameters

instrhexrd.instrument.HEDMInstrument instance

the instrument class to evalutate.

Returns

tth_maxfloat

The maximum observable Bragg angle by the instrument in radians.

hexrd.instrument.hedm_instrument.migrate_instrument_config(instrument_config)[source]

utility function to generate old instrument config dictionary

hexrd.instrument.hedm_instrument.pixel_resolution(instr)[source]

Return the minimum, median, and maximum angular resolution of the instrument.

Parameters

instrHEDMInstrument instance

An instrument.

Returns

tth_statsfloat

min/median/max tth resolution in radians.

eta_statsTYPE

min/median/max eta resolution in radians.

hexrd.instrument.hedm_instrument.run_fast_histogram(x, bins, weights=None)[source]
hexrd.instrument.hedm_instrument.run_numpy_histogram(x, bins, weights=None)[source]