-
Notifications
You must be signed in to change notification settings - Fork 353
Grids 4 #1027
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
Grids 4 #1027
Conversation
The goal of the grids module is for users to not have to be familiar with xarray to use it. Returning a u.Quantity is more useful.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1027 +/- ##
==========================================
+ Coverage 96.82% 96.86% +0.04%
==========================================
Files 69 70 +1
Lines 6737 6864 +127
==========================================
+ Hits 6523 6649 +126
- Misses 214 215 +1 ☔ View full report in Codecov by Sentry. |
Would you mind if we commandeered this PR to also fix the issue of the new xarray 0.17 breaking our stuff, as found out by #1045? |
@StanczakDominik Not at all - go for it! |
... actually sorry, I should have squash-merged #1045 to master first, then just merged master here T_T my bad! Let's ignore the added changes that show up here for now. |
I've noticed an unintended consequence of changing
to
Which is that the following code no longer changes the underlying array:
because
But does anyone have thoughts on this? I can try to explain it better in the documentation and/or notebook. Ultimately I think it's still worth it to have Is there a way to use |
I think I've narrowed (at least one of) the
Results in the following printouts:
Notice ax0, ax1, and ax2 have disappeared and EDIT In case anyone is interested, the solution was that I needed to manually add the coordinate array to the new DataArray before putting it into the Dataset:
Previously I was just specifying dims=['ax'] and thinking it got the coordinates from the dataset, but I guess what was happening is that it thought the DataArray had NO coordinates and then removed them from the DataSet when the DataArray was added. |
@StanczakDominik I believe I've resolved the I do want to resolve the |
Oh bloody hell... This is exactly what got me one of the previous times when I tried integrating xarray with units for our use cases. No, I don't think there's any way of dodging that just yet. There may be some improvements coming in the future;
But no, for now AFAIK there's no way to do that cleanly UNLESSSSSSSSSSSSSSSSSSSSSSS I just had an idea that might be a hack but just might work. We currently do this:
But
so, suppose we did some variation of this:
... the more I think about it the more I seem to remember experimenting with that and failing. We definitely need a As for the MultiIndex, I don't see anything all that relevant in their changelog. We might want to report back to them with an MVE... If you could share a script that reproduces this bug, I'd step through with pudb and try to make one. |
Fingers crossed, but I think your solution works!
Then the following test now passes!
I loved the Hamilton reference, btw ;) As for MultiIndex, I will create a minimal example. However, I'm not sure it's really a bug (they may have always intended this to be required and the fact that it worked previously was the bug...) |
Here is the minimal example: I've verified that the two examples run differently on |
…ire_quantities` method
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.
Looks great! Awesome that you got the quantity no copy thing working, I have a couple of places i know I want to use it already :)
A place for more minor changes to
plasmapy.plasma.grids
.Changelog:
grid.__getitem__(key)
now returns au.Quantity
array instead of anxarray.DataArray
object. The units are more apparent this way (not buried in the attrs).Added
grid.require_quantities
method to make sure that a list of required quantities are present on a grid. @StanczakDominik suggested this on Proton Radiography Module #895 to replace some functionality in the proton radiography__init__
function. This (very minor) refactor is also included in this PR.Fixed bugs in
grids.py
for non-uniform grids that arose when xarray upgraded to v0.17.0.