works also for arrays ...
This commit is contained in:
parent
2ad86e4202
commit
20a06840b0
|
@ -34,7 +34,7 @@ class Geom:
|
|||
self.set_origin(origin)
|
||||
self.set_homogenization(homogenization)
|
||||
self.set_comments(comments)
|
||||
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
"""Basic information on geometry definition."""
|
||||
|
@ -69,7 +69,7 @@ class Geom:
|
|||
origin_old = self.get_origin()
|
||||
unique_old = len(np.unique(self.microstructure))
|
||||
max_old = np.nanmax(self.microstructure)
|
||||
|
||||
|
||||
if size is not None and rescale:
|
||||
raise ValueError('Either set size explicitly or rescale automatically')
|
||||
|
||||
|
@ -107,7 +107,7 @@ class Geom:
|
|||
if max_old != np.nanmax(self.microstructure):
|
||||
message[-1] = util.delete(message[-1])
|
||||
message.append(util.emph('max microstructure: {}'.format(np.nanmax(self.microstructure))))
|
||||
|
||||
|
||||
return util.return_message(message)
|
||||
|
||||
|
||||
|
@ -123,7 +123,7 @@ class Geom:
|
|||
"""
|
||||
self.comments = []
|
||||
self.add_comments(comments)
|
||||
|
||||
|
||||
|
||||
def add_comments(self,comments):
|
||||
"""
|
||||
|
@ -259,7 +259,7 @@ class Geom:
|
|||
header.append('origin x {} y {} z {}'.format(*self.get_origin()))
|
||||
header.append('homogenization {}'.format(self.get_homogenization()))
|
||||
return header
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_file(fname):
|
||||
|
@ -285,7 +285,7 @@ class Geom:
|
|||
if not keyword.startswith('head') or header_length < 3:
|
||||
raise TypeError('Header length information missing or invalid')
|
||||
|
||||
comments = []
|
||||
comments = []
|
||||
for i,line in enumerate(content[:header_length]):
|
||||
items = line.lower().strip().split()
|
||||
key = items[0] if items else ''
|
||||
|
@ -314,14 +314,14 @@ class Geom:
|
|||
else: items = list(map(float,items))
|
||||
microstructure[i:i+len(items)] = items
|
||||
i += len(items)
|
||||
|
||||
|
||||
if i != grid.prod():
|
||||
raise TypeError('Invalid file: expected {} entries, found {}'.format(grid.prod(),i))
|
||||
|
||||
|
||||
microstructure = microstructure.reshape(grid,order='F')
|
||||
if not np.any(np.mod(microstructure.flatten(),1) != 0.0): # no float present
|
||||
microstructure = microstructure.astype('int')
|
||||
|
||||
|
||||
return Geom(microstructure.reshape(grid),size,origin,homogenization,comments)
|
||||
|
||||
|
||||
|
@ -339,7 +339,7 @@ class Geom:
|
|||
"""
|
||||
header = self.get_header()
|
||||
grid = self.get_grid()
|
||||
|
||||
|
||||
if pack is None:
|
||||
plain = grid.prod()/np.unique(self.microstructure).size < 250
|
||||
else:
|
||||
|
@ -390,7 +390,7 @@ class Geom:
|
|||
elif compressType == 'of':
|
||||
f.write('{} of {}\n'.format(reps,former))
|
||||
|
||||
|
||||
|
||||
def to_vtk(self,fname=None):
|
||||
"""
|
||||
Generates vtk file.
|
||||
|
@ -409,7 +409,7 @@ class Geom:
|
|||
else:
|
||||
sys.stdout.write(v.__repr__())
|
||||
|
||||
|
||||
|
||||
def show(self):
|
||||
"""Show raw content (as in file)."""
|
||||
f=StringIO()
|
||||
|
@ -445,7 +445,7 @@ class Geom:
|
|||
ms = np.concatenate([ms,ms[:,limits[0]:limits[1]:-1,:]],1)
|
||||
if 'x' in directions:
|
||||
ms = np.concatenate([ms,ms[limits[0]:limits[1]:-1,:,:]],0)
|
||||
|
||||
|
||||
#self.add_comments('geom.py:mirror v{}'.format(version)
|
||||
return self.update(ms,rescale=True)
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class Table:
|
|||
|
||||
|
||||
def _add_comment(self,label,shape,info):
|
||||
if info:
|
||||
if info is not None:
|
||||
c = '{}{}: {}'.format(label,' '+str(shape) if np.prod(shape,dtype=int) > 1 else '',info)
|
||||
self.comments.append(c)
|
||||
|
||||
|
@ -251,7 +251,7 @@ class Table:
|
|||
|
||||
"""
|
||||
self.data.rename(columns={label_old:label_new},inplace=True)
|
||||
c = '{} => {}{}'.format(label_old,label_new,'' if not info else ': {}'.format(info))
|
||||
c = '{} => {}{}'.format(label_old,label_new,'' if info is None else ': {}'.format(info))
|
||||
self.comments.append(c)
|
||||
self.shapes = {(label if label != label_old else label_new):self.shapes[label] for label in self.shapes}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ class VTK:
|
|||
reader = vtk.vtkGenericDataObjectReader()
|
||||
reader.SetFileName(fname)
|
||||
reader.Update()
|
||||
if not dataset_type:
|
||||
if dataset_type is None:
|
||||
raise TypeError('Dataset type for *.vtk file not given.')
|
||||
elif dataset_type.lower().endswith('rectilineargrid'):
|
||||
geom = reader.GetRectilinearGridOutput()
|
||||
|
@ -196,7 +196,7 @@ class VTK:
|
|||
|
||||
if isinstance(data,np.ndarray):
|
||||
d = np_to_vtk(num_array=data.reshape(data.shape[0],-1),deep=True)
|
||||
if not label:
|
||||
if label is None:
|
||||
raise ValueError('No label defined for numpy.ndarray')
|
||||
d.SetName(label)
|
||||
if data.shape[0] == N_cells:
|
||||
|
|
Loading…
Reference in New Issue