[AstroPy] Revert to astropy 1.3 constants (for testing) in astropy 2.0

Thomas Robitaille thomas.robitaille at gmail.com
Sun Jan 28 05:16:25 EST 2018


Hi Duncan,

Just to close the loop on this (and in case anyone finds this thread),
this will be much simpler in the upcoming 3.0 release, as there will
be a context manager to do this:

http://docs.astropy.org/en/latest/api/astropy.constants.set_enabled_constants.html#astropy.constants.set_enabled_constants

Cheers,
Tom


On 10 July 2017 at 15:01, Duncan Macleod <duncan.macleod at ligo.org> wrote:
> Hi Derek,
>
> Unfortunately, I don't want to change the imports in my module, but only in
> the test suite. Essentially I want to mock the constants module back to
> astropy-1.3 values.
>
> In the end I ended up with the following in my test module:
>
> from astropy import __version__ as astropy_version
> if astropy_version >= '2.0':
>     from astropy import constants
>     from astropy.constants import (si, astropyconst13)
>     units.M_sun._represents = units.Unit(astropyconst13.M_sun)
>     constants.M_sun = si.M_sun = astropyconst13.M_sun
>     constants.G = si.G = astropyconst13.G
>     constants.c = si.c = astropyconst13.c
>     constants.pc = si.pc = astropyconst13.pc
>
> to just fix the constants I need without editing the module code that
> actually uses them. This is after the module import, but before any function
> calls. A bit messy, but does the job.
>
>
> D
>
> On 10 July 2017 at 14:56, Derek Homeier
> <derek at astro.physik.uni-goettingen.de> wrote:
>>
>> On 10 Jul 2017, at 2:34 pm, Duncan Macleod <duncan.macleod at ligo.org>
>> wrote:
>> >
>> > Is there a way to tell astropy.constants to use the version 1.3
>> > constants (from astropy.constants.astropyconst13) when using the v2.0
>> > package? i.e. have astropy.constants.M_sun come from iau2012 and not
>> > iau2015?
>> >
>> > I have a bunch of unit tests are now failing because of the relatively
>> > large changes in some constants.*
>> >
>> Depends on how you currently import them, but replacing e.g.
>>
>> from astropy import constants as const
>>
>> with
>>
>> from astropy.constants import astropyconst13 as const
>>
>> should have the desired effect.
>>
>> HTH
>>                                                 Derek
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at python.org
>> https://mail.python.org/mailman/listinfo/astropy
>
>
>
>
> --
> Duncan Macleod
> duncan.macleod at ligo.org
> Sêr Cymru Cofund Fellow
> School of Physics and Astronomy
> Cardiff University
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>


More information about the AstroPy mailing list