astroquery icon indicating copy to clipboard operation
astroquery copied to clipboard

Cannot change Vizier configuration value neither at runtime nor with config file due to outdated parameter name in astroquery.cfg

Open orionlee opened this issue 1 year ago • 12 comments

I cannot change configuration values for Vizier, both at runtime via conf object, or at configuration file ~/.astropy/config/astroquery.cfg .

  1. For changing values with config file, setting the server in astroquery.cfg does not have any effect.
[vizier]

vizier_server = vizier.cfa.harvard.edu

UPDATE: The issue is because the parameter name is now server instead of vizier_server . See https://github.com/astropy/astroquery/issues/3018#issuecomment-2146166158 below.


  1. For changing the values at runtime, setting it with conf.server does not have any effect either. More examples later.

The issue of changing at runtime is similar to #2291 (for SIMBAD) and #2993 (for astrometry.net). The specifics are slightly different, but they all boil down to that the default value is read once at class loading time.


Example for runtime config issue

For illustration, I added a debug output at the end of VizierClass.__init__():

        # at the end of __init__()
        print("[DBG] vizier_server param:", vizier_server, "- in conf obj:", conf.server)

Test code

import astroquery.vizier as vizier

print("Before change:", vizier.conf.server)
vizier.conf.server = "vizier.cfa.harvard.edu"
print("after change:", vizier.conf.server)

print("Create Vizier object...")
vizier.Vizier()

Output: it shows the updated value in conf object is not used.

Before change: vizier.cds.unistra.fr
after change: vizier.cfa.harvard.edu
Create Vizier object...
[DBG] vizier_server param: vizier.cds.unistra.fr - in conf obj: vizier.cfa.harvard.edu

Workaround for runtime issue: Reload all relevant modules

from importlib import reload
import astroquery.vizier as vizier

vizier.conf.server = "vizier.cfa.harvard.edu"

# need to reload both
reload(vizier.core)
reload(vizier)

print("Create Vizier object...")
vizier.Vizier()

Output

Create Vizier object...
[DBG] vizier_server param: vizier.cfa.harvard.edu - in conf obj: vizier.cfa.harvard.edu

It could get tricky in practice to do proper reloading. If Vizier is imported to some other module, say, module_a, module_a would also need to be reloaded.


Versions astroquery: v0.4.7 astropy: v6.0.1 Platform: Windows 11

orionlee avatar May 31 '24 23:05 orionlee

Inspecting a few other packages,

orionlee avatar Jun 01 '24 00:06 orionlee

This is a duplicate of https://github.com/astropy/astroquery/issues/2993 - in short, we don't support the approach you're trying now, but we could (slowly) refactor to support it.

keflavich avatar Jun 01 '24 00:06 keflavich

There are two issues here.

  1. changing with config file. Somehow it does not work, as if astroquery.cfg is ignored. I don't think it is raised in other issues.

  2. changing at runtime: it is of the same nature of #2993 (for astrometry.net) and #2291 (for SIMBAD)

orionlee avatar Jun 01 '24 00:06 orionlee

Ahhh, ok, issue 1 is new, you're right. That is a bug.

keflavich avatar Jun 01 '24 01:06 keflavich

For issue 1, the vizier config in file astroquery.cfg is ignored, I've reproduced it in Linux and WSL2 as well.

Alongside with issue 2, runtime config is ignored, effectively one cannot configure Vizier at all. The only workaround is to explicitly pass along the parameters in constructing Vizier() object, e.g., Vizier(vizier_server="vizier.cfa.harvard.edu").


Test:

In [1]: import astroquery; print("astroquery:", astroquery.__version__)
   ...: import astropy; print("astropy:", astropy.__version__)
   ...:
   ...: import astroquery.vizier as vizier
   ...: v = vizier.Vizier()
   ...: print(v.VIZIER_SERVER)
astroquery: 0.4.6
astropy: 5.2.1
vizier.u-strasbg.fr

In [2]: !grep vizier ~/.astropy/config/astroquery.cfg
[vizier]
# Options: vizier.u-strasbg.fr, vizier.nao.ac.jp, vizier.hia.nrc.ca, vizier.ast.cam.ac.uk, vizier.cfa.harvard.edu, www.ukirt.jach.hawaii.edu, vizier.iucaa.ernet.in, vizier.china-vo.org
#vizier_server = vizier.u-strasbg.fr
vizier_server = vizier.cfa.harvard.edu

