-
Notifications
You must be signed in to change notification settings - Fork 340
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 Volume Weighted Interpolator in CartesianGrid class (grids.py) #1173
Conversation
This reverts commit 335305c.
for more information, see https://pre-commit.ci
This is closer to a proper volume-weighted interpolator, but the edge behavior is still a little wonky and probably needs to be revisited.
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report
@@ Coverage Diff @@
## main #1173 +/- ##
=======================================
Coverage ? 97.06%
=======================================
Files ? 73
Lines ? 7088
Branches ? 0
=======================================
Hits ? 6880
Misses ? 208
Partials ? 0 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes will properly add the np.nan
values.
Co-authored-by: Erik Everson <[email protected]>
Co-authored-by: Erik Everson <[email protected]>
This was never hit because it isn't actually supported to add quantities this way anymore: I've just removed this line. Quantities should be added after creating the grid, using I changed the way the proton radiography code was handling NaN values and all the tests are now passing. |
…average_interpolator_handle_out_of_bounds`
…_at_several_positions
…emove unused sections of code
@rocco8773 Awesome, thanks for cleaning this up and getting it merged! |
I realized the current volume weighted interpolator in grids.CartesianGrid was incorrect. This PR fixes that.
Here's an example of the old interpolator: the linear interpolation between data points is backwards!
And here it is with the corrected algorithm
I haven't yet found a good implementation of this algorithm to copy, so my code probably isn't the most efficient. The diagram below shows the idea in 2D
The particle position "p" is surrounded by a box of size dx * dy. The four surrounding grid points are similarly surrounded. The weight for the field from each grid point is then the area (volume in 3D) of the overlap between the particle box and the box for each grid point.