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 quantity errors from astro source models #200

merged 1 commit into from Sep 20, 2014


None yet
1 participant

cdeil commented Sep 20, 2014

@adonath After updating to Numpy 1.9, I'm getting unit test fails on my Mac from the SNR and PWN code and tests you wrote.

E.g. this code:

from astropy.units import Quantity
from gammapy.astro.source import SNR
t = Quantity([0, 1, 10, 100, 1000, 10000], 'yr')
snr = SNR()

fails like this:

AttributeError                            Traceback (most recent call last)
/private/tmp/gammapy/ in <module>()
      4 t = Quantity([0, 1, 10, 100, 1000, 10000], 'yr')
      5 snr = SNR()
----> 6 snr.radius(t)

/private/tmp/gammapy/gammapy/astro/source/ in radius(self, t)
     85                      self._radius_free_expansion(t).to('cm'))
     86         import IPython; IPython.embed()
---> 87         return Quantity(r, 'cm')
     89     def _radius_free_expansion(self, t):

/Users/deil/Library/Python/3.4/lib/python/site-packages/astropy-1.0.dev9928-py3.4-macosx-10.9-x86_64.egg/astropy/units/ in __new__(cls, value, unit, dtype, copy, order, subok, ndmin)
    176         if isinstance(value, Quantity):
    177             if unit is not None and unit is not value.unit:
--> 178                 value =
    179                 # the above already makes a copy (with float dtype)
    180                 copy = False

/Users/deil/Library/Python/3.4/lib/python/site-packages/astropy-1.0.dev9928-py3.4-macosx-10.9-x86_64.egg/astropy/units/ in to(self, unit, equivalencies)
    577         unit = Unit(unit)
    578         new_val = np.asarray(
--> 579   , self.value, equivalencies=equivalencies))
    580         return self._new_view(new_val, unit)

AttributeError: 'NoneType' object has no attribute 'to'

I've traced it down to the np.where calls ... they return an un-initialised Quantity as mentioned here (I think this is a new issue that appeared with the update to numpy 1.9 !?):

>>> np.where([True, False], Quantity([1,2], 'cm'), Quantity([10, 20], 'cm'))
<Quantity [  1., 20.] (Unit not initialised)>

Fixing this now ... something to watch out in the future.

@cdeil cdeil self-assigned this Sep 20, 2014

@cdeil cdeil added this to the 0.2 milestone Sep 20, 2014

cdeil added a commit that referenced this pull request Sep 20, 2014

Merge pull request #200 from gammapy/astro_quantity_fix
Quantity errors from gammapy.astro.source models

@cdeil cdeil merged commit 9aa0a3b into master Sep 20, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed

@cdeil cdeil changed the title from Quantity errors from gammapy.astro.source models to Fix quantity errors from astro source models Apr 8, 2015

@cdeil cdeil deleted the astro_quantity_fix branch Apr 13, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment