Skip to content

Commit f06c665

Browse files
Add Transforms Testcases and fix some stuff (#696)
* Add transforms testcases * Transforms updates and testcases * Replace all old usages of xfcapi to the new versions
1 parent 7071869 commit f06c665

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1542
-561
lines changed

hexrd/cli/find_orientations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def write_results(results, cfg):
8585
)
8686
for gid, q in enumerate(results['qbar'].T):
8787
phi = 2*np.arccos(q[0])
88-
n = xfcapi.unitRowVector(q[1:])
88+
n = xfcapi.unit_vector(q[1:])
8989
grain_params = np.hstack([phi*n, const.zeros_3, const.identity_6x1])
9090
gw.dump_grain(gid, 1., 0., grain_params)
9191
gw.close()

hexrd/cli/fit_grains.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def rotation_matrices(self):
7777
n = len(self.expmap)
7878
rmats = np.zeros((n, 3, 3))
7979
for i in range(n):
80-
rmats[i] = xfcapi.makeRotMatOfExpMap(self.expmap[i])
80+
rmats[i] = xfcapi.make_rmat_of_expmap(self.expmap[i])
8181
self._rotation_matrices = rmats
8282
return self._rotation_matrices
8383

@@ -307,7 +307,7 @@ def execute(args, parser):
307307
gw = instrument.GrainDataWriter(grains_filename)
308308
for i_g, q in enumerate(qbar.T):
309309
phi = 2*np.arccos(q[0])
310-
n = xfcapi.unitRowVector(q[1:])
310+
n = xfcapi.unit_vector(q[1:])
311311
grain_params = np.hstack(
312312
[phi*n, cnst.zeros_3, cnst.identity_6x1]
313313
)

hexrd/fitgrains.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from hexrd import instrument
1616
from hexrd.transforms import xfcapi
17+
from hexrd import rotations
1718
from hexrd.fitting import fitGrain, objFuncFitGrain, gFlag_ref
1819

