added Geom.copy() method
This commit is contained in:
parent
bd78bf9d1d
commit
499ce01748
|
@ -1,4 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
|
import copy
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
@ -52,6 +53,16 @@ class Geom:
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def __copy__(self):
|
||||||
|
"""Copy geometry."""
|
||||||
|
return copy.deepcopy(self)
|
||||||
|
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
"""Copy geometry."""
|
||||||
|
return self.__copy__()
|
||||||
|
|
||||||
|
|
||||||
def update(self,microstructure=None,size=None,origin=None,rescale=False):
|
def update(self,microstructure=None,size=None,origin=None,rescale=False):
|
||||||
"""
|
"""
|
||||||
Update microstructure and size.
|
Update microstructure and size.
|
||||||
|
@ -774,4 +785,3 @@ class Geom:
|
||||||
|
|
||||||
#ToDo: self.add_comments('geom.py:vicinity_offset v{}'.format(version)
|
#ToDo: self.add_comments('geom.py:vicinity_offset v{}'.format(version)
|
||||||
return self.update(microstructure)
|
return self.update(microstructure)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import copy
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
@ -31,7 +29,7 @@ def reference_dir(reference_dir_base):
|
||||||
class TestGeom:
|
class TestGeom:
|
||||||
|
|
||||||
def test_update(self,default):
|
def test_update(self,default):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
modified.update(
|
modified.update(
|
||||||
default.get_microstructure(),
|
default.get_microstructure(),
|
||||||
default.get_size(),
|
default.get_size(),
|
||||||
|
@ -110,7 +108,7 @@ class TestGeom:
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_mirror(self,default,update,reference_dir,directions,reflect):
|
def test_mirror(self,default,update,reference_dir,directions,reflect):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
modified.mirror(directions,reflect)
|
modified.mirror(directions,reflect)
|
||||||
tag = f'directions={"-".join(directions)}_reflect={reflect}'
|
tag = f'directions={"-".join(directions)}_reflect={reflect}'
|
||||||
reference = reference_dir/f'mirror_{tag}.geom'
|
reference = reference_dir/f'mirror_{tag}.geom'
|
||||||
|
@ -119,7 +117,7 @@ class TestGeom:
|
||||||
|
|
||||||
@pytest.mark.parametrize('stencil',[1,2,3,4])
|
@pytest.mark.parametrize('stencil',[1,2,3,4])
|
||||||
def test_clean(self,default,update,reference_dir,stencil):
|
def test_clean(self,default,update,reference_dir,stencil):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
modified.clean(stencil)
|
modified.clean(stencil)
|
||||||
tag = f'stencil={stencil}'
|
tag = f'stencil={stencil}'
|
||||||
reference = reference_dir/f'clean_{tag}.geom'
|
reference = reference_dir/f'clean_{tag}.geom'
|
||||||
|
@ -136,7 +134,7 @@ class TestGeom:
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_scale(self,default,update,reference_dir,grid):
|
def test_scale(self,default,update,reference_dir,grid):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
modified.scale(grid)
|
modified.scale(grid)
|
||||||
tag = f'grid={util.srepr(grid,"-")}'
|
tag = f'grid={util.srepr(grid,"-")}'
|
||||||
reference = reference_dir/f'scale_{tag}.geom'
|
reference = reference_dir/f'scale_{tag}.geom'
|
||||||
|
@ -144,7 +142,7 @@ class TestGeom:
|
||||||
assert geom_equal(modified,Geom.from_file(reference))
|
assert geom_equal(modified,Geom.from_file(reference))
|
||||||
|
|
||||||
def test_renumber(self,default):
|
def test_renumber(self,default):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
microstructure = modified.get_microstructure()
|
microstructure = modified.get_microstructure()
|
||||||
for m in np.unique(microstructure):
|
for m in np.unique(microstructure):
|
||||||
microstructure[microstructure==m] = microstructure.max() + np.random.randint(1,30)
|
microstructure[microstructure==m] = microstructure.max() + np.random.randint(1,30)
|
||||||
|
@ -154,7 +152,7 @@ class TestGeom:
|
||||||
assert geom_equal(modified,default)
|
assert geom_equal(modified,default)
|
||||||
|
|
||||||
def test_substitute(self,default):
|
def test_substitute(self,default):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
microstructure = modified.get_microstructure()
|
microstructure = modified.get_microstructure()
|
||||||
offset = np.random.randint(1,500)
|
offset = np.random.randint(1,500)
|
||||||
microstructure += offset
|
microstructure += offset
|
||||||
|
@ -167,7 +165,7 @@ class TestGeom:
|
||||||
@pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]),
|
@pytest.mark.parametrize('axis_angle',[np.array([1,0,0,86.7]), np.array([0,1,0,90.4]), np.array([0,0,1,90]),
|
||||||
np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])])
|
np.array([1,0,0,175]),np.array([0,-1,0,178]),np.array([0,0,1,180])])
|
||||||
def test_rotate360(self,default,axis_angle):
|
def test_rotate360(self,default,axis_angle):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
for i in range(np.rint(360/axis_angle[3]).astype(int)):
|
for i in range(np.rint(360/axis_angle[3]).astype(int)):
|
||||||
modified.rotate(Rotation.from_axis_angle(axis_angle,degrees=True))
|
modified.rotate(Rotation.from_axis_angle(axis_angle,degrees=True))
|
||||||
assert geom_equal(modified,default)
|
assert geom_equal(modified,default)
|
||||||
|
@ -175,7 +173,7 @@ class TestGeom:
|
||||||
@pytest.mark.parametrize('Eulers',[[32.0,68.0,21.0],
|
@pytest.mark.parametrize('Eulers',[[32.0,68.0,21.0],
|
||||||
[0.0,32.0,240.0]])
|
[0.0,32.0,240.0]])
|
||||||
def test_rotate(self,default,update,reference_dir,Eulers):
|
def test_rotate(self,default,update,reference_dir,Eulers):
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
modified.rotate(Rotation.from_Eulers(Eulers,degrees=True))
|
modified.rotate(Rotation.from_Eulers(Eulers,degrees=True))
|
||||||
tag = f'Eulers={util.srepr(Eulers,"-")}'
|
tag = f'Eulers={util.srepr(Eulers,"-")}'
|
||||||
reference = reference_dir/f'rotate_{tag}.geom'
|
reference = reference_dir/f'rotate_{tag}.geom'
|
||||||
|
@ -184,7 +182,7 @@ class TestGeom:
|
||||||
|
|
||||||
def test_canvas(self,default):
|
def test_canvas(self,default):
|
||||||
grid_add = np.random.randint(0,30,(3))
|
grid_add = np.random.randint(0,30,(3))
|
||||||
modified = copy.deepcopy(default)
|
modified = default.copy()
|
||||||
modified.canvas(modified.grid + grid_add)
|
modified.canvas(modified.grid + grid_add)
|
||||||
e = default.grid
|
e = default.grid
|
||||||
assert np.all(modified.microstructure[:e[0],:e[1],:e[2]] == default.microstructure)
|
assert np.all(modified.microstructure[:e[0],:e[1],:e[2]] == default.microstructure)
|
||||||
|
@ -213,7 +211,7 @@ class TestGeom:
|
||||||
m = np.ones(g,'i')
|
m = np.ones(g,'i')
|
||||||
x = (g*np.random.permutation(np.array([.5,1,1]))).astype('i')
|
x = (g*np.random.permutation(np.array([.5,1,1]))).astype('i')
|
||||||
m[slice(0,x[0]),slice(0,x[1]),slice(0,x[2])] = 2
|
m[slice(0,x[0]),slice(0,x[1]),slice(0,x[2])] = 2
|
||||||
m2 = copy.deepcopy(m)
|
m2 = m.copy()
|
||||||
for i in [0,1,2]:
|
for i in [0,1,2]:
|
||||||
m2[(np.roll(m,+vicinity,i)-m)!=0] += offset
|
m2[(np.roll(m,+vicinity,i)-m)!=0] += offset
|
||||||
m2[(np.roll(m,-vicinity,i)-m)!=0] += offset
|
m2[(np.roll(m,-vicinity,i)-m)!=0] += offset
|
||||||
|
|
Loading…
Reference in New Issue