Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hexrd/core/instrument/hedm_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ def __init__(self, filename):
self.fid = filename
else:
self.fid = open(filename, 'w')
print(self._header, file=self.fid)
self.fid.write(self._header + '\n')

def __del__(self):
self.close()
Expand Down Expand Up @@ -2294,7 +2294,7 @@ def dump_patch(
self._delim.join(np.tile('{:<23.16e}', 10)).format(*res[7:]),
]
)
print(output_str, file=self.fid)
self.fid.write(output_str + '\n')
return output_str


Expand Down Expand Up @@ -2349,7 +2349,7 @@ def __init__(self, filename=None, array=None):
self.fid = filename
else:
self.fid = open(filename, 'w')
print(self._header, file=self.fid)
self.fid.write(self._header + '\n')

def __del__(self):
self.close()
Expand Down Expand Up @@ -2385,7 +2385,7 @@ def dump_grain(self, grain_id, completeness, chisq, grain_params):
self._delim.join(np.tile('{:<23.16e}', len(res) - 3)).format(*res[3:]),
]
)
print(output_str, file=self.fid)
self.fid.write(output_str + '\n')
return output_str


Expand Down
23 changes: 0 additions & 23 deletions hexrd/core/material/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,26 +1562,3 @@ def get_hkl_strings(pdata):
'return_indices': True,
}
return np.intersect1d(**kwargs)[1:]


#
# ============================== Executable section for testing
#


if __name__ == '__main__':
#
# For testing
#
import sys

if len(sys.argv) == 1:
print("need argument: materials.cfg")
sys.exit()

ml = loadMaterialList(sys.argv[1])

print('MATERIAL LIST\n')
print((' from file: ', sys.argv[1]))
for m in ml:
print(m)
10 changes: 6 additions & 4 deletions hexrd/core/material/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ def PrintPossibleSG(xtal_sys):
sgmax = 2
sgmin = 1

line = ""
for i in range(sgmin, sgmax + 1):
j = i - sgmin + 1
pstr = f'{i}:{pstr_spacegroup[i - 1]}\t'
pstr = f"{i}:{pstr_spacegroup[i - 1]}\t"
line += pstr

if j % 4 == 0 or j == sgmax:
print(pstr)
else:
print(pstr, end='')
logger.info(line.rstrip())
line = ""

return sgmin, sgmax

Expand Down
29 changes: 0 additions & 29 deletions hexrd/core/valunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

"""

import doctest
import math

import numpy as np
Expand Down Expand Up @@ -308,31 +307,3 @@ def _degrees(x: float) -> valWUnit:

# Function alias
_angstroms = _angstrom

if __name__ == '__main__': # pragma: no cover
#
# doc testing
#
print("running doctest")
doctest.testmod()

#
# other tests
#
def testConversions():
print('===== Testing unit conversions ...')
print('..... angles:')
v = valWUnit('180d', 'angle', 180.0, 'degrees')
print(v)
print((' in degrees:', v.getVal('degrees')))
print((' in radians: ', v.getVal('radians')))

print('..... lengths:')
ulist = ['m', 'mm', 'meter', 'angstrom']
v = valWUnit('one meter', 'length', 1.0, 'meter')
print(v)
for u in ulist:
print((' in ', u, ': ', v.getVal(u)))
return

testConversions()
1 change: 0 additions & 1 deletion scripts/install/install_build_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,4 @@ def install(library, destination):
library = sys.argv[1]
destination = sys.argv[2]

print(f'Installing "{library}" to "{destination}"')
install(library, destination)
144 changes: 0 additions & 144 deletions tests/fit_grains_check.py

This file was deleted.

68 changes: 64 additions & 4 deletions tests/test_fit-grains.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import pytest
import coloredlogs


from hexrd.core import matrixutil as mutil
from hexrd.core import rotations as rot
from hexrd.hedm import config
from hexrd.hedm.fitgrains import fit_grains


from fit_grains_check import compare_grain_fits


logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

Expand Down Expand Up @@ -73,6 +71,68 @@ def test_config(single_ge_config_path, single_ge_include_path):

return conf

def compare_grain_fits(
fit_grain_params, ref_grain_params, mtol=1.0e-4, ctol=1.0e-3, vtol=1.0e-4
):
"""
Executes comparison between reference and fit grain parameters for ff-HEDM
for the same initial parameters.

Parameters
----------
fit_grain_params : array_like, (n, 12)
The fit grain parameters to be tested.
ref_grain_params : array_like, (n, 12)
The reference grain parameters (see Notes below).

Returns
-------
bool
True is successful comparison

Notes
-----
The fitgrains action currently returns
grain_id, completeness, chisq, grain_params.
We will have to assume that the grain_ids are in the *same order* as the
reference, which can be enforces by running the comparison using the
reference orientation list.
"""
fit_grain_params = np.atleast_2d(fit_grain_params)
ref_grain_params = np.atleast_2d(ref_grain_params)
cresult = False
ii = 0
for fg, rg in zip(fit_grain_params, ref_grain_params):
# test_orientation
quats = rot.quatOfExpMap(np.vstack([fg[:3], rg[:3]]).T)
ang, mis = rot.misorientation(
quats[:, 0].reshape(4, 1), quats[:, 1].reshape(4, 1)
)
if ang <= mtol:
cresult = True
else:
logger.warning(f"orientations for grain {ii} do not agree.")
return cresult

# test position
if np.linalg.norm(fg[3:6] - rg[3:6]) > ctol:
logger.warning(f"centroidal coordinates for grain {ii} do not agree.")
return False

# test strain
vmat_fit = mutil.symmToVecMV(
np.linalg.inv(mutil.vecMVToSymm(fg[6:])), scale=False
)
vmat_ref = mutil.symmToVecMV(
np.linalg.inv(mutil.vecMVToSymm(rg[6:])), scale=False
)
if np.linalg.norm(vmat_fit - vmat_ref, ord=1) > vtol:
logger.warning(f"stretch components for grain {ii} do not agree.")
return False

# index grain id
ii += 1
return cresult

def test_fit_grains(
single_ge_include_path,
Expand Down
Loading