migrating to new table class

This commit is contained in:
Martin Diehl 2020-03-18 23:43:56 +01:00
parent cbe5944390
commit f7a6ac4a0e
1 changed files with 22 additions and 23 deletions

View File

@ -1,11 +1,16 @@
import os,sys,shutil import os
import logging,logging.config import sys
import damask import shutil
import numpy as np import logging
import logging.config
from collections.abc import Iterable from collections.abc import Iterable
from optparse import OptionParser from optparse import OptionParser
class Test(): import numpy as np
import damask
class Test:
""" """
General class for testing. General class for testing.
@ -494,15 +499,13 @@ class Test():
if len(files) < 2: return True # single table is always close to itself... if len(files) < 2: return True # single table is always close to itself...
tables = [damask.ASCIItable(name = filename,readonly = True) for filename in files] tables = [damask.Table.from_ASCII(filename) for filename in files]
for table in tables:
table.head_read()
columns += [columns[0]]*(len(files)-len(columns)) # extend to same length as files columns += [columns[0]]*(len(files)-len(columns)) # extend to same length as files
columns = columns[:len(files)] # truncate to same length as files columns = columns[:len(files)] # truncate to same length as files
for i,column in enumerate(columns): for i,column in enumerate(columns):
if column is None: columns[i] = tables[i].labels(raw = False) # if no column is given, use all if column is None: columns[i] = list(tables[i].shapes.keys()) # if no column is given, use all
logging.info('comparing ASCIItables') logging.info('comparing ASCIItables')
for i in range(len(columns)): for i in range(len(columns)):
@ -512,22 +515,20 @@ class Test():
) )
logging.info(files[i]+': '+','.join(columns[i])) logging.info(files[i]+': '+','.join(columns[i]))
dimensions = tables[0].label_dimension(columns[0]) # width of each requested column dimensions = [np.prod(tables[0].shapes[c]) for c in columns[0]] # width of each requested column
maximum = np.zeros_like(columns[0],dtype=float) # one magnitude per column entry maximum = np.zeros_like(columns[0],dtype=float) # one magnitude per column entry
data = [] # list of feature table extracted from each file (ASCII table) data = [] # list of feature table extracted from each file (ASCII table)
for i,(table,labels) in enumerate(zip(tables,columns)): for i,(table,labels) in enumerate(zip(tables,columns)):
if np.any(dimensions != table.label_dimension(labels)): # check data object consistency if np.any(dimensions != [np.prod(table.shapes[c]) for c in labels]): # check data object consistency
logging.critical('Table {} differs in data layout.'.format(files[i])) logging.critical('Table {} differs in data layout.'.format(files[i]))
return False return False
table.data_readArray(labels) # read data, ... data.append(np.hstack(list(table.get(label) for label in labels))) # store
data.append(table.data) # ... store, ...
table.close() # ... close
for j,label in enumerate(labels): # iterate over object labels for j,label in enumerate(labels): # iterate over object labels
maximum[j] = np.maximum( maximum[j] = np.maximum(
maximum[j], maximum[j],
np.amax(np.linalg.norm(table.data[:,table.label_indexrange(label)], np.amax(np.linalg.norm(table.get(label),
axis=1)) axis=1))
) # find maximum Euclidean norm across rows ) # find maximum Euclidean norm across rows
@ -549,8 +550,6 @@ class Test():
logging.info('data : {}'.format(np.absolute(data[1][j])[culprits])) logging.info('data : {}'.format(np.absolute(data[1][j])[culprits]))
logging.info('deviation: {}'.format(np.absolute(data[0][j]-data[1][j])[goodguys])) logging.info('deviation: {}'.format(np.absolute(data[0][j]-data[1][j])[goodguys]))
logging.info('data : {}'.format(np.absolute(data[1][j])[goodguys])) logging.info('data : {}'.format(np.absolute(data[1][j])[goodguys]))
# for ok,valA,valB in zip(allclose,data[0],data[1]):
# logging.debug('{}:\n{}\n{}'.format(ok,valA,valB))
allclose = True # start optimistic allclose = True # start optimistic
for i in range(1,len(data)): for i in range(1,len(data)):