simplified and selected better names

This commit is contained in:
Martin Diehl 2019-09-15 16:00:19 -07:00
parent c76d4d3f87
commit f6ac8c995f
3 changed files with 57 additions and 132 deletions

View File

@ -62,8 +62,8 @@ for filename in options.filenames:
results.visible['increments'] = [inc] results.visible['increments'] = [inc]
for label in options.con: for label in options.con:
for o in results.constituent_output_iter(): for o in results.iter_visible('con_physics'):
for c in results.constituent_iter(): for c in results.iter_visible('constituents'):
x = results.get_dataset_location(label) x = results.get_dataset_location(label)
if len(x) == 0: if len(x) == 0:
continue continue
@ -77,8 +77,8 @@ for filename in options.filenames:
header+=' '+label header+=' '+label
for label in options.mat: for label in options.mat:
for o in results.materialpoint_output_iter(): for o in results.iter_visible('mat_physics'):
for m in results.materialpoint_iter(): for m in results.iter_visible('materialpoints'):
x = results.get_dataset_location(label) x = results.get_dataset_location(label)
if len(x) == 0: if len(x) == 0:
continue continue

View File

@ -62,13 +62,13 @@ for filename in options.filenames:
vtk_data = [] vtk_data = []
results.visible['increments'] = [inc] results.visible['increments'] = [inc]
results.materialpoint_set([]) results.set_visible('materialpoints',False)
results.constituent_set(results.constituents) results.set_visible('constituents', True)
for label in options.con: for label in options.con:
for o in results.constituent_output_iter(): for o in results.iter_visible('con_physics'):
if o != 'generic': if o != 'generic':
for c in results.constituent_iter(): for c in results.iter_visible('constituents'):
x = results.get_dataset_location(label) x = results.get_dataset_location(label)
if len(x) == 0: if len(x) == 0:
continue continue
@ -84,15 +84,15 @@ for filename in options.filenames:
array = results.read_dataset(x,0) array = results.read_dataset(x,0)
shape = [array.shape[0],np.product(array.shape[1:])] shape = [array.shape[0],np.product(array.shape[1:])]
vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE))
vtk_data[-1].SetName('1_'+x[0].split('/')[1]+'/generic/'+label) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
rGrid.GetCellData().AddArray(vtk_data[-1]) rGrid.GetCellData().AddArray(vtk_data[-1])
results.constituent_set([]) results.set_visible('constituents', False)
results.materialpoint_set(results.materialpoints) results.set_visible('materialpoints',True)
for label in options.mat: for label in options.mat:
for o in results.materialpoint_output_iter(): for o in results.iter_visible('mat_physics'):
if o != 'generic': if o != 'generic':
for m in results.materialpoint_iter(): for m in results.iter_visible('materialpoints'):
x = results.get_dataset_location(label) x = results.get_dataset_location(label)
if len(x) == 0: if len(x) == 0:
continue continue
@ -108,7 +108,7 @@ for filename in options.filenames:
array = results.read_dataset(x,0) array = results.read_dataset(x,0)
shape = [array.shape[0],np.product(array.shape[1:])] shape = [array.shape[0],np.product(array.shape[1:])]
vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE)) vtk_data.append(numpy_support.numpy_to_vtk(num_array=array.reshape(shape),deep=True,array_type= vtk.VTK_DOUBLE))
vtk_data[-1].SetName('1_'+x[0].split('/')[1]+'/generic/'+label) vtk_data[-1].SetName('1_'+x[0].split('/',1)[1])
rGrid.GetCellData().AddArray(vtk_data[-1]) rGrid.GetCellData().AddArray(vtk_data[-1])
if results.structured: if results.structured:

View File

