ImageD11.forward_model.forward_model module#

ImageD11.forward_model.forward_model.beam_attenuation(pos_lab, Lsam2det, dety_mm, detz_mm, Rsample=0.3, Lsam2sou=97000.0, beam_name='pencil_beam', rou=2.7, mass_abs=0.5685)#

calculate the beam path length along the sample incoming beam length + outcoming diffracting beam length diffraction occurring at (x,y,z) I/I0 = exp(-mass_abs * rou * beam_length) mass_abs: mass-energy absorption coefficient, obtained from e.g. NIST table [cm^2/g] rou: density of the sample [g/cm^3] beam_length: total length of the X-ray beam path in the sample by default, values of mass_abs and rou is for Aluminium at 40 keV

Parameters:
  • pos_lab (float) – positions in lab coordinate system [mm]

  • Lsam2det (float) – sample-to-detector distance [mm]

  • dety_mm (float) – peak position Y [mm]

  • detz_mm (float) – peak position Z [mm]

  • Rsample (float) – sample radius [mm]

  • Lsam2sou (float) – sample-to-source distance [mm]

  • beam_name (string) – name of the beam shape, ‘pencil_beam’, ‘cone_beam’, ‘parallel_beam’

  • rou (float) – sample density [g/cm^3]

  • mass_abs (float) – mass-energy absorption coefficient [cm^2/g]

Returns:

transmission factor to quantify I/I0 L_total (float): total length of the X-ray beam path in the sample [mm]

Return type:

trans_factor (float)

ImageD11.forward_model.forward_model.cf_filter_for_grain(cf, grain_id=0)#
ImageD11.forward_model.forward_model.cf_plot_sino(cfs, skip=1, hist2d_plot=False, bins=(3620, 400))#

plot sinogram for each cf wrapped in a list :param cfs: list of ImageD11 column files :type cfs: list :param skip: every point to skip for speeding up plotting :type skip: int :param hist2d_plot: False for scatter plot, True for hist2d :type hist2d_plot: bool :param bins: N_omega * N_dty, used when hist2d_plot is True :type bins: tuple

ImageD11.forward_model.forward_model.cf_remove_unmatched_peaks(cf_strong, cf_matched_all)#

Remove unmatched peaks from the cf_strong so that grain sinograms are expected to be cleaner after re-assigning the cleaned cf_strong

Arguments: cf_strong – ImageD11 colume file, e.g. cf_4d = ds.get_cf_4d_from_disk() and then filter cf_matched_all – list of matched peaks for each of the grain, list of ImageD11.columnfile

Returns: cf_clean – cleaned cf_strong

ImageD11.forward_model.forward_model.cf_remove_weak_peaks(cf, percent_int=20, thres_int=None)#

remove weak peaks either by specifying the minimum peak intensity or by removing the lowest percent_int percent of the all peaks Matching the peaks from cf to the forward calculated peaks by checking differences in omega, tth, fc(dety), sc(detz)

Arguments: cf – ImageD11 column file [object] percent_int – percentage of the weak intensities thres_int – threshold intenisty

Returns: filterd peaks as cf object

ImageD11.forward_model.forward_model.cf_set_difference(cf1, cf2, tol=0.001, chunk_size=100)#

Matching the peaks from cf to the forward calculated peaks by checking differences in omega, tth, fc(dety), sc(detz)

Arguments: cf1 – ImageD11 column file [object] cf2 – ImageD11 column file [object] tol – tolerance for matching the peaks, dty, omega, sc and fc chunk_size – number of cf1 rows to process at a time (tune for memory/speed)

Returns: cf1_diff – rest of the peaks from cf1 which is not contained in cf2 cf2_diff – rest of the peaks from cf2 which is not contained in cf1

ImageD11.forward_model.forward_model.find_matches_chunk(cf1_dty_chunk, cf1_omega_chunk, cf1_fc_chunk, cf1_sc_chunk, cf2_dty, cf2_omega, cf2_fc, cf2_sc, tol, start_idx, matched_cf1, matched_cf2)#
ImageD11.forward_model.forward_model.find_matching_peaks(cf, fwd, dsmax=1.5, tol_angle=0.1, tol_pixel=0.55, vectorized_comp=True)#

Matching the peaks from cf to the forward calculated peaks by checking differences in omega, tth, fc(dety), sc(detz)

Arguments: cf – ImageD11 column file [object] fwd – forward calculated peaks info obtained from forward_comp [list] dsmax – maximum ds [Angstrom^-1] tol_angle – tolerance for matching angles, omega and two-theta [deg] tol_pixel – tolerance for matching pixel coordinate, dety (fc) and detz (sc), [pixel] vectorized_comp – flag for vectorized comparison [bool]