1920
logger = logging.getLogger(__name__)
@@ -258,7 +259,7 @@ def fit_grain_FF_reduced(grain_id):
258259
x_diff = abs(xyo_det[:, 0] - xyo_det_fit['calc_xy'][:, 0])
259260
y_diff = abs(xyo_det[:, 1] - xyo_det_fit['calc_xy'][:, 1])
260261
ome_diff = np.degrees(
261-
xfcapi.angularDifference(xyo_det[:, 2],
262+
rotations.angularDifference(xyo_det[:, 2],
262263
xyo_det_fit['calc_omes'])
263264
)
264265

hexrd/fitting/calibration/laue.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def grain_params_euler(self):
6969

7070
grain_params = self.grain_params.copy()
7171
rme = RotMatEuler(np.zeros(3), **self.euler_convention)
72-
rme.rmat = xfcapi.makeRotMatOfExpMap(grain_params[:3])
72+
rme.rmat = xfcapi.make_rmat_of_expmap(grain_params[:3])
7373
grain_params[:3] = np.degrees(rme.angles)
7474
return grain_params
7575

@@ -171,7 +171,7 @@ def autopick_points(self, raw_img_dict, tth_tol=5., eta_tol=5.,
171171
rmat_s = np.eye(3) # !!! forcing to identity
172172
omega = 0. # !!! same ^^^
173173

174-
rmat_c = xfcapi.makeRotMatOfExpMap(self.grain_params[:3])
174+
rmat_c = xfcapi.make_rmat_of_expmap(self.grain_params[:3])
175175
tvec_c = self.grain_params[3:6]
176176
# vinv_s = self.grain_params[6:12] # !!!: patches don't take this yet
177177

@@ -358,16 +358,16 @@ def autopick_points(self, raw_img_dict, tth_tol=5., eta_tol=5.,
358358
# need xy coords
359359
# !!! forcing ome = 0. -- could be inconsistent with rmat_s
360360
cmv = np.atleast_2d(np.hstack([com_angs, omega]))
361-
gvec_c = xfcapi.anglesToGVec(
361+
gvec_c = xfcapi.angles_to_gvec(
362362
cmv,
363363
chi=self.instr.chi,
364-
rMat_c=rmat_c,
365-
bHat_l=self.instr.beam_vector)
366-
new_xy = xfcapi.gvecToDetectorXY(
364+
rmat_c=rmat_c,
365+
beam_vec=self.instr.beam_vector)
366+
new_xy = xfcapi.gvec_to_xy(
367367
gvec_c,
368368
det.rmat, rmat_s, rmat_c,
369369
det.tvec, self.instr.tvec, tvec_c,
370-
beamVec=self.instr.beam_vector)
370+
beam_vec=self.instr.beam_vector)
371371
meas_xy[iRefl, :] = new_xy
372372
if det.distortion is not None:
373373
meas_xy[iRefl, :] = det.distortion.apply_inverse(

hexrd/fitting/calibration/multigrain.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from hexrd import constants as cnst
88
from hexrd import matrixutil as mutil
9+
from hexrd import rotations
910
from hexrd.transforms import xfcapi
1011

1112
from .. import grains as grainutil
@@ -49,7 +50,7 @@ def calibrate_instrument_from_sx(
4950
if ome_period is not None:
5051
for det_key in instr.detectors:
5152
for ig in range(ngrains):
52-
xyo_det[det_key][ig][:, 2] = xfcapi.mapAngle(
53+
xyo_det[det_key][ig][:, 2] = rotations.mapAngle(
5354
xyo_det[det_key][ig][:, 2],
5455
ome_period
5556
)
@@ -257,7 +258,7 @@ def sxcal_obj_func(plist_fit, plist_full,
257258
# 3) apply stretch tensor
258259
# 4) normalize reciprocal lattice vectors in SAMPLE frame
259260
# 5) transform unit reciprocal lattice vetors back to CRYSAL frame
260-
rmat_c = xfcapi.makeRotMatOfExpMap(grain[:3])
261+
rmat_c = xfcapi.make_rmat_of_expmap(grain[:3])
261262
tvec_c = grain[3:6]
262263
vinv_s = grain[6:]
263264
gvec_c = np.dot(bmat, ghkls.T)
@@ -314,7 +315,7 @@ def sxcal_obj_func(plist_fit, plist_full,
314315
calc_omes_all = np.hstack(calc_omes_all)
315316

316317
diff_vecs_xy = calc_xy_all - meas_xy_all
317-
diff_ome = xfcapi.angularDifference(calc_omes_all, meas_omes_all)
318+
diff_ome = rotations.angularDifference(calc_omes_all, meas_omes_all)
318319
retval = np.hstack(
319320
[diff_vecs_xy,
320321
diff_ome.reshape(npts_tot, 1)]
@@ -359,8 +360,8 @@ def parse_reflection_tables(cfg, instr, grain_ids, refit_idx=None):
359360
valid_reflections = gtable[:, 0] >= 0 # is indexed
360361
not_saturated = gtable[:, 6] < panel.saturation_level
361362
# throw away extremem etas
362-
p90 = xfcapi.angularDifference(gtable[:, 8], cnst.piby2)
363-
m90 = xfcapi.angularDifference(gtable[:, 8], -cnst.piby2)
363+
p90 = rotations.angularDifference(gtable[:, 8], cnst.piby2)
364+
m90 = rotations.angularDifference(gtable[:, 8], -cnst.piby2)
364365
accept_etas = np.logical_or(p90 > ext_eta_tol,
365366
m90 > ext_eta_tol)
366367
logger.info(f"panel '{det_key}', grain {grain_id}")

hexrd/fitting/grains.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from hexrd import matrixutil as mutil
88

99
from hexrd.transforms import xfcapi
10+
from hexrd import constants
11+
from hexrd import rotations
1012

1113
from hexrd.xrdutil import extract_detector_transformation
1214

@@ -15,8 +17,8 @@
1517
epsf = np.finfo(float).eps # ~2.2e-16
1618
sqrt_epsf = np.sqrt(epsf) # ~1.5e-8
1719

18-
bVec_ref = xfcapi.bVec_ref
19-
eta_ref = xfcapi.eta_ref
20+
bVec_ref = constants.beam_vec
21+
eta_ref = constants.eta_vec
2022
vInv_ref = np.r_[1., 1., 1., 0., 0., 0.]
2123

2224

@@ -71,7 +73,7 @@ def fitGrain(gFull, instrument, reflections_dict,
7173
"""
7274
# FIXME: will currently fail if omePeriod is specifed
7375
if omePeriod is not None:
74-
# xyo_det[:, 2] = xfcapi.mapAngle(xyo_det[:, 2], omePeriod)
76+
# xyo_det[:, 2] = rotations.mapAngle(xyo_det[:, 2], omePeriod)
7577
raise RuntimeError
7678

7779
gFit = gFull[gFlag]
@@ -162,7 +164,7 @@ def objFuncFitGrain(gFit, gFull, gFlag,
162164
gFull[gFlag] = gFit
163165

164166
# map parameters to functional arrays
165-
rMat_c = xfcapi.makeRotMatOfExpMap(gFull[:3])
167+
rMat_c = xfcapi.make_rmat_of_expmap(gFull[:3])
166168
tVec_c = gFull[3:6].reshape(3, 1)
167169
vInv_s = gFull[6:]
168170
vMat_s = mutil.vecMVToSymm(vInv_s) # NOTE: Inverse of V from F = V * R
@@ -281,7 +283,9 @@ def objFuncFitGrain(gFit, gFull, gFlag,
281283
# return residual vector
282284
# IDEA: try angles instead of xys?
283285
diff_vecs_xy = calc_xy_all - meas_xyo_all[:, :2]
284-
diff_ome = xfcapi.angularDifference(calc_omes_all, meas_xyo_all[:, 2])
286+
diff_ome = rotations.angularDifference(
287+
calc_omes_all, meas_xyo_all[:, 2]
288+
)
285289
retval = np.hstack([diff_vecs_xy,
286290
diff_ome.reshape(npts, 1)
287291
]).flatten()
@@ -309,15 +313,15 @@ def matchOmegas(xyo_det, hkls_idx, chi, rMat_c, bMat, wavelength,
309313
"""
310314
# get omegas for rMat_s calculation
311315
if omePeriod is not None:
312-
meas_omes = xfcapi.mapAngle(xyo_det[:, 2], omePeriod)
316+
meas_omes = rotations.mapAngle(xyo_det[:, 2], omePeriod)
313317
else:
314318
meas_omes = xyo_det[:, 2]
315319

316-
oangs0, oangs1 = xfcapi.oscillAnglesOfHKLs(
320+
oangs0, oangs1 = xfcapi.oscill_angles_of_hkls(
317321
hkls_idx.T, chi, rMat_c, bMat, wavelength,
318-
vInv=vInv,
319-
beamVec=beamVec,
320-
etaVec=etaVec)
322+
v_inv=vInv,
323+
beam_vec=beamVec,
324+
eta_vec=etaVec)
321325
if np.any(np.isnan(oangs0)):
322326
# debugging
323327
# TODO: remove this
@@ -333,10 +337,12 @@ def matchOmegas(xyo_det, hkls_idx, chi, rMat_c, bMat, wavelength,
333337
# CAPI version gives vstacked angles... must be (2, nhkls)
334338
calc_omes = np.vstack([oangs0[:, 2], oangs1[:, 2]])
335339
if omePeriod is not None:
336-
calc_omes = np.vstack([xfcapi.mapAngle(oangs0[:, 2], omePeriod),
337-
xfcapi.mapAngle(oangs1[:, 2], omePeriod)])
340+
calc_omes = np.vstack([rotations.mapAngle(oangs0[:, 2], omePeriod),
341+
rotations.mapAngle(oangs1[:, 2], omePeriod)])
338342
# do angular difference
339-
diff_omes = xfcapi.angularDifference(np.tile(meas_omes, (2, 1)), calc_omes)
343+
diff_omes = rotations.angularDifference(
344+
np.tile(meas_omes, (2, 1)), calc_omes
345+
)
340346
match_omes = np.argsort(diff_omes, axis=0) == 0
341347
calc_omes = calc_omes.T.flatten()[match_omes.T.flatten()]
342348

0 commit comments

Comments
 (0)