Versions:

  • WSL2: astroquery 0.4.6, astropy: 5.2.1, Python 3.8
  • Linux (Ubuntu 20.404): astroquery: 0.4.6, astropy: 5.3.4, Python 3.11

orionlee avatar Jun 02 '24 19:06 orionlee

For issue 1, static config issue, it turns out the config parameter name for Vizier server is server, rather than vizier_server .

This would be ignored

[vizier]

vizier_server = vizier.cfa.harvard.edu

While this would be honored:

[vizier]

server = vizier.cfa.harvard.edu

I use vizier_server because it is in the generated astroqueryc.cfg:

# vizier_server = vizier.cds.unistra.fr

It looks like the parameter was renamed from vizier_server to server at some astroquery version, and the generated astroqueryc.cfg was from created from some old version of astroquery.

Re-generating astroqueryc.cfg would produce a new config file with correct parameter names.

from astropy.config import create_config_file
create_config_file('astroquery', overwrite=True)

orionlee avatar Jun 03 '24 21:06 orionlee

Good detective work. It looks any new astroquery users are unaffected, but anyone who had an old version of the config (the change was 10 years ago, in c58b497b81813300b4e9b371bc820d87df4836bd, so congrats on being a long-time user!) would encounter the same problem as you.

keflavich avatar Jun 03 '24 21:06 keflavich

There might still be a problem that somehow an outdated astroquery.cfg is somehow generated.

  1. I do not know when it was first generated on my machine, but it is in 2020s.
  2. in a hosted environment I got in May this year (about a month ago), https://timeseries.science.stsci.edu/ , the astroquery.cfg there also has the same outdated parameter names. The vizier section of astroquery.cfg there:
[vizier]

# Name of the VizieR mirror to use.                                                                                                                                                                 
# Options: vizier.u-strasbg.fr, vizier.nao.ac.jp, vizier.hia.nrc.ca, vizier.ast.cam.ac.uk, vizier.cfa.harvard.edu, www.ukirt.jach.hawaii.edu, vizier.iucaa.ernet.in, vizier.china-vo.org            
#vizier_server = vizier.u-strasbg.fr                                                                                                                                                                

# default timeout for connecting to server                                                                                                                                                          
#timeout = 60                                                                                                                                                                                       

# maximum number of rows that will be fetched from the result (set to -1 for                                                                                                                        
# unlimited).                                                                                                                                                                                       
#row_limit = 50                                                                                                                                                                                     

I do not know how / when the astroquery.cfg there is first generated. But it should be somewhat recent (unless their hosted environment copies some outdated version manually in their process)

The software version there is astroquery 0.4.6, astropy 5.3.4


The vizier section in the above astroquery.cfg is different from the generated one using create_config_file()

[vizier]

## Name of the VizieR mirror to use.
# server = vizier.cds.unistra.fr
...

The generated one

  • has the correct parameter name server
  • does not have the nice description listing out all the mirrors
  • the commented default value is different, with the more recent cds.unistra.fr domain.

It is as if even if a practically brand new hosted environment, an outdated astroquery.cfg still gets somehow generated.

orionlee avatar Jun 03 '24 22:06 orionlee

Sorry I failed to follow up on this. There is indeed an issue here, where the default name being produced in astroquery.cfg is vizier_server, but that is not a recognized keyword. However, since, as you pointed out, the one created by create_config_file is correct, I think the issue is sort of solved.

The question left to answer in this Issue is: are users' config files being generated incorrectly? Where and why? i.e., where/when does create_config_file get called or fail to get called?

keflavich avatar Sep 07 '24 18:09 keflavich

In the hosted https://timeseries.science.stsci.edu/ environment, it should be a fresh environment with recent versions (astroquery 0.4.6, astropy 5.3.4)

But somehow the default astroquery.cfg file there still used the outdated parameter names.

orionlee avatar Sep 11 '24 19:09 orionlee

Not sure if this is related but I noticed that the configuration value is accessed in the __init__ call which means it is evaluated at import time. Is there are reason that vizier_server isn't just set to None and then have the value be extracted from conf inside the __init__?

astrofrog avatar Feb 24 '25 14:02 astrofrog

We could do that, @astrofrog. Do you think that's the cause of the above issue? I'd suspect it's unrelated, since the problem here is that the keyword is incorrectly named.

keflavich avatar Feb 24 '25 17:02 keflavich