Closed SteveOstile closed 1 year ago
Thanks for the report!
I agree this behavior is not obvious. That said it's at least partially intentional, though I agree there's definitely a bug still. Looking back at the code of the rotate function, it appears the logic was/is to avoid rotating large arrays of zero-padding, for performance reasons. The zero padding is supposed to be added back in later, if needed. See this part of code, from the definition of the rotate
function:
if self.ispadded:
# pupil plane is padded - trim out the zeros since it's not needed in the rotation
# If needed in later steps, the padding will be re-added automatically
self.wavefront = utils.remove_padding(self.wavefront, self.oversample)
self.ispadded = False
This all works as intended for the Fraunhofer code. But definitely something is not as intended for the Fresnel side of things. First, the apparent spatial extent of the illuminated beam certainly shouldn't change. Secondly, it's clearly not adding back in the zero padding before trying a subsequent Fresnel propagation.
The first problem appears to be related to extra internal index arrays the Fresnel code maintains, which don't get updated for the change in padding. The not adding back in the zero padding is simple: the propagate_fresnel
code simply doesn't check for an unpadded array.
I think the most straightforward fix is likely to subclass the rotation function for FresnelWavefront
and leave out the bit that removes the padding. Seems to me that any speed gains from not rotating the many zeros are not worth the added complexity in this case.
Oh and @SteveOstile: welcome! Thanks for reporting this. And I see this looks like your first comment on a GitHub issue so let me extend an extra welcome in that case :-)
Fix added in PR #573. @SteveOstile, let me know if you're comfortable enough with git/gitub to perhaps check out and test that code? For me, running with the modified version in the PR, your example code above runs with no surprises.
Hi @mperrin,
Thanks for reacting so quickly to my comment! I understand the issue now. Well, I am so new on github that I am not very comfortable in reviewing your modification. I have to look how I can pip install your modification...
Hi @SteveOstile we've merged the fix into the develop
branch here. I believe you should be able to install from GitHub with something like this:
pip install git+https://github.com/spacetelescope/poppy.git@develop#egg=poppy
@mperrin Excellent ! It works perfectly !
Dear Poppy team,
Thanks for nice work on Poppy !
I've found an unexpected modification of the FresnelWavefront matrix size after applying rotation using the following code :
The 2 print outputs are:
Before rotation: (2048, 2048) After rotation: (1024, 1024)
Displaying amplitude and phase before rotation:
Displaying amplitude and phase after rotation:
As you can see, the matrix size goes from 2048 x 2048 to 1024x1024 and the width of the beam is doubled. Also this generates the following error while propagating the rotated wavefront #
Thanks for looking at this issue.