added typehints to seeds.py
This commit is contained in:
parent
34e04fa45e
commit
32aff9d966
|
@ -95,7 +95,7 @@ mypy:
|
||||||
stage: python
|
stage: python
|
||||||
script:
|
script:
|
||||||
- cd $DAMASKROOT/python
|
- cd $DAMASKROOT/python
|
||||||
- mypy damask/tensor.py damask/mechanics.py
|
- mypy damask/tensor.py damask/mechanics.py damask/seeds.py
|
||||||
except:
|
except:
|
||||||
- master
|
- master
|
||||||
- release
|
- release
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
"""Functionality for generation of seed points for Voronoi or Laguerre tessellation."""
|
"""Functionality for generation of seed points for Voronoi or Laguerre tessellation."""
|
||||||
|
|
||||||
from scipy import spatial as _spatial
|
from scipy import spatial as _spatial
|
||||||
|
from typing import Sequence
|
||||||
|
|
||||||
import numpy as _np
|
import numpy as _np
|
||||||
|
|
||||||
from . import util as _util
|
from . import util as _util
|
||||||
from . import grid_filters as _grid_filters
|
from . import grid_filters as _grid_filters
|
||||||
|
from . import _grid
|
||||||
|
|
||||||
|
|
||||||
def from_random(size,N_seeds,cells=None,rng_seed=None):
|
def from_random(size: _np.ndarray, N_seeds: int, cells: _np.ndarray = None, rng_seed=None) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Place seeds randomly in space.
|
Place seeds randomly in space.
|
||||||
|
|
||||||
|
@ -41,7 +44,8 @@ def from_random(size,N_seeds,cells=None,rng_seed=None):
|
||||||
return coords
|
return coords
|
||||||
|
|
||||||
|
|
||||||
def from_Poisson_disc(size,N_seeds,N_candidates,distance,periodic=True,rng_seed=None):
|
def from_Poisson_disc(size: _np.ndarray, N_seeds: int, N_candidates: int, distance: float,
|
||||||
|
periodic: bool = True, rng_seed=None) -> _np.ndarray:
|
||||||
"""
|
"""
|
||||||
Place seeds according to a Poisson disc distribution.
|
Place seeds according to a Poisson disc distribution.
|
||||||
|
|
||||||
|
@ -75,18 +79,17 @@ def from_Poisson_disc(size,N_seeds,N_candidates,distance,periodic=True,rng_seed=
|
||||||
i = 0
|
i = 0
|
||||||
progress = _util._ProgressBar(N_seeds+1,'',50)
|
progress = _util._ProgressBar(N_seeds+1,'',50)
|
||||||
while s < N_seeds:
|
while s < N_seeds:
|
||||||
|
i += 1
|
||||||
candidates = rng.random((N_candidates,3))*_np.broadcast_to(size,(N_candidates,3))
|
candidates = rng.random((N_candidates,3))*_np.broadcast_to(size,(N_candidates,3))
|
||||||
tree = _spatial.cKDTree(coords[:s],boxsize=size) if periodic else \
|
tree = _spatial.cKDTree(coords[:s],boxsize=size) if periodic else \
|
||||||
_spatial.cKDTree(coords[:s])
|
_spatial.cKDTree(coords[:s])
|
||||||
distances = tree.query(candidates)[0]
|
distances = tree.query(candidates)[0]
|
||||||
best = distances.argmax()
|
best = distances.argmax()
|
||||||
if distances[best] > distance: # require minimum separation
|
if distances[best] > distance: # require minimum separation
|
||||||
|
i = 0
|
||||||
coords[s] = candidates[best] # maximum separation to existing point cloud
|
coords[s] = candidates[best] # maximum separation to existing point cloud
|
||||||
s += 1
|
s += 1
|
||||||
progress.update(s)
|
progress.update(s)
|
||||||
i = 0
|
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
if i == 100:
|
if i == 100:
|
||||||
raise ValueError('Seeding not possible')
|
raise ValueError('Seeding not possible')
|
||||||
|
@ -94,7 +97,8 @@ def from_Poisson_disc(size,N_seeds,N_candidates,distance,periodic=True,rng_seed=
|
||||||
return coords
|
return coords
|
||||||
|
|
||||||
|
|
||||||
def from_grid(grid,selection=None,invert=False,average=False,periodic=True):
|
def from_grid(grid: _grid.Grid, selection: Sequence[int] = None,
|
||||||
|
invert: bool = False, average: bool = False, periodic: bool = True) -> tuple[_np.ndarray, _np.ndarray]:
|
||||||
"""
|
"""
|
||||||
Create seeds from grid description.
|
Create seeds from grid description.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue