Skip to content

Commit 6a16d3c

Browse files
committed
Remove fit_grains_check.py
1 parent f0b0a94 commit 6a16d3c

File tree

2 files changed

+64
-144
lines changed

2 files changed

+64
-144
lines changed

tests/fit_grains_check.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

tests/test_fit-grains.py

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
import pytest
88
import coloredlogs
99

10-
10+
from hexrd.core import matrixutil as mutil
11+
from hexrd.core import rotations as rot
1112
from hexrd.hedm import config
1213
from hexrd.hedm.fitgrains import fit_grains
1314

1415

15-
from fit_grains_check import compare_grain_fits
16-
17-
1816
logger = logging.getLogger(__name__)
1917
logger.setLevel(logging.INFO)
2018

@@ -73,6 +71,68 @@ def test_config(single_ge_config_path, single_ge_include_path):
7371

7472
return conf
7573

74+
def compare_grain_fits(
75+
fit_grain_params, ref_grain_params, mtol=1.0e-4, ctol=1.0e-3, vtol=1.0e-4
76+
):
77+
"""
78+
Executes comparison between reference and fit grain parameters for ff-HEDM
79+
for the same initial parameters.
80+
81+
Parameters
82+
----------
83+
fit_grain_params : array_like, (n, 12)
84+
The fit grain parameters to be tested.
85+
ref_grain_params : array_like, (n, 12)
86+
The reference grain parameters (see Notes below).
87+
88+
Returns
89+
-------
90+
bool
91+
True is successful comparison
92+
93+
Notes
94+
-----
95+
The fitgrains action currently returns
96+
grain_id, completeness, chisq, grain_params.
97+
We will have to assume that the grain_ids are in the *same order* as the
98+
reference, which can be enforces by running the comparison using the
99+
reference orientation list.
100+
"""
101+
fit_grain_params = np.atleast_2d(fit_grain_params)
102+
ref_grain_params = np.atleast_2d(ref_grain_params)
103+
cresult = False
104+
ii = 0
105+
for fg, rg in zip(fit_grain_params, ref_grain_params):
106+
# test_orientation
107+
quats = rot.quatOfExpMap(np.vstack([fg[:3], rg[:3]]).T)
108+
ang, mis = rot.misorientation(
109+
quats[:, 0].reshape(4, 1), quats[:, 1].reshape(4, 1)
110+
)
111+
if ang <= mtol:
112+
cresult = True
113+
else:
114+
logger.warning(f"orientations for grain {ii} do not agree.")
115+
return cresult
116+
117+
# test position
118+
if np.linalg.norm(fg[3:6] - rg[3:6]) > ctol:
119+
logger.warning(f"centroidal coordinates for grain {ii} do not agree.")
120+
return False
121+
122+
# test strain
123+
vmat_fit = mutil.symmToVecMV(
124+
np.linalg.inv(mutil.vecMVToSymm(fg[6:])), scale=False
125+
)
126+
vmat_ref = mutil.symmToVecMV(
127+
np.linalg.inv(mutil.vecMVToSymm(rg[6:])), scale=False
128+
)
129+
if np.linalg.norm(vmat_fit - vmat_ref, ord=1) > vtol:
130+
logger.warning(f"stretch components for grain {ii} do not agree.")
131+
return False
132+
133+
# index grain id
134+
ii += 1
135+
return cresult
76136

77137
def test_fit_grains(
78138
single_ge_include_path,

0 commit comments

Comments
 (0)