better fitting name

load implies a more direct takeover.
This commit is contained in:
Martin Diehl 2020-10-09 19:19:05 +02:00
parent 57180952ec
commit 06d11a72da
3 changed files with 19 additions and 18 deletions

View File

@ -50,7 +50,8 @@ for name in filenames:
for l in [options.quaternion,options.phase,options.microstructure]:
if l is not None: labels.append(l)
geom = damask.Geom.load_table(name,options.pos,labels)
t = damask.Table.load(name)
geom = damask.Geom.from_table(t,options.pos,labels)
damask.util.croak(geom)
geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',compress=False)

View File

@ -6,7 +6,6 @@ from . import grid_filters
from . import Config
from . import Lattice
from . import Rotation
from . import Table
class ConfigMaterial(Config):
"""Material configuration."""
@ -27,13 +26,13 @@ class ConfigMaterial(Config):
@staticmethod
def load_table(fname,coordinates=None,constituents={},**kwargs):
def from_table(table,coordinates=None,constituents={},**kwargs):
"""
Load from an ASCII table.
Parameters
----------
fname : str, file handle, or damask.Table
table : damask.Table
Table that contains material information.
coordinates : str, optional
Label of spatial coordiates. Used for sorting and performing a
@ -50,11 +49,12 @@ class ConfigMaterial(Config):
--------
>>> import damask
>>> import damask.ConfigMaterial as cm
>>> damask.Table.load('small.txt')
>>> t = damask.Table.load('small.txt')
>>> t
pos pos pos qu qu qu qu phase homog
0 0 0 0 0.19 0.8 0.24 -0.51 Aluminum SX
1 1 0 0 0.8 0.19 0.24 -0.51 Steel SX
>>> cm.load_table('small.txt','pos',{'O':'qu','phase':'phase'},homogenization='homog')
>>> cm.from_table(t,'pos',{'O':'qu','phase':'phase'},homogenization='homog')
material:
- constituents:
- O: [0.19, 0.8, 0.24, -0.51]
@ -68,10 +68,12 @@ class ConfigMaterial(Config):
homogenization: SX
"""
t = Table.load(fname)
if coordinates is not None:
t = t.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)])
t = table.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)])
grid_filters.coord0_check(t.get(coordinates))
else:
t = table
constituents_ = {k:t.get(v) for k,v in constituents.items()}
kwargs_ = {k:t.get(v) for k,v in kwargs.items()}

View File

@ -11,7 +11,6 @@ from . import environment
from . import VTK
from . import util
from . import grid_filters
from . import Table
from . import Rotation
@ -246,14 +245,14 @@ class Geom:
@staticmethod
def load_table(fname,coordinates,labels):
def from_table(table,coordinates,labels):
"""
Load an ASCII table.
Parameters
----------
fname : str, file handle, or damask.Table
Table that contains geometry information.
table : damask.Table
Table that contains material information.
coordinates : str
Label of the column containing the spatial coordinates.
labels : str or list of str
@ -261,16 +260,15 @@ class Geom:
Each unique combintation of values results in a material.
"""
table = (fname if isinstance(fname,Table) else Table.load(fname)). \
sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)])
t = table.sort_by([f'{i}_{coordinates}' for i in range(3,0,-1)])
grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(table.get(coordinates))
grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(t.get(coordinates))
labels_ = [labels] if isinstance(labels,str) else labels
_,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0)
_,unique_inverse = np.unique(np.hstack([t.get(l) for l in labels_]),return_inverse=True,axis=0)
ma = unique_inverse.reshape(grid,order='F') + 1
return Geom(ma,size,origin,util.execution_stamp('Geom','load_table'))
return Geom(ma,size,origin,util.execution_stamp('Geom','from_table'))
@staticmethod