-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Refactor Quantity into Numpy ndarray sub-class #929
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
Conversation
|
I'll have to look at this after 0.2.1 is out. But I like where this is going.... |
|
+1,000,000 in principle. I'll have to play with this a bit, and it does seem to break every test configuration on Travis so there's probably some glitch here... |
|
@mdboom - the tests are failing because astropy.constants is broken. This is very much an incomplete pull request at this stage, so any help is welcome :-) |
|
Ah, very nice -- thanks @astrofrog ! |
|
@astrofrog before we proceed - Wasn't the idea that Quantity would carry uncertainties? Does that still work with being a subclass of |
|
I think this may come useful as a base class for models._Parameter class. This will make parameters usable in astrophysical models as it already handles units. |
|
@nden 👍 to the idea of letting Parameters in models be One concern about this, though: this makes tab-completion very busy on The other danger is that this now ties us to the numpy API permanently. I thought the whole points of this is to encourage |
|
@eteq - the plan was not to allow |
|
@wkerzendorf - the decision was to not have uncertainties in quantities (that's what NDData is for). |
|
Except that Constants have uncertainties, they just aren't carried through when used in operations with other Quantities :/ |
|
re: uncertainties and constants: @iguananaut raises a good point here... and that would be a useful feature. I think the primary motivation for keeping uncertainties out of |
|
@astrofrog - Ah, I see, yeah then my second issue is maybe not as big a deal. And would q.mean() return a |
|
I think we need to have a scalar class that carries errors along and i think So in my opinion, the |
|
@eteq - I think that anyone can feel free to try and develop a framework for uncertainties, and we can then decide whether to attach it to Quantity, NDData, etc. But actually the more time goes on, the less important that feature seems to me, and I think it's actually going to be virtually impossible to implement. There's a lot more useful functionality that we need to develop (specutils, photutils, WCSAxes, etc.) that this is not a high priority (at least for me). |
|
We also need to be a little bit careful with thinks like |
|
@astrofrog - ok, that sounds good - as @wkerzendorf says, we probably want tests to ensure ufuncs like |
|
re: uncertainties: In my mind, a lack of uncertainties is one of the main things blocking implementation of things like That said, @astrofrog has a very good point that we should develop the framework first, and later decide whether or not it ends up in |
|
I have a feeling that eventually these two data structures will merge together, but in the meantime I'm happy to hack on them from different directions until they meet up in the middle. |
|
@iguananaut - do you have any ideas of how |
|
I'm trying to get a pyfits release out the door, but I'll start looking at this once that's done. Can you give me some idea of what the problem is with constants? Does it have something to do with the metaclass? |
|
@iguananaut - yes, it's to do with the metaclass and |
|
@iguananaut - I was wondering whether you could take a look at this, since I'm not sure I understand fully how the Constant meta-class works. I've rebased the branch on the latest master as there were some conflicts. |
|
Taking a look now. No promises on what I'll find :) |
|
@iguananaut - thanks! |
|
Thanks to @iguananaut the test now pass, so anyone interested can try out this branch. There is however the issue that @wkerzendorf raised which is that many ufuncs are going to be returning results that are wrong in terms of the units. For instance, all the following are wrong: I'm not sure how we could best deal with things like @iguananaut - before you fixed this branch, the There's another thing worth thinking about - would it simplify things to have a separate class for |
|
I've been trying to improve the test coverage and as part of this uncovered and fixed a few bugs. A couple did not have a trivial fix, so I've marked them as xfail and opened a new issue (#1273) since these bugs are not critical (they only occur for in-place use of specific functions/methods). |
…ns fail tests anyway to see if they would have worked, but these cause segfaults with older version of Numpy.
|
This is now ready for a final review! I will send an email to the dev list. |
|
@iguananaut - can you confirm this works on Windows? |
|
Well done! I just tried it out, looks very nice. Thanks to everyone who contributed to this! |
|
I got one relevant test failure on Windows with Numpy 1.7: Seems more an error in the test though. I'm not sure what that means or why the test is using getfield there. |
|
Oh I think I see the problem. This is a 32-bit build of Python so the default dtype on that array is int32, not int64, so taking offset=4 doesn't make any sense. In order to be agnostic this test should explicitly write |
|
@iguananaut - do all the test pass now? |
|
Any remaining comments, or shall we merge this later today? |
|
@mdboom @iguananaut - does this look ready to merge from your perspective? |
|
Yes, as far as I'm concerned. |
|
Ok, so @iguananaut - could you check that everything passes on Windows, and merge this if so? Thanks! |
|
Oh, I thought I updated you on this days ago, but I just realized I had a tab open where I started to do so, and then must have gotten distracted. Yes, all the (relevant) tests pass on Windows now. |
Refactor Quantity into Numpy ndarray sub-class
This is an alternative to #899 and tries to fix the issue described there.
Basically, this re-factors the
Quantityclass so that it can be a sub-class of Numpy ndarray. This works nicely when using the class as standalone, but it is breaking havoc when I put it in Astropy, because of the code in astropy.constants.@iguananaut - I can't figure out how to adjust the
ConstantandConstantMetaclasses to work properly now, do you have any ideas? If you can think of a fix, please feel free to open a PR against my branch.cc @taldcroft @mdboom @eteq