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 Volume Weighted Interpolator in CartesianGrid class (grids.py) #1173

Merged
merged 86 commits into from
Aug 16, 2021

Conversation

pheuer
Copy link
Member

@pheuer pheuer commented Jun 23, 2021

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!
image

And here it is with the corrected algorithm
image

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

image

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.

@pheuer pheuer requested a review from StanczakDominik June 23, 2021 18:27
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions bot added Breaking plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage notebooks Related to example Jupyter notebooks in docs/examples/ plasmapy.plasma Related to the plasmapy.plasma subpackage labels Jun 23, 2021
…rids"

This reverts commit 7e839ee, reversing
changes made to bc7c334.
@github-actions github-actions bot removed Breaking notebooks Related to example Jupyter notebooks in docs/examples/ plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage labels Jun 23, 2021
@codecov
Copy link

codecov bot commented Jun 23, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@7174839). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7174839...f309347. Read the comment docs.

Copy link
Member

@rocco8773 rocco8773 left a 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.

plasmapy/plasma/grids.py Outdated Show resolved Hide resolved
plasmapy/plasma/grids.py Outdated Show resolved Hide resolved
plasmapy/plasma/grids.py Outdated Show resolved Hide resolved
plasmapy/plasma/grids.py Outdated Show resolved Hide resolved
@pheuer
Copy link
Member Author

pheuer commented Aug 6, 2021

I just noticed in AbstractGrid._load_grid online 605 you used add_quantity instead of add_quantities. I'm surprised there's no failed tests from this and I'm guessing that's because tests never reached this line.

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 add_quantities().

I changed the way the proton radiography code was handling NaN values and all the tests are now passing.

@rocco8773 rocco8773 merged commit 5f82159 into PlasmaPy:main Aug 16, 2021
@pheuer
Copy link
Member Author

pheuer commented Aug 17, 2021

@rocco8773 Awesome, thanks for cleaning this up and getting it merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.diagnostics Related to the plasmapy.diagnostics subpackage plasmapy.plasma Related to the plasmapy.plasma subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants