def test_write_read(self, default, tmp_path, mode): default.save(tmp_path / 'default.txt') if mode == 'path': new = Table.load(tmp_path / 'default.txt') elif mode == 'str': new = Table.load(str(tmp_path / 'default.txt')) assert all(default.data == new.data) and default.shapes == new.shapes
def test_relationship_reference(self, update, ref_path, model, lattice): reference = ref_path / f'{lattice}_{model}.txt' o = Orientation(lattice=lattice) eu = o.related(model).as_Euler_angles(degrees=True) if update: coords = np.array([(1, i + 1) for i, x in enumerate(eu)]) Table(eu,{'Eulers':(3,)})\ .add('pos',coords)\ .save(reference) assert np.allclose(eu, Table.load(reference).get('Eulers'))
def test_Schmid(self, update, ref_path, lattice, mode): L = Orientation(lattice=lattice) reference = ref_path / f'{lattice}_{mode}.txt' P = L.Schmid(mode) if update: table = Table(P.reshape(-1, 9), {'Schmid': ( 3, 3, )}) table.save(reference) assert np.allclose(P, Table.load(reference).get('Schmid'))
def test_relationship_reference(self, update, reference_dir, model, lattice): reference = os.path.join(reference_dir, f'{lattice}_{model}.txt') ori = Orientation(Rotation(), lattice) eu = np.array( [o.rotation.as_Eulers(degrees=True) for o in ori.related(model)]) if update: coords = np.array([(1, i + 1) for i, x in enumerate(eu)]) table = Table(eu, {'Eulers': (3, )}) table = table.add('pos', coords) table.save(reference) assert np.allclose(eu, Table.load(reference).get('Eulers'))
def test_Schmid(self, update, ref_path, lattice): O = Orientation(lattice=lattice) # noqa for mode in ['slip', 'twin']: reference = ref_path / f'{lattice}_{mode}.txt' P = O.Schmid(N_slip='*') if mode == 'slip' else O.Schmid( N_twin='*') if update: table = Table(P.reshape(-1, 9), {'Schmid': ( 3, 3, )}) table.save(reference) assert np.allclose(P, Table.load(reference).get('Schmid'))
def test_ODF_cell(self, reference_dir, fractions, degrees, N): steps = np.array([144, 36, 36]) limits = np.array([360., 90., 90.]) rng = tuple(zip(np.zeros(3), limits)) weights = Table.load( reference_dir / 'ODF_experimental_cell.txt').get('intensity').flatten() Eulers = grid_filters.cell_coord0(steps, limits) Eulers = np.radians(Eulers) if not degrees else Eulers Eulers_r = Rotation.from_ODF(weights, Eulers.reshape(-1, 3, order='F'), N, degrees, fractions).as_Eulers(True) weights_r = np.histogramdd( Eulers_r, steps, rng)[0].flatten(order='F') / N * np.sum(weights) if fractions: assert np.sqrt(((weights_r - weights)**2).mean()) < 4
def test_ODF_node(self, reference_dir, degrees, N): steps = np.array([144, 36, 36]) limits = np.array([360., 90., 90.]) rng = tuple(zip(-limits / steps * .5, limits - limits / steps * .5)) weights = Table.load(reference_dir / 'ODF_experimental.txt').get('intensity') weights = weights.reshape(steps + 1, order='F')[:-1, :-1, :-1].reshape(-1, order='F') Eulers = grid_filters.node_coord0(steps, limits)[:-1, :-1, :-1] Eulers = np.radians(Eulers) if not degrees else Eulers Eulers_r = Rotation.from_ODF(weights, Eulers.reshape(-1, 3, order='F'), N, degrees).as_Eulers(True) weights_r = np.histogramdd( Eulers_r, steps, rng)[0].flatten(order='F') / N * np.sum(weights) assert np.sqrt(((weights_r - weights)**2).mean()) < 5
def test_write_read_file(self, default, tmp_path): with open(tmp_path / 'default.txt', 'w') as f: default.save(f) with open(tmp_path / 'default.txt') as f: new = Table.load(f) assert all(default.data == new.data) and default.shapes == new.shapes
def test_read_strange(self, ref_path, fname): with open(ref_path / fname) as f: Table.load(f)
def test_read_strange(self, reference_dir, fname): with open(reference_dir / fname) as f: Table.load(f)
def test_write_read_legacy_style(self, default, tmp_path): with open(tmp_path / 'legacy.txt', 'w') as f: default.save(f, legacy=True) with open(tmp_path / 'legacy.txt') as f: new = Table.load(f) assert all(default.data == new.data) and default.shapes == new.shapes