Skip to content

Commit 1011e0a

Browse files
committed
Merge branch '346-result-view-warning-for-invalid-options' into 'development'
warn for unreasonable arguments to result.view etc Closes #346 See merge request damask/DAMASK!1051
2 parents 6668a68 + 8f07b14 commit 1011e0a

File tree

1 file changed

+43
-34
lines changed

1 file changed

+43
-34
lines changed

python/damask/_result.py

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ def __repr__(self) -> str:
204204

205205
def _manage_view(self,
206206
action: Literal['set', 'add', 'del'],
207-
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
208-
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
209-
phases: Union[None, str, Sequence[str], bool] = None,
210-
homogenizations: Union[None, str, Sequence[str], bool] = None,
211-
fields: Union[None, str, Sequence[str], bool] = None) -> "Result":
207+
increments: Optional[Union[int, Sequence[int], str, Sequence[str], bool]] = None,
208+
times: Optional[Union[float, Sequence[float], Literal['*'], bool]] = None,
209+
phases: Optional[Union[str, Sequence[str], bool]] = None,
210+
homogenizations: Optional[Union[str, Sequence[str], bool]] = None,
211+
fields: Optional[Union[str, Sequence[str], bool]] = None) -> "Result":
212212
"""
213213
Manage the visibility of the groups.
214214
@@ -217,9 +217,10 @@ def _manage_view(self,
217217
action : str
218218
Select from 'set', 'add', and 'del'.
219219
increments : (list of) int, (list of) str, or bool, optional
220-
Numbers of increments to select.
221-
times : (list of) float, (list of) str, or bool, optional
222-
Simulation times of increments to select.
220+
Numbers of increments to select. Mutually exclusive with 'times'.
221+
times : (list of) float, '*', or bool, optional
222+
Simulation times of increments to select. Mutually exclusive with
223+
'increments'.
223224
phases : (list of) str, or bool, optional
224225
Names of phases to select.
225226
homogenizations : (list of) str, or bool, optional
@@ -247,15 +248,17 @@ def _manage_view(self,
247248
datasets = '*'
248249
elif datasets is False:
249250
datasets = []
251+
250252
choice = [datasets] if not hasattr(datasets,'__iter__') or isinstance(datasets,str) else list(datasets) # type: ignore
253+
N_expected = len(choice)
251254

252255
if what == 'increments':
253256
choice = [c if isinstance(c,str) and c.startswith(prefix_inc) else
254257
self._increments[c] if isinstance(c,int) and c<0 else
255258
f'{prefix_inc}{c}' for c in choice]
256259
elif what == 'times':
257260
times = list(self._times.values())
258-
atol = 1e-2 * np.min(np.diff(times))
261+
atol = 1.e-2 * np.min(np.diff(times))
259262
what = 'increments'
260263
if choice == ['*']:
261264
choice = self._increments
@@ -270,8 +273,11 @@ def _manage_view(self,
270273
choice.append(self._increments[idx-1])
271274

272275
valid = _match(choice,getattr(self,'_'+what))
273-
existing = set(self._visible[what])
276+
if len(valid) < N_expected:
277+
w = what if times is None else 'times'
278+
logger.warning(f'Found only "{list(map(str,valid))}" when requesting "{datasets}" for "{w}".')
274279

280+
existing = set(self._visible[what])
275281
if action == 'set':
276282
dup._visible[what] = sorted(set(valid), key=util.natural_sort)
277283
elif action == 'add':
@@ -329,11 +335,11 @@ def times_in_range(self,
329335

330336

331337
def view(self,*,
332-
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
333-
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
334-
phases: Union[None, str, Sequence[str], bool] = None,
335-
homogenizations: Union[None, str, Sequence[str], bool] = None,
336-
fields: Union[None, str, Sequence[str], bool] = None,
338+
increments: Optional[Union[int, Sequence[int], str, Sequence[str], bool]] = None,
339+
times: Optional[Union[float, Sequence[float], Literal['*'], bool]] = None,
340+
phases: Optional[Union[str, Sequence[str], bool]] = None,
341+
homogenizations: Optional[Union[str, Sequence[str], bool]] = None,
342+
fields: Optional[Union[str, Sequence[str], bool]] = None,
337343
protected: Optional[bool] = None) -> "Result":
338344
"""
339345
Set view.
@@ -344,9 +350,10 @@ def view(self,*,
344350
Parameters
345351
----------
346352
increments : (list of) int, (list of) str, or bool, optional
347-
Numbers of increments to select.
348-
times : (list of) float, (list of) str, or bool, optional
349-
Simulation times of increments to select.
353+
Numbers of increments to select. Mutually exclusive with 'times'.
354+
times : (list of) float, '*', or bool, optional
355+
Simulation times of increments to select. Mutually exclusive with
356+
'increments'.
350357
phases : (list of) str, or bool, optional
351358
Names of phases to select.
352359
homogenizations : (list of) str, or bool, optional
@@ -385,11 +392,11 @@ def view(self,*,
385392

386393

387394
def view_more(self,*,
388-
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
389-
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
390-
phases: Union[None, str, Sequence[str], bool] = None,
391-
homogenizations: Union[None, str, Sequence[str], bool] = None,
392-
fields: Union[None, str, Sequence[str], bool] = None) -> "Result":
395+
increments: Optional[Union[int, Sequence[int], str, Sequence[str], bool]] = None,
396+
times: Optional[Union[float, Sequence[float], Literal['*'], bool]] = None,
397+
phases: Optional[Union[str, Sequence[str], bool]] = None,
398+
homogenizations: Optional[Union[str, Sequence[str], bool]] = None,
399+
fields: Optional[Union[str, Sequence[str], bool]] = None) -> "Result":
393400
"""
394401
Add to view.
395402
@@ -399,9 +406,10 @@ def view_more(self,*,
399406
Parameters
400407
----------
401408
increments : (list of) int, (list of) str, or bool, optional
402-
Numbers of increments to select.
403-
times : (list of) float, (list of) str, or bool, optional
404-
Simulation times of increments to select.
409+
Numbers of increments to select. Mutually exclusive with 'times'.
410+
times : (list of) float, '*', or bool, optional
411+
Simulation times of increments to select. Mutually exclusive with
412+
'increments'.
405413
phases : (list of) str, or bool, optional
406414
Names of phases to select.
407415
homogenizations : (list of) str, or bool, optional
@@ -427,11 +435,11 @@ def view_more(self,*,
427435

428436

429437
def view_less(self,*,
430-
increments: Union[None, int, Sequence[int], str, Sequence[str], bool] = None,
431-
times: Union[None, float, Sequence[float], str, Sequence[str], bool] = None,
432-
phases: Union[None, str, Sequence[str], bool] = None,
433-
homogenizations: Union[None, str, Sequence[str], bool] = None,
434-
fields: Union[None, str, Sequence[str], bool] = None) -> "Result":
438+
increments: Optional[Union[int, Sequence[int], str, Sequence[str], bool]] = None,
439+
times: Optional[Union[float, Sequence[float], Literal['*'], bool]] = None,
440+
phases: Optional[Union[str, Sequence[str], bool]] = None,
441+
homogenizations: Optional[Union[str, Sequence[str], bool]] = None,
442+
fields: Optional[Union[str, Sequence[str], bool]] = None) -> "Result":
435443
"""
436444
Remove from view.
437445
@@ -441,9 +449,10 @@ def view_less(self,*,
441449
Parameters
442450
----------
443451
increments : (list of) int, (list of) str, or bool, optional
444-
Numbers of increments to select.
445-
times : (list of) float, (list of) str, or bool, optional
446-
Simulation times of increments to select.
452+
Numbers of increments to select. Mutually exclusive with 'times'.
453+
times : (list of) float, '*', or bool, optional
454+
Simulation times of increments to select. Mutually exclusive with
455+
'increments'.
447456
phases : (list of) str, or bool, optional
448457
Names of phases to select.
449458
homogenizations : (list of) str, or bool, optional

0 commit comments

Comments
 (0)