Skip to content

Commit 64f5999

Browse files
committed
Merge branch 'housekeeping_2025-02-22' into 'development'
several small improvements See merge request damask/DAMASK!1034
2 parents 8e0d208 + e797026 commit 64f5999

17 files changed

+198
-345
lines changed

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ doctest:
122122
- export DAMASK_ROOT=$(pwd)
123123
- PYTHONPATH=${DAMASK_ROOT}/python:$PYTHONPATH
124124
- cd python
125-
- python3 -m pytest -v --doctest-modules -k 'not result and not configmaterial and not orientation and not rotation and not geomgrid' damask
125+
- python3 -m pytest -v --doctest-modules -k 'not result and not configmaterial and not orientation and not geomgrid' damask
126126

127127
mypy:
128128
extends: .python_default

examples/grid/20grains.seeds

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
1_pos 2_pos 3_pos 1_euler 2_euler 3_euler
2-
0.375488 0.161813 0.891040 197.572861 16.816409 129.422844
3-
0.187988 0.849313 0.953540 257.468172 53.250534 157.331503
4-
0.750488 0.349313 0.953540 216.994815 94.418518 251.147231
5-
0.312988 0.099313 0.891040 196.157946 55.870978 21.681170
6-
0.562988 0.536813 0.703540 152.515728 139.769395 240.036018
7-
0.750488 0.036813 0.641040 232.521881 73.749222 241.429633
8-
0.812988 0.724313 0.016040 157.531396 135.503513 75.737722
9-
0.187988 0.161813 0.266040 321.038280 27.209843 46.413467
10-
0.562988 0.286813 0.203540 346.918594 87.495569 113.554206
11-
0.937988 0.599313 0.953540 138.038947 99.827132 130.935878
12-
0.937988 0.349313 0.578540 285.021014 118.092004 205.270837
13-
0.812988 0.661813 0.453540 190.402171 56.738068 157.896545
14-
0.125488 0.411813 0.203540 204.496042 95.031265 355.814582
15-
0.625488 0.224313 0.578540 333.214790 82.133355 36.736132
16-
0.687988 0.161813 0.891040 25.572981 164.242648 75.195632
17-
0.625488 0.161813 0.766040 31.366548 76.392403 58.071426
18-
0.437988 0.724313 0.266040 7.278623 77.044663 235.118997
19-
0.437988 0.099313 0.641040 299.743144 76.475096 91.184977
20-
0.937988 0.911813 0.828540 280.136430 27.439718 167.871878
21-
0.437988 0.411813 0.516040 313.204373 68.676053 87.993213
1+
1_pos 2_pos 3_pos
2+
0.375488 0.161813 0.891040
3+
0.187988 0.849313 0.953540
4+
0.750488 0.349313 0.953540
5+
0.312988 0.099313 0.891040
6+
0.562988 0.536813 0.703540
7+
0.750488 0.036813 0.641040
8+
0.812988 0.724313 0.016040
9+
0.187988 0.161813 0.266040
10+
0.562988 0.286813 0.203540
11+
0.937988 0.599313 0.953540
12+
0.937988 0.349313 0.578540
13+
0.812988 0.661813 0.453540
14+
0.125488 0.411813 0.203540
15+
0.625488 0.224313 0.578540
16+
0.687988 0.161813 0.891040
17+
0.625488 0.161813 0.766040
18+
0.437988 0.724313 0.266040
19+
0.437988 0.099313 0.641040
20+
0.937988 0.911813 0.828540
21+
0.437988 0.411813 0.516040