Returns: cf_matched – colume file that only matches with forward calculated peaks fwd_matched – matched peaks among all the forward calculated peaks ij – indices corresponding to cf_matched and fwd_matched, respectively Completeness – the fraction of matched forward peaks

ImageD11.forward_model.forward_model.find_omega(a, b, c, d, sqD)#

Finds the omega (rotation angle) that generates the diffraction.

Arguments: a, b, c, d, sqD – parameters as per the problem’s equation

Returns: Omega – list containing the solutions for omega (in the range [0, 2*pi])

ImageD11.forward_model.forward_model.forward_comp(pos, U, B, ucell, pars, ds_max=1.2, rot_start=-91, rot_end=91, rot_step=0.05, verbose=1)#

Given pos, U, B, ucell, pars, forward calculate the expected intersection position on the detector.

Arguments: pos – position vector U – rotation matrix B – B matrix represented by lattice parameters ucell – ImageD11.unitcell object pars – ImageD1.parameters object, e.g. ImageD11.parameters.read_par_file(‘pars.json’) ds_max – maximum ds rot_start – starting omega angle [deg] rot_step – step size of the omega rotation [deg] rot_end – end omega angle [deg] verbose – verbose level for displaying print out

Returns: fwd – list of expected peak positions: [rot in degrees, hkl, 2-theta in degrees, Gt, dety, detz, dety_mm, detz_mm, HitDetFlag] Nr_simu – number of theoretical spots expected on the detector

ImageD11.forward_model.forward_model.forward_det_pos(pos, omega, Gw, theta, p)#

Given omega, Gw, pos, U, and other parameters, outputs the expected intersection position on the detector.

Arguments: pos – position vector S – rotation matrix or similar omega – rotation angle in radians Gw – G vector p – parameter containing the following: Lsam2det – distance from the sample to the detector theta – diffraction angle RotDet – rotation matrix for the detector dety0, detz0 – detector center positions in pixels dety00, detz00 – detector offset position pixelysize, pixelzsize – pixel sizes in mm detysize, detzsize – detector sizes in pixels BeamStopY, BeamStopZ – beamstop positions flip_lr_flag, flip_ud_flag – flags for flipping left-right or up-down

Returns: dety, detz – detector positions in pixels dety_mm, detz_mm – detector positions in mm Gt.T – diffraction vector in lab frame, 1*3 numpy array HitDetFlag – flag if the position hits the effective area of the detector

ImageD11.forward_model.forward_model.forward_match_peaks(cf_strong, grains, ds, ucell, pars, ds_max=1.6, tol_angle=1, tol_pixel=5, thres_int=None, vectorized_comp=True, verbose=1)#

Perform forward calculation to find the matched fwd peaks and exp peaks

Arguments: cf_strong – ImageD11 colume file, e.g. cf_4d = ds.get_cf_4d_from_disk() and then filter grains – list of grain object, e.g. grains = ds.get_grains_from_disk(phase_str) ds – dataset object, e.g. ds = ImageD11.sinograms.dataset.load(dset_file) ucell – ImageD11.unitcell object, e.g. ucell = ds.phases.unitcells[phase_str] pars – ImageD1.parameters object, e.g. pars = ImageD11.parameters.read_par_file(ds.parfile) Optional arguments: ds_max – maximum 1/d tol_angle – tolerance of angles for matching peaks tol_piexl – tolerance of pixels for matching peaks thres_int – intensity threshold, None as default to not remove peaks vectorized_comp – flag for vectorized comparison [bool] verbose – verbose level for displaying print out

Returns: cf_matched_all – list of matched peaks for each of the grain, list of ImageD11.columnfile Comp_all – Completeness values [N*2] list, original completeness and updated completeness after removing the low-intensity matched peaks

ImageD11.forward_model.forward_model.get_ds_max(pars)#

Calculate two-theta angle from ds and wavelength according to Bragg’s law

Arguments: pars – ImageD11 pars object

Returns: ds_max – maximum ds spacing detectable on the detector [Anstrom^-1]

ImageD11.forward_model.forward_model.get_hkls(ucell, dsmax=1.2, verbose=1)#

get hkl list from the ucell provided by ImageD11

Arguments: ucell, dsmax

Returns: ds_all – 1/d of all the unique hkl families within dsmax hkls – list of hkl indices for the lattice planes

ImageD11.forward_model.forward_model.get_omega_matrix(omega)#

Calculate the rotation matrix (Omega) for a rotation angle around Z vertical axis in right-hand coordinate system Returns: Omega matrix 3*3 array

ImageD11.forward_model.forward_model.get_tth_from_ds(ds, wavelength)#

Calculate two-theta angle from ds and wavelength according to Bragg’s law

Arguments: ds – inverse of d-spacing for a given hkl family wavelength – [Angstrom]

Returns: two-theta in degrees