diff --git a/processing/pre/seeds_fromDistribution.py b/processing/pre/seeds_fromDistribution.py index 94201e97a..3589e7fbf 100755 --- a/processing/pre/seeds_fromDistribution.py +++ b/processing/pre/seeds_fromDistribution.py @@ -149,9 +149,10 @@ class myThread (threading.Thread): break elif currentError[i] < target[i]['error']: # better fit bestSeedsUpdate = time.time() # save time of better fit - print 'Thread %i: Better match (%i bins, %6.4f --> %6.4f)'%(self.threadID,i+1,target[i]['error'],currentError[i]) - print ' target: ',target[i]['histogram'] - print ' best: ',currentHist[i] + damask.util.croak('Thread %i: Better match (%i bins, %6.4f --> %6.4f)' + %(self.threadID,i+1,target[i]['error'],currentError[i])) + damask.util.croak(' target: ',target[i]['histogram']) + damask.util.croak(' best: ',currentHist[i]) currentSeedsName = baseFile+'_'+str(bestSeedsUpdate).replace('.','-') # name of new seed file (use time as unique identifier) perturbedSeedsVFile.reset() bestSeedsVFile.close() @@ -164,7 +165,7 @@ class myThread (threading.Thread): for j in xrange(nMicrostructures): # save new errors for all bins target[j]['error'] = currentError[j] if myMatch > match: # one or more new bins have no deviation - print 'Stage %i cleared'%(myMatch) + damask.util.croak( 'Stage %i cleared'%(myMatch)) match=myMatch sys.stdout.flush() break @@ -179,7 +180,8 @@ class myThread (threading.Thread): target[j]['error'] = currentError[j] randReset = True else: #--- not all grains are tessellated - print 'Thread %i: Microstructure mismatch (%i microstructures mapped)'%(self.threadID,myNmicrostructures) + damask.util.croak('Thread %i: Microstructure mismatch (%i microstructures mapped)' + %(self.threadID,myNmicrostructures)) randReset = True @@ -226,9 +228,11 @@ parser.set_defaults(maxseeds = 0) options = parser.parse_args()[0] +damask.util.report(scriptName,options.seedFile) + if options.randomSeed == None: options.randomSeed = int(os.urandom(4).encode('hex'), 16) -print 'random seed', options.randomSeed +damask.util.croak(options.randomSeed) delta = (options.scale/options.grid[0],options.scale/options.grid[1],options.scale/options.grid[2]) baseFile=os.path.splitext(os.path.basename(options.seedFile))[0] points = float(reduce(mul,options.grid)) @@ -269,7 +273,7 @@ initialGeomTable = damask.ASCIItable(initialGeomVFile,None,labeled=False,readonl initialGeomTable.head_read() info,devNull = initialGeomTable.head_getGeom() -if info['microstructures'] != nMicrostructures: print 'error. Microstructure count mismatch' +if info['microstructures'] != nMicrostructures: damask.util.croak('error. Microstructure count mismatch') initialData = np.bincount(initialGeomTable.microstructure_read(info['grid']))/points for i in xrange(nMicrostructures): @@ -291,7 +295,7 @@ if options.maxseeds < 1: else: maxSeeds = options.maxseeds -if match >0: print 'Stage %i cleared'%match +if match >0: damask.util.croak('Stage %i cleared'%match) sys.stdout.flush() initialGeomVFile.close() diff --git a/processing/pre/seeds_fromGeom.py b/processing/pre/seeds_fromGeom.py index 0b87c3310..8c4e0250e 100755 --- a/processing/pre/seeds_fromGeom.py +++ b/processing/pre/seeds_fromGeom.py @@ -52,14 +52,14 @@ for name in filenames: buffered = False, labeled = False) except: continue - table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else '')) + damask.util.report(scriptName,name) # --- interpret header ---------------------------------------------------------------------------- table.head_read() info,extra_header = table.head_getGeom() - table.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))), + damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))), 'size x y z: %s'%(' x '.join(map(str,info['size']))), 'origin x y z: %s'%(' : '.join(map(str,info['origin']))), 'homogenization: %i'%info['homogenization'], @@ -70,7 +70,7 @@ for name in filenames: if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') if errors != []: - table.croak(errors) + damask.util.croak(errors) table.close(dismiss = True) continue diff --git a/processing/pre/seeds_fromPokes.py b/processing/pre/seeds_fromPokes.py index bfa7337ea..9240e71c2 100755 --- a/processing/pre/seeds_fromPokes.py +++ b/processing/pre/seeds_fromPokes.py @@ -1,9 +1,10 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,re,random,math,numpy as np +import os,math,sys +import numpy as np import damask -from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP +from optparse import OptionParser scriptID = '$Id$' scriptName = scriptID.split()[1] @@ -47,6 +48,7 @@ parser.set_defaults(x = False, (options,filenames) = parser.parse_args() +if options.z == None: parser.error('please specify top and bottom z plane...') # --- loop over output files ------------------------------------------------------------------------- if filenames == []: filenames = [None] @@ -54,17 +56,18 @@ if filenames == []: filenames = [None] for name in filenames: try: table = damask.ASCIItable(name = name, - outname = os.path.splitext(name])[0]+'_poked_{}.seeds'.format(options.N) if name else name, + outname = os.path.splitext(name)[-2]+'_poked_{}.seeds'.format(options.N) if name else name, buffered = False, labeled = False) except: continue - table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else '')) + damask.util.report(scriptName,name) + print os.path.splitext(name)[-1]+'_poked_{}.seeds'.format(options.N) # --- interpret header ---------------------------------------------------------------------------- table.head_read() info,extra_header = table.head_getGeom() - table.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))), + damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))), 'size x y z: %s'%(' x '.join(map(str,info['size']))), 'origin x y z: %s'%(' : '.join(map(str,info['origin']))), 'homogenization: %i'%info['homogenization'], @@ -75,7 +78,7 @@ for name in filenames: if np.any(info['grid'] < 1): errors.append('invalid grid a b c.') if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.') if errors != []: - table.croak(errors) + damask.util.croak(errors) table.close(dismiss = True) continue @@ -93,7 +96,7 @@ for name in filenames: Ny = int(options.N/math.sqrt(options.N*info['size'][0]/info['size'][1])) Nz = int((max(options.z)-min(options.z))/info['size'][2]*info['grid'][2]) - table.croak('poking {} x {} x {}...'.format(Nx,Ny,Nz)) + damask.util.croak('poking {} x {} x {}...'.format(Nx,Ny,Nz)) seeds = np.zeros((Nx*Ny*Nz,4),'d') grid = np.zeros(3,'i') @@ -120,17 +123,16 @@ for name in filenames: remarks = [] if ( newInfo['microstructures'] != info['microstructures']): remarks.append('--> microstructures: %i'%newInfo['microstructures']) - if remarks != []: table.croak(remarks) + if remarks != []: damask.util.croak(remarks) # ------------------------------------------ assemble header --------------------------------------- - table.info_clear() table.info_append(extra_header+[ scriptID + ' ' + ' '.join(sys.argv[1:]), "poking\ta {}\tb {}\tc {}".format(Nx,Ny,Nz), - "grid\ta {}\tb {}\tc {}".format(newInfo['grid']), - "size\tx {}\ty {}\tz {}".format(newInfo['size']), - "origin\tx {}\ty {}\tz {}".format(info['origin']), + "grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']), + "size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']), + "origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']), "homogenization\t{}".format(info['homogenization']), "microstructures\t{}".format(newInfo['microstructures']), ]) @@ -141,8 +143,8 @@ for name in filenames: # --- write seeds information ------------------------------------------------------------ - theTable.data = seeds - theTable.data_writeArray() + table.data = seeds + table.data_writeArray() # --- output finalization -------------------------------------------------------------------------- diff --git a/processing/pre/seeds_fromRandom.py b/processing/pre/seeds_fromRandom.py index be2320d47..12a62966a 100755 --- a/processing/pre/seeds_fromRandom.py +++ b/processing/pre/seeds_fromRandom.py @@ -127,7 +127,7 @@ for name in filenames: buffered = False) except: continue - table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else '')) + damask.util.report(scriptName,name) # --- sanity checks ------------------------------------------------------------------------- @@ -138,9 +138,9 @@ for name in filenames: if options.selective and 4./3.*math.pi*(options.distance/2.)**3*options.N > 0.5: (remarks if options.force else errors).append('maximum recommended seed point count for given distance is {}.{}'.format(int(3./8./math.pi/(options.distance/2.)**3),'..'*options.force)) - if remarks != []: table.croak(remarks) + if remarks != []: damask.util.croak(remarks) if errors != []: - table.croak(errors) + damask.util.croak(errors) sys.exit() # --- do work ------------------------------------------------------------------------------------ @@ -167,7 +167,7 @@ for name in filenames: seeds = np.zeros((options.N,3),dtype=float) # seed positions array seeds[0] = np.random.random(3)*options.grid/max(options.grid) i = 1 # start out with one given point - if i%(options.N/100.) < 1: table.croak('.',False) + if i%(options.N/100.) < 1: damask.util.croak('.',False) while i < options.N: candidates = np.random.random(options.numCandidates*3).reshape(options.numCandidates,3) @@ -176,9 +176,9 @@ for name in filenames: if distances[best] > options.distance: # require minimum separation seeds[i] = candidates[best] # take candidate with maximum separation to existing point cloud i += 1 - if i%(options.N/100.) < 1: table.croak('.',False) + if i%(options.N/100.) < 1: damask.util.croak('.',False) - table.croak('') + damask.util.croak('') seeds = seeds.T # prepare shape for stacking if options.weights: @@ -206,7 +206,7 @@ for name in filenames: ]) table.labels_clear() table.labels_append( ['{dim}_{label}'.format(dim = 1+i,label = 'pos') for i in xrange(3)] + - ['{dim}_{label}'.format(dim = 1+i,label = 'Euler') for i in xrange(3)] + + ['{dim}_{label}'.format(dim = 1+i,label = 'eulerangles') for i in xrange(3)] + ['microstructure'] + (['weight'] if options.weights else [])) table.head_write() diff --git a/processing/pre/seeds_fromTable.py b/processing/pre/seeds_fromTable.py index 9bfbd2578..d406e7916 100755 --- a/processing/pre/seeds_fromTable.py +++ b/processing/pre/seeds_fromTable.py @@ -1,10 +1,9 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,itertools +import os,string,itertools import numpy as np from optparse import OptionParser -from collections import defaultdict import damask scriptID = string.replace('$Id$','\n','\\n') @@ -64,7 +63,7 @@ for name in filenames: outname = os.path.splitext(name)[0]+'.seeds' if name else name, buffered = False) except: continue - table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else '')) + damask.util.report(scriptName,name) table.head_read() # read ASCII header info @@ -82,7 +81,7 @@ for name in filenames: errors.append('column {} has wrong dimension'.format(label)) if errors != []: - table.croak(errors) + damask.util.croak(errors) table.close(dismiss = True) # close ASCII table file handles and delete output file continue