cleaning deprecated modules

This commit is contained in:
Martin Diehl 2020-03-18 17:51:47 +01:00
parent c40e607e08
commit cbe5944390
2 changed files with 22 additions and 29 deletions

View File

@ -14,9 +14,7 @@ class ASCIItable():
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def __init__(self, def __init__(self,
name = None, name,
outname = None,
buffered = False, # is ignored, only exists for compatibility reasons
labeled = True, # assume table has labels labeled = True, # assume table has labels
readonly = False, # no reading from file readonly = False, # no reading from file
): ):
@ -27,8 +25,9 @@ class ASCIItable():
'dataStart': 0, 'dataStart': 0,
} }
self.__IO__['inPlace'] = not outname and name and not readonly self.__IO__['inPlace'] = name and not readonly
if self.__IO__['inPlace']: outname = name + self.tmpext # transparently create tmp file outname = name + self.tmpext if self.__IO__['inPlace'] else None # transparently create tmp file
try: try:
self.__IO__['in'] = (open( name,'r') if os.access( name, os.R_OK) else None) if name else sys.stdin self.__IO__['in'] = (open( name,'r') if os.access( name, os.R_OK) else None) if name else sys.stdin
except TypeError: except TypeError:
@ -424,29 +423,26 @@ class ASCIItable():
return labels_missing return labels_missing
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_write(self, def data_write(self):
delimiter = '\t'):
"""Write current data array and report alive output back.""" """Write current data array and report alive output back."""
if len(self.data) == 0: return True if len(self.data) == 0: return True
if isinstance(self.data[0],list): if isinstance(self.data[0],list):
return self.output_write([delimiter.join(map(self._quote,items)) for items in self.data]) return self.output_write(['\t'.join(map(self._quote,items)) for items in self.data])
else: else:
return self.output_write( delimiter.join(map(self._quote,self.data))) return self.output_write( '\t'.join(map(self._quote,self.data)))
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_writeArray(self, def data_writeArray(self):
fmt = None,
delimiter = '\t'):
"""Write whole numpy array data.""" """Write whole numpy array data."""
for row in self.data: for row in self.data:
try: try:
output = [fmt % value for value in row] if fmt else list(map(repr,row)) output = list(map(repr,row))
except Exception: except Exception:
output = [fmt % row] if fmt else [repr(row)] output = [repr(row)]
try: try:
self.__IO__['out'].write(delimiter.join(output) + '\n') self.__IO__['out'].write('\t'.join(output) + '\n')
except Exception: except Exception:
pass pass

View File

@ -282,12 +282,10 @@ class Test():
import numpy as np import numpy as np
logging.info('\n '.join(['comparing',File1,File2])) logging.info('\n '.join(['comparing',File1,File2]))
table1 = damask.ASCIItable(name=File1,readonly=True) table = damask.Table.from_ASCII(File1)
table1.head_read() len1=len(table.comments)+2
len1=len(table1.info)+2 table = damask.Table.from_ASCII(File2)
table2 = damask.ASCIItable(name=File2,readonly=True) len2=len(table.comments)+2
table2.head_read()
len2=len(table2.info)+2
refArray = np.nan_to_num(np.genfromtxt(File1,missing_values='n/a',skip_header = len1,autostrip=True)) refArray = np.nan_to_num(np.genfromtxt(File1,missing_values='n/a',skip_header = len1,autostrip=True))
curArray = np.nan_to_num(np.genfromtxt(File2,missing_values='n/a',skip_header = len2,autostrip=True)) curArray = np.nan_to_num(np.genfromtxt(File2,missing_values='n/a',skip_header = len2,autostrip=True))
@ -445,15 +443,15 @@ class Test():
if not (isinstance(files, Iterable) and not isinstance(files, str)): # check whether list of files is requested if not (isinstance(files, Iterable) and not isinstance(files, str)): # check whether list of files is requested
files = [str(files)] files = [str(files)]
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: for table in tables:
table.head_read() table._label_flat()
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 = True) # if no column is given, read all if column is None: columns[i] = list(tables[i].data.columns) # if no column is given, read all
logging.info('comparing ASCIItables statistically') logging.info('comparing ASCIItables statistically')
for i in range(len(columns)): for i in range(len(columns)):
@ -467,9 +465,8 @@ class Test():
data = [] data = []
for table,labels in zip(tables,columns): for table,labels in zip(tables,columns):
table.data_readArray(labels) table._label_condensed()
data.append(table.data) data.append(np.hstack(list(table.get(label) for label in labels)))
table.close()
for i in range(1,len(data)): for i in range(1,len(data)):