Stop Ptycho2DDataset.inspec() from raising a divzero error in many situations #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Because of how the calculation was done to display diffraction patterns in Ptycho2DDataset.inspect(), torch would often raise a divide by zero error if there were any masked pixels which were less than zero. This is pretty common e.g. on raw data from an Eiger detector.
I just tweaked the calculation so an error will only appear if unmasked pixels are below zero. I think in this case, it is appropriate for an error to pop up, as the user likely wants to be aware of such a situation.
This change also affects the output: now, masked pixels will always show as though they had a measured value of "0". Previously, they would always show the value "0", which only corresponds to the same thing when the log-offset is 1. I think this is more sane and consistent, but it does mean that in many situations it is no longer possible to determine which pixels are masked just by looking at dataset.inspect(). To account for this, I added an kwarg,
plot_mask, which will plot the dataset's mask when set to True. I have it set to False by default to avoid cluttering the plots further.Open to suggestions for tweaks, while I'm making changes here!