allow asciitable to use file handle instead of string (following e.g. numpy.genfromtxt)
This commit is contained in:
parent
24bd3a6eee
commit
6a3a0f3859
|
@ -37,11 +37,18 @@ class ASCIItable():
|
||||||
|
|
||||||
self.__IO__['inPlace'] = not outname and name and not readonly
|
self.__IO__['inPlace'] = not outname and name and not readonly
|
||||||
if self.__IO__['inPlace']: outname = name + self.tmpext # transparently create tmp file
|
if self.__IO__['inPlace']: outname = name + self.tmpext # transparently create tmp file
|
||||||
self.__IO__['in'] = (open( name,'r') if os.access( name, os.R_OK) else None) if name else sys.stdin
|
try:
|
||||||
self.__IO__['out'] = (open(outname,'w') if (not os.path.isfile(outname) \
|
self.__IO__['in'] = (open( name,'r') if os.access( name, os.R_OK) else None) if name else sys.stdin
|
||||||
or os.access(outname, os.W_OK)) \
|
except TypeError:
|
||||||
and (not self.__IO__['inPlace'] \
|
self.__IO__['in'] = name
|
||||||
or os.access(name, os.W_OK)) else None) if outname else sys.stdout
|
|
||||||
|
try:
|
||||||
|
self.__IO__['out'] = (open(outname,'w') if (not os.path.isfile(outname) \
|
||||||
|
or os.access(outname, os.W_OK)) \
|
||||||
|
and (not self.__IO__['inPlace'] \
|
||||||
|
or os.access(name, os.W_OK)) else None) if outname else sys.stdout
|
||||||
|
except TypeError:
|
||||||
|
self.__IO__['out'] = outname
|
||||||
|
|
||||||
self.info = []
|
self.info = []
|
||||||
self.labels = []
|
self.labels = []
|
||||||
|
|
|
@ -92,7 +92,7 @@ class myThread (threading.Thread):
|
||||||
perturbedSeedsVFile = StringIO()
|
perturbedSeedsVFile = StringIO()
|
||||||
myBestSeedsVFile.reset()
|
myBestSeedsVFile.reset()
|
||||||
|
|
||||||
perturbedSeedsTable = damask.ASCIItable(myBestSeedsVFile,perturbedSeedsVFile,labels=True) # read current best fitting seed file and to perturbed seed file
|
perturbedSeedsTable = damask.ASCIItable(myBestSeedsVFile,perturbedSeedsVFile,labeled=True) # read current best fitting seed file and to perturbed seed file
|
||||||
perturbedSeedsTable.head_read()
|
perturbedSeedsTable.head_read()
|
||||||
perturbedSeedsTable.head_write()
|
perturbedSeedsTable.head_write()
|
||||||
outputAlive=True
|
outputAlive=True
|
||||||
|
@ -115,7 +115,7 @@ class myThread (threading.Thread):
|
||||||
' -g '+' '.join(map(str, options.grid)),streamIn=perturbedSeedsVFile)[0])
|
' -g '+' '.join(map(str, options.grid)),streamIn=perturbedSeedsVFile)[0])
|
||||||
perturbedGeomVFile.reset()
|
perturbedGeomVFile.reset()
|
||||||
#--- evaluate current seeds file ----------------------------------------------------------------------
|
#--- evaluate current seeds file ----------------------------------------------------------------------
|
||||||
perturbedGeomTable = damask.ASCIItable(perturbedGeomVFile,labels=False)
|
perturbedGeomTable = damask.ASCIItable(perturbedGeomVFile,labeled=False,readonly=True)
|
||||||
perturbedGeomTable.head_read()
|
perturbedGeomTable.head_read()
|
||||||
for i in perturbedGeomTable.info:
|
for i in perturbedGeomTable.info:
|
||||||
if i.startswith('microstructures'): myNmicrostructures = int(i.split('\t')[1])
|
if i.startswith('microstructures'): myNmicrostructures = int(i.split('\t')[1])
|
||||||
|
@ -232,19 +232,21 @@ points = float(reduce(mul,options.grid))
|
||||||
|
|
||||||
|
|
||||||
# ----------- calculate target distribution and bin edges
|
# ----------- calculate target distribution and bin edges
|
||||||
with open(os.path.splitext(os.path.basename(options.target))[0]+'.geom') as targetGeomFile:
|
targetGeomFile = os.path.splitext(os.path.basename(options.target))[0]+'.geom'
|
||||||
targetGeomTable = damask.ASCIItable(targetGeomFile,labels=False)
|
targetGeomTable = damask.ASCIItable(targetGeomFile,labeled=False,readonly=True)
|
||||||
targetGeomTable.head_read()
|
targetGeomTable.head_read()
|
||||||
for i in targetGeomTable.info:
|
|
||||||
if i.startswith('microstructures'): nMicrostructures = int(i.split()[1])
|
|
||||||
if i.startswith('grid'): targetPoints = np.array(map(float,i.split()[2:7:2])).prod()
|
|
||||||
|
|
||||||
targetGeomTable.data_readArray()
|
for i in targetGeomTable.info:
|
||||||
targetVolFrac = np.bincount(targetGeomTable.data.astype(int).ravel())[1:nMicrostructures+1]/targetPoints
|
if i.startswith('microstructures'): nMicrostructures = int(i.split()[1])
|
||||||
target=[]
|
if i.startswith('grid'): targetPoints = int(np.array(map(float,i.split()[2:7:2])).prod())
|
||||||
for i in xrange(1,nMicrostructures+1):
|
|
||||||
targetHist,targetBins = np.histogram(targetVolFrac,bins=i) #bin boundaries
|
targetGeomTable.data_readArray()
|
||||||
target.append({'histogram':targetHist,'bins':targetBins})
|
|
||||||
|
targetVolFrac = np.bincount(targetGeomTable.data.astype(int).ravel())[1:nMicrostructures+1]/targetPoints
|
||||||
|
target=[]
|
||||||
|
for i in xrange(1,nMicrostructures+1):
|
||||||
|
targetHist,targetBins = np.histogram(targetVolFrac,bins=i) #bin boundaries
|
||||||
|
target.append({'histogram':targetHist,'bins':targetBins})
|
||||||
|
|
||||||
# ----------- create initial seed file or open existing one
|
# ----------- create initial seed file or open existing one
|
||||||
bestSeedsVFile = StringIO()
|
bestSeedsVFile = StringIO()
|
||||||
|
@ -264,7 +266,7 @@ initialGeomVFile = StringIO()
|
||||||
initialGeomVFile.write(execute('geom_fromVoronoiTessellation '+
|
initialGeomVFile.write(execute('geom_fromVoronoiTessellation '+
|
||||||
' -g '+' '.join(map(str, options.grid)),bestSeedsVFile)[0])
|
' -g '+' '.join(map(str, options.grid)),bestSeedsVFile)[0])
|
||||||
initialGeomVFile.reset()
|
initialGeomVFile.reset()
|
||||||
initialGeomTable = damask.ASCIItable(initialGeomVFile,labels=False)
|
initialGeomTable = damask.ASCIItable(initialGeomVFile,labeled=False,readonly=True)
|
||||||
initialGeomTable.head_read()
|
initialGeomTable.head_read()
|
||||||
for i in initialGeomTable.info:
|
for i in initialGeomTable.info:
|
||||||
if i.startswith('microstructures'): initialMicrostructures = int(i.split('\t')[1])
|
if i.startswith('microstructures'): initialMicrostructures = int(i.split('\t')[1])
|
||||||
|
|
Loading…
Reference in New Issue