Skip to content
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

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

Open
orionlee opened this issue May 31, 2024 · 10 comments

Comments

@orionlee
Copy link
Contributor

orionlee commented May 31, 2024

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 #3018 (comment) 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
Copy link
Contributor Author

orionlee commented Jun 1, 2024

Inspecting a few other packages,

@orionlee orionlee changed the title Cannot change configuration value for Vizier at runtime and config files Cannot change configuration value for Vizier neither at runtime nor with config file Jun 1, 2024
@orionlee orionlee changed the title Cannot change configuration value for Vizier neither at runtime nor with config file Cannot change Vizier configuration value neither at runtime nor with config file Jun 1, 2024
@keflavich
Copy link
Contributor

This is a duplicate of #2993 - in short, we don't support the approach you're trying now, but we could (slowly) refactor to support it.

@orionlee
Copy link
Contributor Author

orionlee commented Jun 1, 2024

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 Issue changing configuration at runtime #2993 (for astrometry.net) and Changing config items at runtime is broken #2291 (for SIMBAD)

@keflavich
Copy link
Contributor

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

@orionlee
Copy link
Contributor Author

orionlee commented Jun 2, 2024

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
Copy link
Contributor Author

orionlee commented Jun 3, 2024

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)

@keflavich
Copy link
Contributor

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 c58b497, so congrats on being a long-time user!) would encounter the same problem as you.

@orionlee
Copy link
Contributor Author

orionlee commented Jun 3, 2024

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.

@keflavich
Copy link
Contributor

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?

@orionlee orionlee changed the title Cannot change Vizier configuration value neither at runtime nor with config file Cannot change Vizier configuration value neither at runtime nor with config file due to outdated parameter name in astroquery.cfg Sep 11, 2024
@orionlee
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants