Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix off-by-one filtering errors. #2016

Merged
merged 5 commits into from
Mar 24, 2022

Conversation

smartalecH
Copy link
Collaborator

Fixes #2012.

Note this is just a patch. A future PR could really improve the performance of our filtering, as described in #2012.

For now, this PR ensures that the impulse response is always Type I (even with an odd number of taps) so that it is zero phase. It adds a new function, compute_mg_dims, to help with this.

Also adds a test to check for "off-by-one" errors.

@smartalecH smartalecH requested a review from oskooi March 23, 2022 19:35
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2022

Codecov Report

Merging #2016 (dfdbba3) into master (34b62e9) will increase coverage by 0.41%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2016      +/-   ##
==========================================
+ Coverage   73.15%   73.57%   +0.41%     
==========================================
  Files          17       17              
  Lines        4917     4896      -21     
==========================================
+ Hits         3597     3602       +5     
+ Misses       1320     1294      -26     
Impacted Files Coverage Δ
python/adjoint/filters.py 60.56% <100.00%> (+10.87%) ⬆️

@oskooi
Copy link
Collaborator

oskooi commented Mar 23, 2022

For consistency, we also need to update the following lines in test_material_grid.py to use mpa.compute_mg_dims:

Nx = int(matgrid_resolution*matgrid_size.x) + 1
Ny = int(matgrid_resolution*matgrid_size.y) + 1

# for a fixed resolution, compute the number of grid points
# necessary which are defined on the corners of the voxels
Nx = int(matgrid_resolution*matgrid_size.x) + 1
Ny = int(matgrid_resolution*matgrid_size.y) + 1

And also:

Nx = int(matgrid_resolution*matgrid_size.x) + 1
Ny = int(matgrid_resolution*matgrid_size.y) + 1

@smartalecH
Copy link
Collaborator Author

For consistency, we also need to update the following lines in test_material_grid.py to use mpa.compute_mg_dims

Fixed, thanks.

@smartalecH
Copy link
Collaborator Author

CI doesn't want to trigger for some reason...

def compute_mg_dims(Lx,Ly,resolution):
'''Compute the material grid dimensions from
the corresponding resolution, x-size, and y-size.
The grid dimensions must be odd.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator Author

@smartalecH smartalecH Mar 24, 2022

Choose a reason for hiding this comment

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

If the number of "taps" is not odd, it's no longer a zero-phase filter.

And the way that we do the FFT filtering requires that the number of taps must equal the size of the input.

@smartalecH
Copy link
Collaborator Author

Should be ready to merge now.

The implementation is agnostic to the number of filter taps. No need to "add 1" or check that's it's odd.

@stevengj
Copy link
Collaborator

LGTM.

@stevengj stevengj merged commit 11545a1 into NanoComp:master Mar 24, 2022
@smartalecH smartalecH deleted the origin/fix_filters branch March 24, 2022 23:52
@mawc2019
Copy link
Contributor

mawc2019 commented Dec 30, 2022

It seems that the 2d filters in filters.py, including cylindrical_filter, conic_filter, and gaussian_filter, should have kernels with circular boundaries, but the code in these functions implies that they are rectangular. For example, in cylindrical_filter, the kernel is defined in this way. This issue was also mentioned here. Before this PR, only the kernel of gaussian_filter has rectangular boundaries, but after this PR, the kernels of all three filters have rectangular boundaries.

In addition, as one of the steps for fixing the off-by-one error, this PR forces the size of each kernel to be an odd number along every direction, which is indicated by _proper_pad. This measure may cause errors in the sizes of kernels. Could the off-by-one error be fixed in a way without introducing the odd-number restriction?

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.

New adjoint filtering scheme
5 participants