Merge branch 'MoreImprovements' into PGI-support
This commit is contained in:
commit
93d7d080ec
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
from io import StringIO
|
||||
from optparse import OptionParser
|
||||
|
||||
import numpy as np
|
||||
|
@ -24,61 +25,33 @@ Transform X,Y,Z,F APS BeamLine 34 coordinates to x,y,z APS strain coordinates.
|
|||
|
||||
parser.add_option('-f','--frame',dest='frame', metavar='string',
|
||||
help='label of APS X,Y,Z coords')
|
||||
parser.add_option('--depth', dest='depth', metavar='string',
|
||||
parser.add_option('--depth', dest='depth', metavar='string',
|
||||
help='depth')
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
if filenames == []: filenames = [None]
|
||||
|
||||
if options.frame is None:
|
||||
parser.error('frame not specified')
|
||||
if options.depth is None:
|
||||
parser.error('depth not specified')
|
||||
|
||||
# --- loop over input files ------------------------------------------------------------------------
|
||||
|
||||
if filenames == []: filenames = [None]
|
||||
theta=-0.75*np.pi
|
||||
RotMat2TSL=np.array([[1., 0., 0.],
|
||||
[0., np.cos(theta), np.sin(theta)], # Orientation to account for -135 deg
|
||||
[0., -np.sin(theta), np.cos(theta)]]) # rotation for TSL convention
|
||||
|
||||
for name in filenames:
|
||||
try: table = damask.ASCIItable(name = name,
|
||||
buffered = False)
|
||||
except: continue
|
||||
damask.util.report(scriptName,name)
|
||||
damask.util.report(scriptName,name)
|
||||
|
||||
# ------------------------------------------ read header ------------------------------------------
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
|
||||
coord = - table.get(options.frame)
|
||||
coord[:,2] += table.get(options.depth)[:,0]
|
||||
|
||||
table.head_read()
|
||||
table.add('coord',
|
||||
np.einsum('ijk,ik->ij',np.broadcast_to(RotMat2TSL,(coord.shape[0],3,3)),coord),
|
||||
scriptID+' '+' '.join(sys.argv[1:]))
|
||||
|
||||
# ------------------------------------------ sanity checks -----------------------------------------
|
||||
errors = []
|
||||
if table.label_dimension(options.frame) != 3:
|
||||
errors.append('input {} does not have dimension 3.'.format(options.frame))
|
||||
if table.label_dimension(options.depth) != 1:
|
||||
errors.append('input {} does not have dimension 1.'.format(options.depth))
|
||||
if errors != []:
|
||||
damask.util.croak(errors)
|
||||
table.close(dismiss = True)
|
||||
continue
|
||||
|
||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||
|
||||
# ------------------------------------------ assemble header ---------------------------------------
|
||||
table.labels_append(['%i_coord'%(i+1) for i in range(3)]) # extend ASCII header with new labels
|
||||
table.head_write()
|
||||
|
||||
# ------------------------------------------ process data ------------------------------------------
|
||||
theta=-0.75*np.pi
|
||||
RotMat2TSL=np.array([[1., 0., 0.],
|
||||
[0., np.cos(theta), np.sin(theta)], # Orientation to account for -135 deg
|
||||
[0., -np.sin(theta), np.cos(theta)]]) # rotation for TSL convention
|
||||
outputAlive = True
|
||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||
coord = list(map(float,table.data[table.label_index(options.frame):table.label_index(options.frame)+3]))
|
||||
depth = float(table.data[table.label_index(options.depth)])
|
||||
|
||||
table.data_append(np.dot(RotMat2TSL,np.array([-coord[0],-coord[1],-coord[2]+depth])))
|
||||
|
||||
outputAlive = table.data_write() # output processed line
|
||||
|
||||
# ------------------------------------------ output finalization -----------------------------------
|
||||
|
||||
table.close() # close ASCII tables
|
||||
table.to_ASCII(sys.stdout if name is None else name)
|
||||
|
|
|
@ -176,7 +176,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
F = table.get(options.defgrad).reshape(grid[2],grid[1],grid[0],3,3)
|
||||
nodes = damask.grid_filters.node_coord(size,F)
|
||||
|
|
|
@ -44,7 +44,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
for label in options.labels:
|
||||
field = table.get(label)
|
||||
|
|
|
@ -50,7 +50,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
F = table.get(options.f).reshape(np.append(grid[::-1],(3,3)))
|
||||
if options.nodal:
|
||||
|
|
|
@ -44,7 +44,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
for label in options.labels:
|
||||
field = table.get(label)
|
||||
|
|
|
@ -143,7 +143,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
neighborhood = neighborhoods[options.neighborhood]
|
||||
diffToNeighbor = np.empty(list(grid+2)+[len(neighborhood)],'i')
|
||||
|
|
|
@ -44,7 +44,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
for label in options.labels:
|
||||
field = table.get(label)
|
||||
|
|
|
@ -65,7 +65,7 @@ for name in filenames:
|
|||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
|
||||
if (options.grid is None or options.size is None):
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
else:
|
||||
grid = np.array(options.grid,'i')
|
||||
size = np.array(options.size,'d')
|
||||
|
|
|
@ -54,7 +54,7 @@ for name in filenames:
|
|||
damask.util.report(scriptName,name)
|
||||
|
||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.get(options.pos))
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
packing = np.array(options.packing,'i')
|
||||
outSize = grid*packing
|
||||
|
|
|
@ -86,7 +86,7 @@ for name in filenames:
|
|||
if options.phase is None:
|
||||
table.data = np.column_stack((table.data,np.ones(len(table.data)))) # add single phase if no phase column given
|
||||
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_2_DNA(table.data[:,0:3])
|
||||
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.data[:,0:3])
|
||||
|
||||
indices = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # indices of position when sorting x fast, z slow
|
||||
microstructure = np.empty(grid,dtype = int) # initialize empty microstructure
|
||||
|
|
|
@ -181,7 +181,7 @@ def cell_coord(size,F,origin=np.zeros(3)):
|
|||
"""
|
||||
return cell_coord0(F.shape[:3][::-1],size,origin) + cell_displacement(size,F)
|
||||
|
||||
def cell_coord0_2_DNA(coord0,ordered=True):
|
||||
def cell_coord0_gridSizeOrigin(coord0,ordered=True):
|
||||
"""
|
||||
Return grid 'DNA', i.e. grid, size, and origin from array of cell positions.
|
||||
|
||||
|
@ -231,7 +231,7 @@ def coord0_check(coord0):
|
|||
array of undeformed cell coordinates.
|
||||
|
||||
"""
|
||||
cell_coord0_2_DNA(coord0,ordered=True)
|
||||
cell_coord0_gridSizeOrigin(coord0,ordered=True)
|
||||
|
||||
|
||||
|
||||
|
@ -331,7 +331,7 @@ def node_2_cell(node_data):
|
|||
|
||||
return c[:-1,:-1,:-1]
|
||||
|
||||
def node_coord0_2_DNA(coord0,ordered=False):
|
||||
def node_coord0_gridSizeOrigin(coord0,ordered=False):
|
||||
"""
|
||||
Return grid 'DNA', i.e. grid, size, and origin from array of nodal positions.
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ class TestGridFilters:
|
|||
|
||||
@pytest.mark.parametrize('mode',[('cell'),('node')])
|
||||
def test_grid_DNA(self,mode):
|
||||
"""Ensure that xx_coord0_2_DNA is the inverse of xx_coord0."""
|
||||
"""Ensure that xx_coord0_gridSizeOrigin is the inverse of xx_coord0."""
|
||||
grid = np.random.randint(8,32,(3))
|
||||
size = np.random.random(3)
|
||||
origin = np.random.random(3)
|
||||
coord0 = eval('grid_filters.{}_coord0(grid,size,origin)'.format(mode)) # noqa
|
||||
_grid,_size,_origin = eval('grid_filters.{}_coord0_2_DNA(coord0.reshape((-1,3)))'.format(mode))
|
||||
_grid,_size,_origin = eval('grid_filters.{}_coord0_gridSizeOrigin(coord0.reshape((-1,3)))'.format(mode))
|
||||
assert np.allclose(grid,_grid) and np.allclose(size,_size) and np.allclose(origin,_origin)
|
||||
|
||||
def test_displacement_fluct_equivalence(self):
|
||||
|
|
Loading…
Reference in New Issue