Skip to content

Conversation

@allevitan
Copy link
Collaborator

@allevitan allevitan commented Nov 19, 2025

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!

…ivide by zero error if unmasked pixels have an issue. Add an option to ptycho_2d_dataset to plot the mask
Copy link
Collaborator

@yoshikisd yoshikisd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

@yoshikisd yoshikisd merged commit 126bfaa into master Dec 8, 2025
9 checks passed
@yoshikisd yoshikisd deleted the fix-divzero-error branch December 8, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants