using numpy functionality
This commit is contained in:
parent
51da632108
commit
96d4975fc4
|
@ -608,10 +608,10 @@ class Geom:
|
|||
Direction(s) along which the microstructure is mirrored.
|
||||
Valid entries are 'x', 'y', 'z'.
|
||||
reflect : bool, optional
|
||||
Reflect (include) outermost layers.
|
||||
Reflect (include) outermost layers. Defaults to False.
|
||||
|
||||
"""
|
||||
valid = {'x','y','z'}
|
||||
valid = ['x','y','z']
|
||||
if not set(directions).issubset(valid):
|
||||
raise ValueError(f'Invalid direction {set(directions).difference(valid)} specified.')
|
||||
|
||||
|
@ -641,19 +641,11 @@ class Geom:
|
|||
Valid entries are 'x', 'y', 'z'.
|
||||
|
||||
"""
|
||||
valid = {'x','y','z'}
|
||||
valid = ['x','y','z']
|
||||
if not set(directions).issubset(valid):
|
||||
raise ValueError(f'Invalid direction {set(directions).difference(valid)} specified.')
|
||||
|
||||
limits = [None,None]
|
||||
ms = self.get_microstructure()
|
||||
|
||||
if 'z' in directions:
|
||||
ms = ms[:,:,limits[0]:limits[1]:-1]
|
||||
if 'y' in directions:
|
||||
ms = ms[:,limits[0]:limits[1]:-1,:]
|
||||
if 'x' in directions:
|
||||
ms = ms[limits[0]:limits[1]:-1,:,:]
|
||||
ms = np.flip(self.microstructure, (valid.index(d) for d in directions if d in valid))
|
||||
|
||||
return self.duplicate(ms,
|
||||
comments=self.get_comments()+[util.execution_stamp('Geom','flip')],
|
||||
|
|
|
@ -168,6 +168,9 @@ class TestGeom:
|
|||
assert geom_equal(Geom.from_file(reference),
|
||||
modified)
|
||||
|
||||
def test_flip_invariant(self,default):
|
||||
assert geom_equal(default,default.flip([]))
|
||||
|
||||
@pytest.mark.parametrize('directions',[(1,2,'y'),('a','b','x'),[1]])
|
||||
def test_flip_invalid(self,default,directions):
|
||||
with pytest.raises(ValueError):
|
||||
|
|
Loading…
Reference in New Issue