Astrometry.net warning about API key
I am trying to avoid getting a warning about the astrometry.net API key when initializing the AstrometryNet class, without having to define the API key in the config file:
In [1]: from astroquery.astrometry_net import AstrometryNet
...: ast = AstrometryNet()
...:
WARNING: Astrometry.net API key not found in configuration file [astroquery.astrometry_net.core]
WARNING: You need to manually edit the configuration file and add it [astroquery.astrometry_net.core]
WARNING: You may also register it for this session with AstrometryNet.api_key = 'XXXXXXXX' [astroquery.astrometry_net.core]
WARNING: Astrometry.net API key not found in configuration file [astroquery.astrometry_net.core]
WARNING: You need to manually edit the configuration file and add it [astroquery.astrometry_net.core]
WARNING: You may also register it for this session with AstrometryNet.api_key = 'XXXXXXXX' [astroquery.astrometry_net.core]
The warning is duplicated because it happens during the import and during the initialization. I thought I could fix this by simply setting the api_key conf item before initializing the class, and indeed this gets rid of the second warning but not the first:
In [1]: from astroquery.astrometry_net import AstrometryNet, conf
...: conf.api_key = 'banana'
...: ast = AstrometryNet()
WARNING: Astrometry.net API key not found in configuration file [astroquery.astrometry_net.core]
WARNING: You need to manually edit the configuration file and add it [astroquery.astrometry_net.core]
WARNING: You may also register it for this session with AstrometryNet.api_key = 'XXXXXXXX' [astroquery.astrometry_net.core]
The issue is that this actually happens during the import:
In [1]: from astroquery.astrometry_net import AstrometryNet, conf
...:
WARNING: Astrometry.net API key not found in configuration file [astroquery.astrometry_net.core]
WARNING: You need to manually edit the configuration file and add it [astroquery.astrometry_net.core]
WARNING: You may also register it for this session with AstrometryNet.api_key = 'XXXXXXXX' [astroquery.astrometry_net.core]
So the only way to get rid of this is to define the API key in the file, but for the use case I am looking at I don't want to have to do that and it should be possible to do by setting conf.api_key.
The issue occurs because internally, AstrometryNetClass is initialized during the import.
I'm not very familiar with how the class infrastructure works in astroquery, but I wonder if the best solution here is to simply check for the API key when it is needed, in the api_key property?
I will open a PR with a possible fix but opening this issue separately in case my fix is not suitable for any reason.
Possible fix in https://github.com/astropy/astroquery/pull/2483