python/damask/_configmaterial.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def from_table(table: Table,*,
242242
kwargs = {}
243243
for arg,val in zip(['homogenization','phase','v','O','V_e'],[homogenization,phase,v,O,V_e]):
244244
if val is not None:
245-
kwargs[arg] = table.get(val) if val in table.labels else np.atleast_2d([val]*len(table)).T # type: ignore
245+
kwargs[arg] = table.get(val) if val in table.labels else np.atleast_2d([val]*len(table)).T # type: ignore[arg-type]
246246

247247
_,idx = np.unique(np.hstack(list(kwargs.values())),return_index=True,axis=0)
248248
idx = np.sort(idx)
@@ -584,7 +584,7 @@ def material_add(self,*,
584584
for arg,val in zip(['homogenization','phase','v','O','V_e'],[homogenization,phase,v,O,V_e]):
585585
if val is None: continue
586586
shape[arg] = np.array(val)
587-
s = shape[arg].shape[:ex.get(arg,None)] # type: ignore
587+
s = shape[arg].shape[:ex.get(arg,None)]
588588
N_materials = max(N_materials,s[0]) if len(s)>0 else N_materials
589589
N_constituents = max(N_constituents,s[1]) if len(s)>1 else N_constituents
590590

@@ -617,7 +617,7 @@ def material_add(self,*,
617617
dup['material'] = dup['material'] + mat if 'material' in dup else mat
618618

619619
for what in [item for item in ['phase','homogenization'] if item in shape]:
620-
for k in np.unique(shape[what]): # type: ignore
620+
for k in np.unique(shape[what]):
621621
if k not in dup[what]: dup[what][str(k)] = None
622622

623623
return dup

python/damask/_crystal.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def __eq__(self,
801801
return (NotImplemented if not isinstance(other, Crystal) else
802802
self.lattice == other.lattice and
803803
self.parameters == other.parameters and
804-
self.family == other.family) # type: ignore
804+
self.family == other.family)
805805

806806
@property
807807
def parameters(self) -> Optional[Dict]:
@@ -1230,7 +1230,7 @@ def characteristic_shear_twin(self,
12301230
return np.array([[0.5*np.sqrt(2.0)]*N_twin_[0]])
12311231
elif self.lattice == 'hP':
12321232
N_twin_ = [len(a) for a in _kinematics[self.lattice]['twin']] if N_twin == '*' else N_twin
1233-
c_a = self.c/self.a #type: ignore
1233+
c_a = self.c/self.a # type: ignore[operator]
12341234
return np.array([[(3.0-c_a**2)/np.sqrt(3.0)/c_a]*N_twin_[0],
12351235
[1.0/c_a]*N_twin_[1],
12361236
[(9.0-4.0*c_a**2)/np.sqrt(48.0)/c_a]*N_twin_[2],
@@ -1285,15 +1285,15 @@ def relation_operations(self,
12851285
raise KeyError(f'unknown orientation relationship "{model}"')
12861286

12871287
sep = '-->'
1288-
search = self.lattice+sep+('' if target is None else target.lattice) # type: ignore
1289-
transform = [t for t in orientation_relationships[model].keys() if t.startswith(search)] # type: ignore
1288+
search = self.lattice+sep+('' if target is None else target.lattice) # type: ignore[operator]
1289+
transform = [t for t in orientation_relationships[model].keys() if t.startswith(search)]
12901290

12911291
if len(transform) != 1:
12921292
raise ValueError(f'invalid target lattice "{search.split(sep)[1]}"')
12931293

1294-
m_l,o_l = transform[0].split(sep) # type: ignore
1294+
m_l,o_l = transform[0].split(sep) # type: ignore[assignment]
12951295
m_p,o_p = orientation_relationships[model][m_l+sep+o_l]
1296-
m = Crystal(lattice=m_l) if self.parameters is None else Crystal(lattice=m_l,**self.parameters) # type: ignore
1296+
m = Crystal(lattice=m_l) if self.parameters is None else Crystal(lattice=m_l,**self.parameters)
12971297
o = Crystal(lattice=o_l) if target is None else target
12981298
m_p = np.stack((m.to_frame(uvw=m_p[:,0] if m_l != 'hP' else util.Bravais_to_Miller(uvtw=m_p[:,0])),
12991299
m.to_frame(hkl=m_p[:,1] if m_l != 'hP' else util.Bravais_to_Miller(hkil=m_p[:,1]))),

python/damask/_geomgrid.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from . import Colormap
1919
from ._typehints import FloatSequence, IntSequence, NumpyRngSeed
2020
try:
21-
import numba as nb # type: ignore
21+
import numba as nb # type: ignore[import-not-found]
2222
except ImportError:
2323
nb = False
2424

@@ -61,8 +61,8 @@ def __init__(self,
6161
6262
"""
6363
self.material = material
64-
self.size = size # type: ignore
65-
self.origin = origin # type: ignore
64+
self.size = size # type: ignore[assignment]
65+
self.origin = origin # type: ignore[assignment]
6666
self.initial_conditions = {} if initial_conditions is None else initial_conditions
6767
self.comments = [] if comments is None else \
6868
[comments] if isinstance(comments,str) else \
@@ -169,9 +169,9 @@ def origin(self,
169169
@property
170170
def initial_conditions(self) -> Dict[str,np.ndarray]:
171171
"""Fields of initial conditions."""
172-
self._ic = dict(zip(self._ic.keys(), # type: ignore
172+
self._ic = dict(zip(self._ic.keys(), # type: ignore[has-type]
173173
[v if isinstance(v,np.ndarray) else
174-
np.broadcast_to(v,self.cells) for v in self._ic.values()])) # type: ignore
174+
np.broadcast_to(v,self.cells) for v in self._ic.values()])) # type: ignore[has-type]
175175
return self._ic
176176

177177
@initial_conditions.setter
@@ -214,7 +214,7 @@ def _load(fname: Union[str, Path], label: str) -> 'GeomGrid':
214214
215215
"""
216216
v = VTK.load(fname if str(fname).endswith('.vti') else str(fname)+'.vti')
217-
cells = np.array(v.vtk_data.GetDimensions())-1 # type: ignore
217+
cells = np.array(v.vtk_data.GetDimensions())-1 # type: ignore[attr-defined]
218218
bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T
219219
ic = {l:v.get(l).reshape(cells,order='F') for l in set(v.labels['Cell Data']) - {label}}
220220

@@ -307,7 +307,7 @@ def load_Neper(fname: Union[str, Path]) -> 'GeomGrid':
307307
308308
"""
309309
v = VTK.load(fname,'ImageData')
310-
cells = np.array(v.vtk_data.GetDimensions())-1 # type: ignore
310+
cells = np.array(v.vtk_data.GetDimensions())-1 # type: ignore[attr-defined]
311311
bbox = np.array(v.vtk_data.GetBounds()).reshape(3,2).T
312312

313313
return GeomGrid(material = v.get('MaterialId').reshape(cells,order='F').astype('int32',casting='unsafe'),

python/damask/_loadcasegrid.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class MaskedMatrixDumper(NiceDumper):
1111
"""Format masked matrices."""
1212

1313
def represent_data(self, data: Any):
14-
return super().represent_data(data.astype(object).filled('x') if isinstance(data, ma.core.MaskedArray) else data) # type: ignore[attr-defined]
14+
return super().represent_data(data.astype(object).filled('x') # type: ignore[attr-defined]
15+
if isinstance(data, ma.core.MaskedArray) else
16+
data)
1517

1618

1719
class LoadcaseGrid(YAML):

python/damask/_orientation.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,27 @@ def from_fiber_component(crystal: IntSequence,
983983
984984
Ranges 0≤θ≤π and 0≤φ≤2π give a unique set of coordinates.
985985
986+
Notes
987+
-----
988+
The value for sigma should be small enough to avoid values
989+
larger than the maximum disorientation of the crystal family
990+
when sampling from a normal distribution.
991+
The maximum disorientation angle d_max is 62.80°, 93.84°,
992+
98.43°, and 120° for cubic, hexagonal, tetragonal, and
993+
orthorhombic crystal families, respectively.
994+
A typically safe value is σ = d_max/5.
995+
996+
References
997+
----------
998+
A. Heinz and P. Neumann, Acta Crystallographica Section A 47:780-789, 1991
999+
https://doi.org/10.1107/S0108767391006864
1000+
9861001
"""
9871002
return Orientation(Rotation.from_fiber_component(crystal,sample,sigma,shape,degrees,rng_seed),
9881003
family=family,lattice=lattice,
9891004
a=a,b=b,c=c, alpha=alpha,beta=beta,gamma=gamma,
9901005
degrees=degrees)
1006+
9911007
@staticmethod
9921008
def from_directions(uvw: IntSequence,
9931009
hkl: IntSequence,
@@ -1142,6 +1158,14 @@ def larger_or_equal(v,c):
11421158
else [-np.inf, -np.inf, -np.inf]) & self.in_FZ
11431159

11441160

1161+
@overload
1162+
def disorientation(self: MyType, other: MyType,
1163+
return_operators: Literal[False] = False) -> MyType:
1164+
...
1165+
@overload
1166+
def disorientation(self: MyType, other: MyType,
1167+
return_operators: Literal[True] = True) -> DisorientationTuple:
1168+
...
11451169
def disorientation(self: MyType,
11461170
other: MyType,
11471171
return_operators: bool = False) -> Union[MyType, DisorientationTuple]:
@@ -1206,7 +1230,7 @@ def disorientation(self: MyType,
12061230
s = self.broadcast_to(s_m).equivalent
12071231
o = other.broadcast_to(s_o).equivalent
12081232

1209-
r_ = s[:,np.newaxis,...].misorientation(o[np.newaxis,:,...]) # type: ignore[index]
1233+
r_ = s[:,np.newaxis,...].misorientation(o[np.newaxis,:,...])
12101234
_r = ~r_
12111235
shp = r_.shape[2:]
12121236

@@ -1309,14 +1333,14 @@ def disorientation_angle(self: MyType,
13091333
trace_max = np.maximum.reduce([trace_max,m1,(m1+m2)*np.sqrt(2.)/2.])
13101334

13111335
else:
1312-
return self.disorientation(other).as_axis_angle(pair=True)[1] # type: ignore
1336+
return self.disorientation(other).as_axis_angle(pair=True)[1]
13131337

13141338
return 2.*np.arccos(np.clip(trace_max[...,0].round(15),None,1.))
13151339

13161340

13171341
def average(self: MyType, # type: ignore[override]
13181342
weights: Optional[FloatSequence] = None,
1319-
return_cloud: bool = False) -> Union[MyType, AverageTuple]:
1343+
return_cloud: Optional[bool] = False) -> Union[MyType, AverageTuple]:
13201344
"""
13211345
Return orientation average over last dimension.
13221346
@@ -1512,7 +1536,7 @@ def IPF_color(self,
15121536
raise ValueError('input is not a field of three-dimensional vectors')
15131537

15141538
vector_:np.ndarray = self.to_SST(vector,proper) if in_SST else \
1515-
self @ np.broadcast_to(vector,self.shape+(3,)) #type: ignore
1539+
self @ np.broadcast_to(vector,self.shape+(3,))
15161540

15171541
if self.standard_triangle is None: # direct exit for no symmetry
15181542
return np.zeros_like(vector_)
@@ -1533,7 +1557,7 @@ def IPF_color(self,
15331557
np.broadcast_to(self.standard_triangle['improper'], vector_.shape+(3,)),
15341558
np.block([vector_[...,:2],np.abs(vector_[...,2:3])])), 12)
15351559

1536-
in_SST_ = np.all(components >= 0.0,axis=-1) #type: ignore
1560+
in_SST_ = np.all(components >= 0.0,axis=-1)
15371561

15381562
with np.errstate(invalid='ignore',divide='ignore'):
15391563
rgb = (components/np.linalg.norm(components,axis=-1,keepdims=True))**(1./3.) # smoothen color ramps
@@ -1719,7 +1743,7 @@ def related(self: MyType,
17191743
"""
17201744
lattice,o = self.relation_operations(model,target)
17211745
target = Crystal(lattice=lattice) if target is None else target
1722-
return Orientation(rotation=o*Rotation(self.quaternion)[np.newaxis,...], # type: ignore
1746+
return Orientation(rotation=o*Rotation(self.quaternion)[np.newaxis,...], # type: ignore[return-value]
17231747
lattice=target.lattice,
17241748
a=target.a,
17251749
b=target.b,

0 commit comments

Comments
 (0)