From d78e0085fc6021622c166ed099c7e62de9603b71 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 4 Apr 2021 18:32:17 +0200 Subject: [PATCH] simplified --- python/damask/_result.py | 39 +++++++++---------------------------- python/tests/test_Result.py | 19 ++++++------------ 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/python/damask/_result.py b/python/damask/_result.py index 12ac73901..c79dd0558 100644 --- a/python/damask/_result.py +++ b/python/damask/_result.py @@ -365,35 +365,6 @@ class Result: 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): """Return information on all active datasets in the file.""" # compatibility hack @@ -1089,7 +1060,15 @@ class Result: pool = mp.Pool(int(os.environ.get('OMP_NUM_THREADS',1))) 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: print('No matching dataset found, no data was added.') return diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index 94f0d6f1a..7fd345012 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -284,13 +284,9 @@ class TestResult: default.view('times',default.times_in_range(0,np.inf)[-1]) default.add_stress_Cauchy() - loc = default.get_dataset_location('sigma') with h5py.File(default.fname,'r') as f: - # h5py3 compatibility - try: - created_first = f[loc[0]].attrs['created'].decode() - except AttributeError: - created_first = f[loc[0]].attrs['created'] + created_first = default.place('sigma').dtype.metadata['created'] + created_first = datetime.strptime(created_first,'%Y-%m-%d %H:%M:%S%z') if overwrite == 'on': @@ -304,16 +300,13 @@ class TestResult: except ValueError: pass with h5py.File(default.fname,'r') as f: - # h5py3 compatibility - try: - created_second = f[loc[0]].attrs['created'].decode() - except AttributeError: - created_second = f[loc[0]].attrs['created'] + created_second = default.place('sigma').dtype.metadata['created'] created_second = datetime.strptime(created_second,'%Y-%m-%d %H:%M:%S%z') + 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: - 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']) def test_rename(self,default,allowed):