better name
This commit is contained in:
parent
a7d998dd48
commit
d76543f759
|
@ -80,12 +80,12 @@ class Result:
|
||||||
self.out_type_ho += f['/'.join([self.increments[0],'homogenization',m])].keys()
|
self.out_type_ho += f['/'.join([self.increments[0],'homogenization',m])].keys()
|
||||||
self.out_type_ho = list(set(self.out_type_ho)) # make unique
|
self.out_type_ho = list(set(self.out_type_ho)) # make unique
|
||||||
|
|
||||||
self.selection = {'increments': self.increments,
|
self.visible = {'increments': self.increments,
|
||||||
'phases': self.phases,
|
'phases': self.phases,
|
||||||
'homogenizations': self.homogenizations,
|
'homogenizations': self.homogenizations,
|
||||||
'out_type_ph': self.out_type_ph,
|
'out_type_ph': self.out_type_ph,
|
||||||
'out_type_ho': self.out_type_ho
|
'out_type_ho': self.out_type_ho
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fname = Path(fname).absolute()
|
self.fname = Path(fname).absolute()
|
||||||
|
|
||||||
|
@ -94,23 +94,23 @@ class Result:
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""Show summary of file content."""
|
"""Show summary of file content."""
|
||||||
all_selected_increments = self.selection['increments']
|
visible_increments = self.visible['increments']
|
||||||
|
|
||||||
self.pick('increments',all_selected_increments[0:1])
|
self.view('increments',visible_increments[0:1])
|
||||||
first = self.list_data()
|
first = self.list_data()
|
||||||
|
|
||||||
self.pick('increments',all_selected_increments[-1:])
|
self.view('increments',visible_increments[-1:])
|
||||||
last = '' if len(all_selected_increments) < 2 else self.list_data()
|
last = '' if len(visible_increments) < 2 else self.list_data()
|
||||||
|
|
||||||
self.pick('increments',all_selected_increments)
|
self.view('increments',visible_increments)
|
||||||
|
|
||||||
in_between = '' if len(all_selected_increments) < 3 else \
|
in_between = '' if len(visible_increments) < 3 else \
|
||||||
''.join([f'\n{inc}\n ...\n' for inc in all_selected_increments[1:-2]])
|
''.join([f'\n{inc}\n ...\n' for inc in visible_increments[1:-2]])
|
||||||
|
|
||||||
return util.srepr(first + in_between + last)
|
return util.srepr(first + in_between + last)
|
||||||
|
|
||||||
|
|
||||||
def _manage_selection(self,action,what,datasets):
|
def _manage_view(self,action,what,datasets):
|
||||||
"""
|
"""
|
||||||
Manages the visibility of the groups.
|
Manages the visibility of the groups.
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class Result:
|
||||||
action : str
|
action : str
|
||||||
Select from 'set', 'add', and 'del'.
|
Select from 'set', 'add', and 'del'.
|
||||||
what : str
|
what : str
|
||||||
Attribute to change (must be from self.selection).
|
Attribute to change (must be in self.visible).
|
||||||
datasets : list of str or bool
|
datasets : list of str or bool
|
||||||
Name of datasets as list, supports ? and * wildcards.
|
Name of datasets as list, supports ? and * wildcards.
|
||||||
True is equivalent to [*], False is equivalent to []
|
True is equivalent to [*], False is equivalent to []
|
||||||
|
@ -156,18 +156,18 @@ class Result:
|
||||||
choice.append(self.increments[idx+1])
|
choice.append(self.increments[idx+1])
|
||||||
|
|
||||||
valid = [e for e_ in [glob.fnmatch.filter(getattr(self,what),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.selection[what])
|
existing = set(self.visible[what])
|
||||||
|
|
||||||
if action == 'set':
|
if action == 'set':
|
||||||
self.selection[what] = valid
|
self.visible[what] = valid
|
||||||
elif action == 'add':
|
elif action == 'add':
|
||||||
add = existing.union(valid)
|
add = existing.union(valid)
|
||||||
add_sorted = sorted(add, key=natural_sort)
|
add_sorted = sorted(add, key=natural_sort)
|
||||||
self.selection[what] = add_sorted
|
self.visible[what] = add_sorted
|
||||||
elif action == 'del':
|
elif action == 'del':
|
||||||
diff = existing.difference(valid)
|
diff = existing.difference(valid)
|
||||||
diff_sorted = sorted(diff, key=natural_sort)
|
diff_sorted = sorted(diff, key=natural_sort)
|
||||||
self.selection[what] = diff_sorted
|
self.visible[what] = diff_sorted
|
||||||
|
|
||||||
|
|
||||||
def _get_attribute(self,path,attr):
|
def _get_attribute(self,path,attr):
|
||||||
|
@ -245,72 +245,72 @@ class Result:
|
||||||
|
|
||||||
def iterate(self,what):
|
def iterate(self,what):
|
||||||
"""
|
"""
|
||||||
Iterate over selection items by setting each one selected.
|
Iterate over visible items and view them independently.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
what : str
|
what : str
|
||||||
Attribute to change (must be from self.selection).
|
Attribute to change (must be from self.visible).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
datasets = self.selection[what]
|
datasets = self.visible[what]
|
||||||
last_selection = datasets.copy()
|
last_view = datasets.copy()
|
||||||
for dataset in datasets:
|
for dataset in datasets:
|
||||||
if last_selection != self.selection[what]:
|
if last_view != self.visible[what]:
|
||||||
self._manage_selection('set',what,datasets)
|
self._manage_view('set',what,datasets)
|
||||||
raise Exception
|
raise Exception
|
||||||
self._manage_selection('set',what,dataset)
|
self._manage_view('set',what,dataset)
|
||||||
last_selection = self.selection[what]
|
last_view = self.visible[what]
|
||||||
yield dataset
|
yield dataset
|
||||||
self._manage_selection('set',what,datasets)
|
self._manage_view('set',what,datasets)
|
||||||
|
|
||||||
|
|
||||||
def pick(self,what,datasets):
|
def view(self,what,datasets):
|
||||||
"""
|
"""
|
||||||
Set selection.
|
Set view.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
what : str
|
what : str
|
||||||
attribute to change (must be from self.selection)
|
attribute to change (must be from self.visible)
|
||||||
datasets : list of str or bool
|
datasets : list of str or bool
|
||||||
name of datasets as list, supports ? and * wildcards.
|
name of datasets as list, supports ? and * wildcards.
|
||||||
True is equivalent to [*], False is equivalent to []
|
True is equivalent to [*], False is equivalent to []
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._manage_selection('set',what,datasets)
|
self._manage_view('set',what,datasets)
|
||||||
|
|
||||||
|
|
||||||
def pick_more(self,what,datasets):
|
def view_more(self,what,datasets):
|
||||||
"""
|
"""
|
||||||
Add to selection.
|
Add to view.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
what : str
|
what : str
|
||||||
attribute to change (must be from self.selection)
|
attribute to change (must be from self.visible)
|
||||||
datasets : list of str or bool
|
datasets : list of str or bool
|
||||||
name of datasets as list, supports ? and * wildcards.
|
name of datasets as list, supports ? and * wildcards.
|
||||||
True is equivalent to [*], False is equivalent to []
|
True is equivalent to [*], False is equivalent to []
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._manage_selection('add',what,datasets)
|
self._manage_view('add',what,datasets)
|
||||||
|
|
||||||
|
|
||||||
def pick_less(self,what,datasets):
|
def view_less(self,what,datasets):
|
||||||
"""
|
"""
|
||||||
Delete from selection.
|
Delete from view.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
what : str
|
what : str
|
||||||
attribute to change (must be from self.selection)
|
attribute to change (must be from self.visible)
|
||||||
datasets : list of str or bool
|
datasets : list of str or bool
|
||||||
name of datasets as list, supports ? and * wildcards.
|
name of datasets as list, supports ? and * wildcards.
|
||||||
True is equivalent to [*], False is equivalent to []
|
True is equivalent to [*], False is equivalent to []
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._manage_selection('del',what,datasets)
|
self._manage_view('del',what,datasets)
|
||||||
|
|
||||||
|
|
||||||
def rename(self,name_old,name_new):
|
def rename(self,name_old,name_new):
|
||||||
|
@ -1189,8 +1189,8 @@ class Result:
|
||||||
"""
|
"""
|
||||||
Write XDMF file to directly visualize data in DADF5 file.
|
Write XDMF file to directly visualize data in DADF5 file.
|
||||||
|
|
||||||
This works only for scalar, 3-vector and 3x3-tensor data.
|
The view is not taken into account, i.e. the content of the
|
||||||
Selection is not taken into account.
|
whole file will be included.
|
||||||
"""
|
"""
|
||||||
if self.N_constituents != 1 or len(self.phases) != 1 or not self.structured:
|
if self.N_constituents != 1 or len(self.phases) != 1 or not self.structured:
|
||||||
raise TypeError('XDMF output requires homogeneous grid')
|
raise TypeError('XDMF output requires homogeneous grid')
|
||||||
|
@ -1319,10 +1319,10 @@ class Result:
|
||||||
|
|
||||||
N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][3:])))))+1
|
N_digits = int(np.floor(np.log10(max(1,int(self.increments[-1][3:])))))+1
|
||||||
|
|
||||||
for inc in util.show_progress(self.iterate('increments'),len(self.selection['increments'])):
|
for inc in util.show_progress(self.iterate('increments'),len(self.visible['increments'])):
|
||||||
|
|
||||||
picked_backup_ho = self.selection['homogenizations'].copy()
|
viewed_backup_ho = self.visible['homogenizations'].copy()
|
||||||
self.pick('homogenizations',False)
|
self.view('homogenizations',False)
|
||||||
for label in (labels if isinstance(labels,list) else [labels]):
|
for label in (labels if isinstance(labels,list) else [labels]):
|
||||||
for o in self.iterate('out_type_ph'):
|
for o in self.iterate('out_type_ph'):
|
||||||
for c in range(self.N_constituents):
|
for c in range(self.N_constituents):
|
||||||
|
@ -1342,10 +1342,10 @@ class Result:
|
||||||
ph_name = re.compile(r'(?<=(phase\/))(.*?)(?=(mechanics))') # identify phase name
|
ph_name = re.compile(r'(?<=(phase\/))(.*?)(?=(mechanics))') # identify phase name
|
||||||
dset_name = prefix+re.sub(ph_name,r'',paths[0].split('/',1)[1]) # remove phase name
|
dset_name = prefix+re.sub(ph_name,r'',paths[0].split('/',1)[1]) # remove phase name
|
||||||
v.add(array,dset_name+f' / {self._get_attribute(paths[0],"Unit")}')
|
v.add(array,dset_name+f' / {self._get_attribute(paths[0],"Unit")}')
|
||||||
self.pick('homogenizations',picked_backup_ho)
|
self.view('homogenizations',viewed_backup_ho)
|
||||||
|
|
||||||
picked_backup_ph = self.selection['phases'].copy()
|
viewed_backup_ph = self.visible['phases'].copy()
|
||||||
self.pick('phases',False)
|
self.view('phases',False)
|
||||||
for label in (labels if isinstance(labels,list) else [labels]):
|
for label in (labels if isinstance(labels,list) else [labels]):
|
||||||
for _ in self.iterate('out_type_ho'):
|
for _ in self.iterate('out_type_ho'):
|
||||||
paths = self.get_dataset_location(label)
|
paths = self.get_dataset_location(label)
|
||||||
|
@ -1353,7 +1353,7 @@ class Result:
|
||||||
continue
|
continue
|
||||||
array = self.read_dataset(paths)
|
array = self.read_dataset(paths)
|
||||||
v.add(array,paths[0].split('/',1)[1]+f' / {self._get_attribute(paths[0],"Unit")}')
|
v.add(array,paths[0].split('/',1)[1]+f' / {self._get_attribute(paths[0],"Unit")}')
|
||||||
self.pick('phases',picked_backup_ph)
|
self.view('phases',viewed_backup_ph)
|
||||||
|
|
||||||
u = self.read_dataset(self.get_dataset_location('u_n' if mode.lower() == 'cell' else 'u_p'))
|
u = self.read_dataset(self.get_dataset_location('u_n' if mode.lower() == 'cell' else 'u_p'))
|
||||||
v.add(u,'u')
|
v.add(u,'u')
|
||||||
|
|
|
@ -21,7 +21,7 @@ def default(tmp_path,ref_path):
|
||||||
fname = '12grains6x7x8_tensionY.hdf5'
|
fname = '12grains6x7x8_tensionY.hdf5'
|
||||||
shutil.copy(ref_path/fname,tmp_path)
|
shutil.copy(ref_path/fname,tmp_path)
|
||||||
f = Result(tmp_path/fname)
|
f = Result(tmp_path/fname)
|
||||||
f.pick('times',20.0)
|
f.view('times',20.0)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -43,56 +43,56 @@ class TestResult:
|
||||||
print(default)
|
print(default)
|
||||||
|
|
||||||
|
|
||||||
def test_pick_all(self,default):
|
def test_view_all(self,default):
|
||||||
default.pick('increments',True)
|
default.view('increments',True)
|
||||||
a = default.get_dataset_location('F')
|
a = default.get_dataset_location('F')
|
||||||
default.pick('increments','*')
|
default.view('increments','*')
|
||||||
b = default.get_dataset_location('F')
|
b = default.get_dataset_location('F')
|
||||||
default.pick('increments',default.incs_in_range(0,np.iinfo(int).max))
|
default.view('increments',default.incs_in_range(0,np.iinfo(int).max))
|
||||||
c = default.get_dataset_location('F')
|
c = default.get_dataset_location('F')
|
||||||
|
|
||||||
default.pick('times',True)
|
default.view('times',True)
|
||||||
d = default.get_dataset_location('F')
|
d = default.get_dataset_location('F')
|
||||||
default.pick('times','*')
|
default.view('times','*')
|
||||||
e = default.get_dataset_location('F')
|
e = default.get_dataset_location('F')
|
||||||
default.pick('times',default.times_in_range(0.0,np.inf))
|
default.view('times',default.times_in_range(0.0,np.inf))
|
||||||
f = default.get_dataset_location('F')
|
f = default.get_dataset_location('F')
|
||||||
assert a == b == c == d == e ==f
|
assert a == b == c == d == e ==f
|
||||||
|
|
||||||
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
|
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
|
||||||
def test_pick_none(self,default,what):
|
def test_view_none(self,default,what):
|
||||||
default.pick(what,False)
|
default.view(what,False)
|
||||||
a = default.get_dataset_location('F')
|
a = default.get_dataset_location('F')
|
||||||
default.pick(what,[])
|
default.view(what,[])
|
||||||
b = default.get_dataset_location('F')
|
b = default.get_dataset_location('F')
|
||||||
|
|
||||||
assert a == b == []
|
assert a == b == []
|
||||||
|
|
||||||
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
|
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
|
||||||
def test_pick_more(self,default,what):
|
def test_view_more(self,default,what):
|
||||||
default.pick(what,False)
|
default.view(what,False)
|
||||||
default.pick_more(what,'*')
|
default.view_more(what,'*')
|
||||||
a = default.get_dataset_location('F')
|
a = default.get_dataset_location('F')
|
||||||
|
|
||||||
default.pick(what,True)
|
default.view(what,True)
|
||||||
b = default.get_dataset_location('F')
|
b = default.get_dataset_location('F')
|
||||||
|
|
||||||
assert a == b
|
assert a == b
|
||||||
|
|
||||||
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
|
@pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations
|
||||||
def test_pick_less(self,default,what):
|
def test_view_less(self,default,what):
|
||||||
default.pick(what,True)
|
default.view(what,True)
|
||||||
default.pick_less(what,'*')
|
default.view_less(what,'*')
|
||||||
a = default.get_dataset_location('F')
|
a = default.get_dataset_location('F')
|
||||||
|
|
||||||
default.pick(what,False)
|
default.view(what,False)
|
||||||
b = default.get_dataset_location('F')
|
b = default.get_dataset_location('F')
|
||||||
|
|
||||||
assert a == b == []
|
assert a == b == []
|
||||||
|
|
||||||
def test_pick_invalid(self,default):
|
def test_view_invalid(self,default):
|
||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
default.pick('invalid',True)
|
default.view('invalid',True)
|
||||||
|
|
||||||
def test_add_absolute(self,default):
|
def test_add_absolute(self,default):
|
||||||
default.add_absolute('F_e')
|
default.add_absolute('F_e')
|
||||||
|
@ -307,7 +307,7 @@ class TestResult:
|
||||||
|
|
||||||
@pytest.mark.parametrize('overwrite',['off','on'])
|
@pytest.mark.parametrize('overwrite',['off','on'])
|
||||||
def test_add_overwrite(self,default,overwrite):
|
def test_add_overwrite(self,default,overwrite):
|
||||||
default.pick('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')
|
loc = default.get_dataset_location('sigma')
|
||||||
|
|
Loading…
Reference in New Issue