import wx from hexrd.valunits import valWUnit from hexrd.xrd.material import Material from hexrd.wx.guiconfig import WindowParameters as WP from hexrd.wx.guiutil import makeTitleBar from hexrd.wx.selecthkls import selectHKLsDialog as hklsDlg # # Data # from hexrd.xrd.crystallography import dUnit as WAVELENGTH_UNIT from hexrd.xrd.crystallography import processWavelength # AngstromTimesKev = 12.39854 # from APS site (lose digits accuracy this way) AngstromTimesKev = processWavelength(1.0) # widChoices = ['two theta', 'strain'] widStrain = 1; widTwoTheta = 0 # # Tooltip # dfltToolTip = r"""Press this button to make the current value (wavelength/strain/2-theta) the default value for new materials. Applies only for the session. """ # # ---------------------------------------------------CLASS: ringPanel # class ringPanel(wx.Panel): """ringPanel """
from hexrd.xrd.experiment import FitModes from hexrd.xrd.crystallography import dUnit as WAVELENGTH_UNIT from hexrd.xrd.crystallography import processWavelength # # wx Modules # from hexrd.wx.guiconfig import WindowParameters as WP from hexrd.wx.guiutil import ResetChoice, AddSpacer, EmptyWindow, makeTitleBar from hexrd.wx.floatcontrol import FloatControl, EVT_FLOAT_CTRL from hexrd.wx.logwindows import logWindow from hexrd.wx.ringsubpanel import ringPanel from hexrd.wx.selecthkls import selectHKLsDialog as hklsDlg #TBR # AngstromTimesKev = 12.39854 # from APS site (lose digits accuracy this way) AngstromTimesKev = processWavelength(1.0) # # ---------------------------------------------------CLASS: plotPanel # class detectorPanel(wx.Panel): """plotPanel """ def __init__(self, parent, id, **kwargs): """Constructor for plotPanel.""" # wx.Panel.__init__(self, parent, id, **kwargs) self.SetBackgroundColour(WP.BG_COLOR_PANEL) # # Data # # *** NONE YET *** #
""" import wx from hexrd.valunits import valWUnit from hexrd.xrd.material import Material from hexrd.wx.guiconfig import WindowParameters as WP from hexrd.wx.guiutil import makeTitleBar from hexrd.wx.selecthkls import selectHKLsDialog as hklsDlg # # Data # from hexrd.xrd.crystallography import dUnit as WAVELENGTH_UNIT from hexrd.xrd.crystallography import processWavelength # AngstromTimesKev = processWavelength(1.0) # 12.39854 (lose digits accuracy this way) # widChoices = ['two theta', 'strain'] widStrain = 1; widTwoTheta = 0 # # Tooltip # dfltToolTip = r"""Press this button to make the current value (wavelength/strain/2-theta) the default value for new materials. Applies only for the session. """ # # ---------------------------------------------------CLASS: ringPanel # class ringPanel(wx.Panel): """ringPanel """
def simulateLauePattern(self, planeData, minEnergy=5, maxEnergy=25, rMat_s=np.eye(3), rMat=None, vInv=None, doGnomonic=False): multipleEnergyRanges = False if hasattr(maxEnergy, '__len__'): assert len(maxEnergy) == len(minEnergy), 'energy cutoff ranges must have the same length' multipleEnergyRanges = True; lmin = []; lmax = [] for i in range(len(maxEnergy)): lmin.append(processWavelength(maxEnergy[i])) lmax.append(processWavelength(minEnergy[i])) else: lmin = processWavelength(maxEnergy) lmax = processWavelength(minEnergy) gvec_c = planeData.getPlaneNormals() hkls = planeData.getSymHKLs() dsp = planeData.getPlaneSpacings() if rMat is None: rMat = [np.eye(3),] if vInv is None: vInv = [vInv_ref,] # rMult = planeData.getMultiplicity() # nHKLs_tot = rMult.sum() # rMask = np.ones(nHKLs_tot, dtype=bool) retval = [] for iG in range(len(rMat)): tmp = {'detXY':[], 'gnoXY':[], 'angles':[], 'dspacing':[], 'hkl':[], 'energy':[]} for iHKL in range(planeData.nHKLs): # stretch them: V^(-1) * R * Gc gvec_s_str = mutil.unitVector( np.dot( vInv[iG], np.dot( rMat[iG], gvec_c[iHKL] ) ) ) gvec_c_str = np.dot(rMat[iG].T, gvec_s_str) gvec_l_str = np.dot(rMat_s, gvec_s_str) # # dpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s) # gpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s, doGnomonic=True) dpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s) gpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s, doGnomonic=True) canIntersect = -np.isnan(dpts[0, :]) npts_in = sum(canIntersect) if np.any(canIntersect): dpts = dpts[:, canIntersect].reshape(3, npts_in) dhkl = hkls[iHKL][:, canIntersect].reshape(3, npts_in) gvl_hat = gvec_l_str[:, canIntersect].reshape(3, npts_in) gvl_xy = gvec_l_str[:2, canIntersect].reshape(2, npts_in) # dot with the beam dotWbeam = np.dot(Z_ref.T, gvl_hat).flatten() # angles theta = piby2 - rot.arccosSafe( dotWbeam ) wlen = 2*dsp[iHKL]*np.sin(theta) eta = np.arccos(gvl_xy[0, :]) # find on spatial extent of detector # for corner # xTest = np.logical_and(dpts[0, :] > 0, dpts[0, :] < self.cdim) # for corner # yTest = np.logical_and(dpts[1, :] > 0, dpts[1, :] < self.rdim) xTest = np.logical_and(dpts[0, :] > -0.5 * self.cdim, dpts[0, :] < 0.5 * self.cdim) yTest = np.logical_and(dpts[1, :] > -0.5 * self.rdim, dpts[1, :] < 0.5 * self.rdim) onDetector = np.logical_and(xTest, yTest) if multipleEnergyRanges: validEnergy = np.zeros(len(wlen), dtype=bool) for i in range(len(lmin)): validEnergy = validEnergy | np.logical_and(wlen >= lmin[i], wlen <= lmax[i]) pass else: validEnergy = np.logical_and(wlen >= lmin, wlen <= lmax) pass keepers = np.logical_and(onDetector, validEnergy) dsp_this = 1. / mutil.columnNorm(np.dot(planeData.latVecOps['B'], dhkl[:, keepers])) tmp['detXY'].append(dpts[:2, keepers]) tmp['gnoXY'].append(gpts[:2, keepers]) tmp['angles'].append(np.vstack([2*theta[keepers]*r2d, eta[keepers]*r2d])) tmp['hkl'].append(dhkl[:, keepers]) tmp['dspacing'].append(dsp_this) tmp['energy'].append(processWavelength(wlen[keepers])) else: tmp['detXY'].append(np.empty((2, 0))) tmp['gnoXY'].append(np.empty((2, 0))) tmp['angles'].append(np.empty((2, 0))) tmp['hkl'].append(np.empty((3, 0))) tmp['dspacing'].append(np.empty(0)) tmp['energy'].append(np.empty(0)) pass pass retval.append(tmp) return retval
def simulateLauePattern(self, planeData, minEnergy=5, maxEnergy=25, rMat_s=np.eye(3), rMat=None, vInv=None, doGnomonic=False): multipleEnergyRanges = False if hasattr(maxEnergy, '__len__'): assert len(maxEnergy) == len( minEnergy), 'energy cutoff ranges must have the same length' multipleEnergyRanges = True lmin = [] lmax = [] for i in range(len(maxEnergy)): lmin.append(processWavelength(maxEnergy[i])) lmax.append(processWavelength(minEnergy[i])) else: lmin = processWavelength(maxEnergy) lmax = processWavelength(minEnergy) gvec_c = planeData.getPlaneNormals() hkls = planeData.getSymHKLs() dsp = planeData.getPlaneSpacings() if rMat is None: rMat = [ np.eye(3), ] if vInv is None: vInv = [ vInv_ref, ] # rMult = planeData.getMultiplicity() # nHKLs_tot = rMult.sum() # rMask = np.ones(nHKLs_tot, dtype=bool) retval = [] for iG in range(len(rMat)): tmp = { 'detXY': [], 'gnoXY': [], 'angles': [], 'dspacing': [], 'hkl': [], 'energy': [] } for iHKL in range(planeData.nHKLs): # stretch them: V^(-1) * R * Gc gvec_s_str = mutil.unitVector( np.dot(vInv[iG], np.dot(rMat[iG], gvec_c[iHKL]))) gvec_c_str = np.dot(rMat[iG].T, gvec_s_str) gvec_l_str = np.dot(rMat_s, gvec_s_str) # # dpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s) # gpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s, doGnomonic=True) dpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s) gpts = self.gVecToDet(gvec_c_str, rMat=rMat[iG], rMat_s=rMat_s, doGnomonic=True) canIntersect = -np.isnan(dpts[0, :]) npts_in = sum(canIntersect) if np.any(canIntersect): dpts = dpts[:, canIntersect].reshape(3, npts_in) dhkl = hkls[iHKL][:, canIntersect].reshape(3, npts_in) gvl_hat = gvec_l_str[:, canIntersect].reshape(3, npts_in) gvl_xy = gvec_l_str[:2, canIntersect].reshape(2, npts_in) # dot with the beam dotWbeam = np.dot(Z_ref.T, gvl_hat).flatten() # angles theta = piby2 - rot.arccosSafe(dotWbeam) wlen = 2 * dsp[iHKL] * np.sin(theta) eta = np.arccos(gvl_xy[0, :]) # find on spatial extent of detector # for corner # xTest = np.logical_and(dpts[0, :] > 0, dpts[0, :] < self.cdim) # for corner # yTest = np.logical_and(dpts[1, :] > 0, dpts[1, :] < self.rdim) xTest = np.logical_and(dpts[0, :] > -0.5 * self.cdim, dpts[0, :] < 0.5 * self.cdim) yTest = np.logical_and(dpts[1, :] > -0.5 * self.rdim, dpts[1, :] < 0.5 * self.rdim) onDetector = np.logical_and(xTest, yTest) if multipleEnergyRanges: validEnergy = np.zeros(len(wlen), dtype=bool) for i in range(len(lmin)): validEnergy = validEnergy | np.logical_and( wlen >= lmin[i], wlen <= lmax[i]) pass else: validEnergy = np.logical_and(wlen >= lmin, wlen <= lmax) pass keepers = np.logical_and(onDetector, validEnergy) dsp_this = 1. / mutil.columnNorm( np.dot(planeData.latVecOps['B'], dhkl[:, keepers])) tmp['detXY'].append(dpts[:2, keepers]) tmp['gnoXY'].append(gpts[:2, keepers]) tmp['angles'].append( np.vstack( [2 * theta[keepers] * r2d, eta[keepers] * r2d])) tmp['hkl'].append(dhkl[:, keepers]) tmp['dspacing'].append(dsp_this) tmp['energy'].append(processWavelength(wlen[keepers])) else: tmp['detXY'].append(np.empty((2, 0))) tmp['gnoXY'].append(np.empty((2, 0))) tmp['angles'].append(np.empty((2, 0))) tmp['hkl'].append(np.empty((3, 0))) tmp['dspacing'].append(np.empty(0)) tmp['energy'].append(np.empty(0)) pass pass retval.append(tmp) return retval