simplified

This commit is contained in:
Martin Diehl 2021-04-04 18:32:17 +02:00
parent a962777d24
commit d78e0085fc
2 changed files with 15 additions and 43 deletions

View File

@ -365,35 +365,6 @@ class Result:
raise PermissionError('Rename operation not permitted') raise PermissionError('Rename operation not permitted')
def groups_with_datasets(self,datasets):
"""
Return groups that contain all requested datasets.
Only groups within
- inc*/phase/*/
- inc*/homogenization/*/
- inc*/geometry/
are considered as they contain user-relevant data.
Single strings will be treated as list with one entry.
Parameters
----------
datasets : iterable or str or bool
"""
groups = []
with h5py.File(self.fname,'r') as f:
for inc in self.visible['increments']:
for ty in ['phases','homogenizations']:
for label in self.visible[ty]:
for field in self.visible['fields']:
group = '/'.join([inc,ty[:-1],label,field])
if set(datasets).issubset(f[group].keys()): groups.append(group)
return groups
def list_data(self): def list_data(self):
"""Return information on all active datasets in the file.""" """Return information on all active datasets in the file."""
# compatibility hack # compatibility hack
@ -1089,7 +1060,15 @@ class Result:
pool = mp.Pool(int(os.environ.get('OMP_NUM_THREADS',1))) pool = mp.Pool(int(os.environ.get('OMP_NUM_THREADS',1)))
lock = mp.Manager().Lock() lock = mp.Manager().Lock()
groups = self.groups_with_datasets(datasets.values()) groups = []
with h5py.File(self.fname,'r') as f:
for inc in self.visible['increments']:
for ty in ['phases','homogenizations']:
for label in self.visible[ty]:
for field in self.visible['fields']:
group = '/'.join([inc,ty[:-1],label,field])
if set(datasets.values()).issubset(f[group].keys()): groups.append(group)
if len(groups) == 0: if len(groups) == 0:
print('No matching dataset found, no data was added.') print('No matching dataset found, no data was added.')
return return

View File

@ -284,13 +284,9 @@ class TestResult:
default.view('times',default.times_in_range(0,np.inf)[-1]) default.view('times',default.times_in_range(0,np.inf)[-1])
default.add_stress_Cauchy() default.add_stress_Cauchy()
loc = default.get_dataset_location('sigma')
with h5py.File(default.fname,'r') as f: with h5py.File(default.fname,'r') as f:
# h5py3 compatibility created_first = default.place('sigma').dtype.metadata['created']
try:
created_first = f[loc[0]].attrs['created'].decode()
except AttributeError:
created_first = f[loc[0]].attrs['created']
created_first = datetime.strptime(created_first,'%Y-%m-%d %H:%M:%S%z') created_first = datetime.strptime(created_first,'%Y-%m-%d %H:%M:%S%z')
if overwrite == 'on': if overwrite == 'on':
@ -304,16 +300,13 @@ class TestResult:
except ValueError: except ValueError:
pass pass
with h5py.File(default.fname,'r') as f: with h5py.File(default.fname,'r') as f:
# h5py3 compatibility created_second = default.place('sigma').dtype.metadata['created']
try:
created_second = f[loc[0]].attrs['created'].decode()
except AttributeError:
created_second = f[loc[0]].attrs['created']
created_second = datetime.strptime(created_second,'%Y-%m-%d %H:%M:%S%z') created_second = datetime.strptime(created_second,'%Y-%m-%d %H:%M:%S%z')
if overwrite == 'on': if overwrite == 'on':
assert created_first < created_second and np.allclose(default.read_dataset(loc),311.) assert created_first < created_second and np.allclose(default.place('sigma'),311.)
else: else:
assert created_first == created_second and not np.allclose(default.read_dataset(loc),311.) assert created_first == created_second and not np.allclose(default.place('sigma'),311.)
@pytest.mark.parametrize('allowed',['off','on']) @pytest.mark.parametrize('allowed',['off','on'])
def test_rename(self,default,allowed): def test_rename(self,default,allowed):