@ -68,61 +68,38 @@ class DADF5():
self.filename = filename self.filename = filename
def __visible_set(self,output,t):
def __manage_visible(self,datasets,what,action):
"""Sets visible.""" """Sets visible."""
# allow True/False and string arguments # allow True/False and string arguments
if output is True: if datasets is True:
output = ['*'] datasets = ['*']
elif output is False: elif datasets is False:
output = [] datasets = []
choice = [output] if isinstance(output,str) else output choice = [datasets] if isinstance(datasets,str) else datasets
valid = [e for e_ in [glob.fnmatch.filter(getattr(self,t),s) for s in choice] for e in e_] valid = [e for e_ in [glob.fnmatch.filter(getattr(self,what) ,s) for s in choice] for e in e_]
existing = set(self.visible[what])
self.visible[t] = valid if action == 'set':
self.visible[what] = valid
elif action == 'add':
self.visible[what] = list(existing.union(valid))
elif action == 'del':
self.visible[what] = list(existing.difference_update(valid))
def __visible_add(self,output,t): def iter_visible(self,what):
"""Adds to visible.""" datasets = self.visible[what]
# allow True/False and string arguments last_datasets = datasets.copy()
if output is True: for dataset in datasets:
output = ['*'] if last_datasets != self.visible[what]:
elif output is False: self.__manage_visible(datasets,what,'set')
output = []
choice = [output] if isinstance(output,str) else output
existing = set(self.visible[t])
valid = [e for e_ in [glob.fnmatch.filter(getattr(self,t),s) for s in choice] for e in e_]
self.visible[t] = list(existing.union(valid))
def __visible_del(self,output,t):
"""Deletes from visible."""
# allow True/False and string arguments
if output is True:
output = ['*']
elif output is False:
output = []
choice = [output] if isinstance(output,str) else output
existing = set(self.visible[t])
valid = [e for e_ in [glob.fnmatch.filter(existing,s) for s in choice] for e in e_]
self.visible[t] = list(existing.difference_update(valid))
def __visible_iter(self,t):
a = self.visible[t]
last_a = a.copy()
for i in a:
if last_a != self.visible[t]:
self.__visible_set(a,t)
raise Exception raise Exception
self.__visible_set(i,t) self.__manage_visible(dataset,what,'set')
last_a = self.visible[t] last_datasets = self.visible[what]
yield i yield dataset
self.__visible_set(a,t) self.__manage_visible(datasets,what,'set')
# ToDo: store increments, select icrements (trivial), position, and time # ToDo: store increments, select icrements (trivial), position, and time
@ -141,70 +118,18 @@ class DADF5():
for t in self.time_information: for t in self.time_information:
if start<= t['inc']< end: if start<= t['inc']< end:
print(t) print(t)
def constituent_output_iter(self):
return self.__visible_iter('con_physics')
def constituent_output_set(self,output):
self.__visible_set(output,'con_physics')
def constituent_output_add(self,output):
self.__visible_add(output,'con_physics')
def constituent_output_del(self,output):
self.__visible_del(output,'con_physics')
def set_visible(self,what,datasets):
def materialpoint_output_iter(self): self.__manage_visible(datasets,what,'set')
return self.__visible_iter('mat_physics')
def materialpoint_output_set(self,output):
self.__visible_set(output,'mat_physics')
def materialpoint_output_add(self,output): def add_visible(self,what,datasets):
self.__visible_add(output,'mat_physics') self.__manage_visible(datasets,what,'add')
def materialpoint_output_del(self,output): def del_visible(self,what,datasets):
self.__visible_del(output,'mat_physics') self.__manage_visible(datasets,what,'del')
def constituent_iter(self):
return self.__visible_iter('constituents')
def constituent_set(self,output):
self.__visible_set(output,'constituents')
def constituent_add(self,output):
self.__visible_add(output,'constituents')
def constituent_del(self,output):
self.__visible_del(output,'constituents')
def materialpoint_iter(self):
return self.__visible_iter('materialpoints')
def materialpoint_set(self,output):
self.__visible_set(output,'materialpoints')
def materialpoint_add(self,output):
self.__visible_add(output,'materialpoints')
def materialpoint_del(self,output):
self.__visible_del(output,'materialpoints')
def groups_with_datasets(self,datasets): def groups_with_datasets(self,datasets):
@ -240,16 +165,16 @@ class DADF5():
with h5py.File(self.filename,'r') as f: with h5py.File(self.filename,'r') as f:
for i in self.visible['increments']: for i in self.visible['increments']:
group_inc = 'inc{:05}'.format(i['inc']) #ToDo: Merge path only once at the end '/'.join(listE) group_inc = 'inc{:05}'.format(i['inc']) #ToDo: Merge path only once at the end '/'.join(listE)
for c in self.constituent_iter(): for c in self.iter_visible('constituents'):
for t in self.constituent_output_iter(): for t in self.iter_visible('con_physics'):
group = '/'.join([group_inc,'constituent',c,t]) group = '/'.join([group_inc,'constituent',c,t])
if sets is True: if sets is True:
groups.append(group) groups.append(group)
else: else:
match = [e for e_ in [glob.fnmatch.filter(f[group].keys(),s) for s in sets] for e in e_] match = [e for e_ in [glob.fnmatch.filter(f[group].keys(),s) for s in sets] for e in e_]
if len(set(match)) == len(sets) : groups.append(group) if len(set(match)) == len(sets) : groups.append(group)
for m in self.materialpoint_iter(): for m in self.iter_visible('materialpoints'):
for t in self.materialpoint_output_iter(): for t in self.iter_visible('mat_physics'):
group = '/'.join([group_inc,'materialpoint',m,t]) group = '/'.join([group_inc,'materialpoint',m,t])
if sets is True: if sets is True:
groups.append(group) groups.append(group)
@ -263,10 +188,10 @@ class DADF5():
"""Shows information on all active datasets in the file.""" """Shows information on all active datasets in the file."""
with h5py.File(self.filename,'r') as f: with h5py.File(self.filename,'r') as f:
group_inc = 'inc{:05}'.format(self.visible['increments'][0]['inc']) #ToDo: Merge path only once at the end '/'.join(listE) group_inc = 'inc{:05}'.format(self.visible['increments'][0]['inc']) #ToDo: Merge path only once at the end '/'.join(listE)
for c in self.visible['constituents']: for c in self.iter_visible('constituents'):
print('\n'+c) print('\n'+c)
group_constituent = group_inc+'/constituent/'+c group_constituent = group_inc+'/constituent/'+c
for t in self.visible['con_physics']: for t in self.iter_visible('con_physics'):
print(' {}'.format(t)) print(' {}'.format(t))
group_output_types = group_constituent+'/'+t group_output_types = group_constituent+'/'+t
try: try:
@ -274,9 +199,9 @@ class DADF5():
print(' {} ({})'.format(x,f[group_output_types+'/'+x].attrs['Description'].decode())) print(' {} ({})'.format(x,f[group_output_types+'/'+x].attrs['Description'].decode()))
except KeyError: except KeyError:
pass pass
for m in self.visible['materialpoints']: for m in self.iter_visible('materialpoints'):
group_materialpoint = group_inc+'/materialpoint/'+m group_materialpoint = group_inc+'/materialpoint/'+m
for t in self.visible['mat_physics']: for t in self.iter_visible('mat_physics'):
print(' {}'.format(t)) print(' {}'.format(t))
group_output_types = group_materialpoint+'/'+t group_output_types = group_materialpoint+'/'+t
try: try:
@ -293,8 +218,8 @@ class DADF5():
for i in self.visible['increments']: for i in self.visible['increments']:
group_inc = 'inc{:05}'.format(i['inc']) group_inc = 'inc{:05}'.format(i['inc'])
for c in self.visible['constituents']: for c in self.iter_visible('constituents'):
for t in self.visible['con_physics']: for t in self.iter_visible('con_physics'):
try: try:
p = '/'.join([group_inc,'constituent',c,t,label]) p = '/'.join([group_inc,'constituent',c,t,label])
f[p] f[p]
@ -302,8 +227,8 @@ class DADF5():
except KeyError as e: except KeyError as e:
print('unable to locate constituents dataset: '+ str(e)) print('unable to locate constituents dataset: '+ str(e))
for m in self.visible['materialpoints']: for m in self.iter_visible('materialpoints'):
for t in self.visible['mat_physics']: for t in self.iter_visible('mat_physics'):
try: try:
p = '/'.join([group_inc,'materialpoint',m,t,label]) p = '/'.join([group_inc,'materialpoint',m,t,label])
f[p] f[p]