[WIP] validator and refactor - #1239
Conversation
woutdenolf
left a comment
There was a problem hiding this comment.
Looks good overall. Some small suggestions.
| def _slot(self, button): | ||
| if hasattr(button, "text"): | ||
| # received a button | ||
| pass | ||
| else: | ||
| # received an integer | ||
| button = self.buttonGroup.button(button) | ||
| if "first" in safe_str(button.text()).lower(): | ||
| self._stackIndex = 0 | ||
| text = safe_str(button.text()).lower() | ||
| if text.startswith("no"): | ||
| self._noMca = True | ||
| self._stackIndex = -1 | ||
| elif "first" in text: | ||
| self._noMca = False | ||
| self._stackIndex = 0 | ||
| else: | ||
| self._noMca = False | ||
| self._stackIndex = -1 |
There was a problem hiding this comment.
I propose a different slot for each of the three buttons.
| if _channels.size == self.data.shape[self.info["McaIndex"]]: | ||
| self.x = [_channels] | ||
| else: | ||
| # if metadata do not match the data, ignore them |
There was a problem hiding this comment.
| # if metadata do not match the data, ignore them | |
| # if metadata does not match the data, ignore them |
| # Cancel return user to Wizard | ||
| return None | ||
|
|
||
| def _effectiveShape(self, selection, rawShape): |
There was a problem hiding this comment.
| def _effectiveShape(self, selection, rawShape): | |
| @staticmethod | |
| def _effectiveShape(selection, rawShape): |
| if ndim > 2: | ||
| self.showMessage( | ||
| "Three dimensions could not represent an image. " | ||
| "'No 1D data' support only 2D and 1D datasets. " |
There was a problem hiding this comment.
| "'No 1D data' support only 2D and 1D datasets. " | |
| "'No 1D data' supports only 2D and 1D datasets. " |
| else: | ||
| if ndim < 2: | ||
| self.showMessage( | ||
| "A 1D dataset could not represent an image and channels. " |
There was a problem hiding this comment.
| "A 1D dataset could not represent an image and channels. " | |
| "A 1D dataset could not represent an image with channels. " |
| if ndim < 2: | ||
| self.showMessage( | ||
| "A 1D dataset could not represent an image and channels. " | ||
| "Use 'No 1D data (image)' in case there is no channel.") |
There was a problem hiding this comment.
| "Use 'No 1D data (image)' in case there is no channel.") | |
| "Use 'No 1D data (image)' in case there are no channels.") |
| noMca = selection.get('noMca') | ||
| scatter = selection['scatter'] |
There was a problem hiding this comment.
In several places you use .get('noMca') instead of ['noMca']. We don't do this for 'scatter' for example. What is the difference?
| selection['scatter'] = self._scatterCheckBox.isChecked() | ||
| selection['allowPadding'] = False | ||
| selection['squeeze'] = False | ||
| selection['noMca'] = self.stackIndexWidget._noMca |
There was a problem hiding this comment.
No need for .get() on these keys, they are always defined.
| if self._stack.info.get("Squeeze", False) and\ | ||
| isinstance(self._stack.data, numpy.ndarray): | ||
| oldshape = self._stack.data.shape | ||
| dialog = ImageShapeDialog(self, shape=oldshape[0:2]) | ||
| if self._squeezeSingletonStack(): |
There was a problem hiding this comment.
Is would check for "Squeeze" and numpy.ndarray inside _squeezeSingletonStack.
I was confused why in _squeezeSingletonStack we set info["Squeeze"] = False. If the check is inside _squeezeSingletonStack that would be clear.
Close #1238
positive:
many validators were added so the user have a info about what is wrong and even suggestions what was selected wrong. + it sends back to Wizard instead of closing it with error.
clear use of "1D data" position. Now there is no hidden (from UI perspective) possibility to open 2D image. To open images as stack "No 1D data" can be selected.
singletons are dropped or kept automatically if possible; in cases where it is not obvious the user is asked what to do with them.
if axis are bigger than dataset - padding is proposed (or cancel to reselect).
other changes:
a) pure singleton is not acceptable - since it makes no sense and would require a special handler.
b) order of axes matters - it is tipped in selection - it was done because before if the number of channels was equal to the size of dimension - it was unclear what will happen.
dimension validator gives:
then there is next validator based on selected axes. The full table of every possible outcome will be quite big.
NOTES:
Some things could be not obvious on first place but there is a logic - for example:
if dataset have singletons and "No 1D data" is selected. Singletons are dropped automatically because having them would only restrict dimensions - while without them user can reshape - and default option is the one as if they do exist (it is for free).
I used some AI generated tests to verify obvious things but i will test more things manually - that is why it is [WIP].
Feel free to suggest different logic. I am also fine if you would sat that this PR is bad idea - but then please provide an idea(s) to fix current state.