Skip to content

BPM and WPM fixes for odd grids#7

Open
EkaterinaBolotskaya wants to merge 2 commits intooptbrea:mainfrom
EkaterinaBolotskaya:bug/odd_grid_fixes
Open

BPM and WPM fixes for odd grids#7
EkaterinaBolotskaya wants to merge 2 commits intooptbrea:mainfrom
EkaterinaBolotskaya:bug/odd_grid_fixes

Conversation

@EkaterinaBolotskaya
Copy link
Copy Markdown

@EkaterinaBolotskaya EkaterinaBolotskaya commented Mar 24, 2026

1. BPM asymmetry - commit 1

BPM simulations are asymmetric on even grids and produce an error on odd grids.
BPM fix - “build frequency list correctly.”

Bug demonstration

Added a PSF profile into the lenses test file: https://diffractio.readthedocs.io/en/latest/source/examples_scalar/lenses.html XZ lens: BPM scheme section

Before the fix:
Asymmetric results on an even grid, error on an odd grid.

Changed the X resolution to (even):
x0 = np.linspace(-diameter / 2, diameter / 2, 2*1024)
image

Changed the X resolution to (odd):
x0 = np.linspace(-diameter / 2, diameter / 2, 2047)
image

After the fix in scalar_fields_XZ
Symmetric and no errors.

Changed the X resolution to (even):
x0 = np.linspace(-diameter / 2, diameter / 2, 2*1024)
image

Changed the X resolution to (odd):
x0 = np.linspace(-diameter / 2, diameter / 2, 2047)
image

I DID NOT TEST THE EQUIVALENT FIX I MADE IN scalar_fields_XYZ

2. WPM asymmetry on odd grids

This one was identified by Lisa Gavronskiy (lisa.gavronskiy@irradiant.tech, https://github.com/lisagavronskiy)
WPM fix - “put spectrum back in the right order before inverse FFT.”

Same example used.
Resolution - odd:
x0 = np.linspace(-diameter / 2, diameter / 2, 2023)
Method BPM -> WPM

Before:
image

After:
image

I DID NOT TEST THE EQUIVALENT FIX I MADE IN scalar_fields_XY

Testing

pytest output is the same before and after fixes:

===================================================================================== short test summary info ====================================================================================== 
FAILED tests/test_scalar_fields_X.py::Test_Scalar_fields_X::test_RS_amplification - OSError: [Errno 22] Invalid argument: 'D:\\GitHub\\diffractio\\tests_results_2026-03-24_11\\scalar_fields_X\\test_RS_amplification_RS*3.png'
FAILED tests/test_scalar_fields_X.py::Test_Scalar_fields_X::test_MTF - TypeError: Scalar_field_X.MTF() got an unexpected keyword argument 'kind'
FAILED tests/test_scalar_fields_XY.py::Test_Scalar_fields_XY::test_MTF - TypeError: Scalar_field_XY.MTF() missing 2 required positional arguments: 'fx' and 'fy'
FAILED tests/test_scalar_masks_XY.py::Test_Scalar_masks_XY::test_super_gauss - AttributeError: 'Scalar_mask_XY' object has no attribute 'super_gauss'
FAILED tests/test_scalar_masks_XZ.py::Test_Scalar_masks_XZ::test_discretize_refractive_index - ValueError: operands could not be broadcast together with shapes (256,) (7,)
FAILED tests/test_utils_math.py::Test_utils_math::test_distance - numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1
FAILED tests/test_utils_math.py::Test_utils_math::test_amplitude2phase - AssertionError: test_amplitude2phase
================================================================= 7 failed, 238 passed, 3 skipped, 3 warnings in 275.59s (0:04:35) ================================================================= 

@EkaterinaBolotskaya EkaterinaBolotskaya changed the title BPM fixes for odd grids BPM and WPM fixes for odd grids Mar 24, 2026
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.

1 participant