geom class is better suited than asciitable class
removing unused functionality from deprecated asciitable
This commit is contained in:
parent
87a578c1ff
commit
f431dd2092
|
@ -221,13 +221,9 @@ baseFile=os.path.splitext(os.path.basename(options.seedFile))[0]
|
|||
points = np.array(options.grid).prod().astype('float')
|
||||
|
||||
# ----------- calculate target distribution and bin edges
|
||||
targetGeomFile = os.path.splitext(os.path.basename(options.target))[0]+'.geom'
|
||||
targetGeomTable = damask.ASCIItable(targetGeomFile,None,labeled=False,readonly=True)
|
||||
targetGeomTable.head_read()
|
||||
info,devNull = targetGeomTable.head_getGeom()
|
||||
nMicrostructures = info['microstructures']
|
||||
targetVolFrac = np.bincount(targetGeomTable.microstructure_read(info['grid']))[1:nMicrostructures+1]/\
|
||||
float(info['grid'].prod())
|
||||
targetGeom = damask.Geom.from_file(os.path.splitext(os.path.basename(options.target))[0]+'.geom')
|
||||
nMicrostructures = len(np.unique(targetGeom.microstructure))
|
||||
targetVolFrac = np.bincount(targetGeom.microstructure.flatten())/targetGeom.grid.prod().astype(np.float)
|
||||
target=[]
|
||||
for i in range(1,nMicrostructures+1):
|
||||
targetHist,targetBins = np.histogram(targetVolFrac,bins=i) #bin boundaries
|
||||
|
@ -251,13 +247,12 @@ initialGeomVFile = StringIO()
|
|||
initialGeomVFile.write(damask.util.execute('geom_fromVoronoiTessellation '+
|
||||
' -g '+' '.join(list(map(str, options.grid))),bestSeedsVFile)[0])
|
||||
initialGeomVFile.seek(0)
|
||||
initialGeomTable = damask.ASCIItable(initialGeomVFile,None,labeled=False,readonly=True)
|
||||
initialGeomTable.head_read()
|
||||
info,devNull = initialGeomTable.head_getGeom()
|
||||
initialGeom = damask.Geom.from_file(initialGeomVFile)
|
||||
|
||||
if info['microstructures'] != nMicrostructures: damask.util.croak('error. Microstructure count mismatch')
|
||||
if len(np.unique(targetGeom.microstructure)) != nMicrostructures:
|
||||
damask.util.croak('error. Microstructure count mismatch')
|
||||
|
||||
initialData = np.bincount(initialGeomTable.microstructure_read(info['grid']))/points
|
||||
initialData = np.bincount(initialGeom.microstructure.flatten())/points
|
||||
for i in range(nMicrostructures):
|
||||
initialHist = np.histogram(initialData,bins=target[i]['bins'])[0]
|
||||
target[i]['error']=np.sqrt(np.square(np.array(target[i]['histogram']-initialHist)).sum())
|
||||
|
@ -273,7 +268,7 @@ for i in range(nMicrostructures):
|
|||
|
||||
|
||||
if options.maxseeds < 1:
|
||||
maxSeeds = info['microstructures']
|
||||
maxSeeds = len(np.unique(initialGeom.microstructure))
|
||||
else:
|
||||
maxSeeds = options.maxseeds
|
||||
|
||||
|
|
|
@ -473,33 +473,3 @@ class ASCIItable():
|
|||
for item in what: self.data_append(item)
|
||||
except TypeError:
|
||||
self.data += [str(what)]
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def microstructure_read(self,
|
||||
grid,
|
||||
type = 'i',
|
||||
strict = False):
|
||||
"""Read microstructure data (from .geom format)."""
|
||||
def datatype(item):
|
||||
return int(item) if type.lower() == 'i' else float(item)
|
||||
|
||||
N = grid.prod() # expected number of microstructure indices in data
|
||||
microstructure = np.zeros(N,type) # initialize as flat array
|
||||
|
||||
i = 0
|
||||
while i < N and self.data_read():
|
||||
items = self.data
|
||||
if len(items) > 2:
|
||||
if items[1].lower() == 'of':
|
||||
items = np.ones(datatype(items[0]))*datatype(items[2])
|
||||
elif items[1].lower() == 'to':
|
||||
items = np.linspace(datatype(items[0]),datatype(items[2]),
|
||||
abs(datatype(items[2])-datatype(items[0]))+1,dtype=int)
|
||||
else: items = list(map(datatype,items))
|
||||
else: items = list(map(datatype,items))
|
||||
|
||||
s = min(len(items), N-i) # prevent overflow of microstructure array
|
||||
microstructure[i:i+s] = items[:s]
|
||||
i += len(items)
|
||||
|
||||
return (microstructure, i == N and not self.data_read()) if strict else microstructure # check for proper point count and end of file
|
||||
|
|
Loading…
Reference in New Issue