bwinkel / pycraf

pycraf is a package that provides functions and procedures for various tasks in spectrum-management compatibility studies.
35 stars 18 forks source link

Error: astropy.units is already imported #24

Closed bwinkel closed 4 years ago

bwinkel commented 4 years ago

With astropy v4 constants can have versions. For backwards compatibility reasons, pycraf uses astropy v2.x values, i.e.

import astropy

astropy.physical_constants.set('astropyconst20')
astropy.astronomical_constants.set('astropyconst20')

One issue with this is that astropy.units must be imported afterwards, otherwise

import astropy.units as u
import astropy

astropy.physical_constants.set('astropyconst20')
>>> RuntimeError: astropy.units is already imported

likewise for pycraf:

import astropy.units as u
import pycraf
>>> RuntimeError: astropy.units is already imported

Unfortunately, for end uses it may not be obvious, what is happening, so it'd be good to add some information to the exception.