-
Notifications
You must be signed in to change notification settings - Fork 16
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
Use NDAstroData.unit #140
base: master
Are you sure you want to change the base?
Use NDAstroData.unit #140
Conversation
and
|
|
Tests are passing after setting the unit to ADU in |
Yes, I think just like we assume that data in a FITS file are in ADU if there's no BUNIT, then we should assume they're in ADU when created from an NDData with no unit. |
Ok, it works and I replaced various places where BUNIT was parsed. I'm not completely happy with the changes in |
I'm not clear why the code at the end of |
Yes, that's the part I'm not happy with, but the problem with the previous version is that as it does the computation without units it doesn't update |
But the previous version used Although a quick look through |
In the previous version |
So the other option I was thinking is ae59e96 which I just pushed. I'm happy to revert to the original version if you prefer it, and setting manually |
Because we use
|
That's also an option, but then something must be done for the setter method as well. |
Can't you simply raise an exception in the Sorry this seems to have opened a can of worms but I think it's clearly the correct idea to use |
This was suggested by @chris-simpson in Trac#828, cc @KathleenLabrie as well.
This PR allows to read the unit from BUNIT and set it to
NDAstroData.unit
, and the opposite when writing files.However there is a problem with this. When a
NDData
object has a unit, then it uses this unit in computations (using AstropyQuantity
objects). Which means that all operands should have a unit. Adding or subtracting a scalar or a Numpy array without a unit raises aUnitConversionError
.There are I think 3 solutions:
Another thing to mention here is that currently there is a small performance overhead when doing arithmetic with NDData, because it uses
self.data * self.unit
to attach the unit which makes a copy of the array. This could be fixed by changing the code in Astropy to useself.data << self.unit
which does not make a copy: astropy/astropy#11107