Skip to content

Commit 1944001

Browse files
authored
Merge pull request #3186 from cds-astro/better-migration-simbad
Better migration simbad
2 parents b005fc9 + b177f06 commit 1944001

File tree

6 files changed

+137
-25
lines changed

6 files changed

+137
-25
lines changed

CHANGES.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ jplspec
1919

2020
- minor improvement to lookuptable behavior [#3173,#2901]
2121

22+
simbad
23+
^^^^^^
24+
25+
- Fixed adding a list of fluxes with the deprecated notation
26+
``Simbad.add_votable_fields("flux(U)", "flux(J)")`` [#3186]
27+
28+
- Support more of the 0.4.7 votable fields. Raise more significant error messages
29+
for the discontinued ones. [#3186]
30+
31+
- Fix the deprecated votable fields ``otype(V)`` and ``otype(S)`` [#3186]
32+
33+
- Fixed non existing flux filters as votable fields would fail silently [#3186]
2234

2335
Infrastructure, Utility and Other Changes and Additions
2436
-------------------------------------------------------

astroquery/simbad/core.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,19 @@ def list_votable_fields(self):
234234
>>> options = Simbad.list_votable_fields() # doctest: +REMOTE_DATA
235235
>>> # to print only the available bundles of columns
236236
>>> options[options["type"] == "bundle of basic columns"][["name", "description"]] # doctest: +REMOTE_DATA
237-
<Table length=8>
238-
name description
239-
object object
240-
------------- ----------------------------------------------------
241-
coordinates all fields related with coordinates
242-
dim major and minor axis, angle and inclination
243-
dimensions all fields related to object dimensions
244-
morphtype all fields related to the morphological type
245-
parallax all fields related to parallaxes
246-
propermotions all fields related with the proper motions
247-
sp all fields related with the spectral type
248-
velocity all fields related with radial velocity and redshift
237+
<Table length=9>
238+
name description
239+
object object
240+
------------- -------------------------------------------------------
241+
coordinates all fields related with coordinates
242+
dim major and minor axis, angle and inclination
243+
dimensions all fields related to object dimensions
244+
morphtype all fields related to the morphological type
245+
parallax all fields related to parallaxes
246+
pm proper motion values in right ascension and declination
247+
propermotions all fields related with the proper motions
248+
sp all fields related with the spectral type
249+
velocity all fields related with radial velocity and redshift
249250
"""
250251
# get the tables with a simple link to basic
251252
query_tables = """SELECT DISTINCT table_name AS name, tables.description
@@ -380,29 +381,33 @@ def add_votable_fields(self, *args):
380381
"""
381382

382383
# the legacy way of adding fluxes
383-
args = list(args)
384+
args = set(args)
384385
fluxes_to_add = []
385-
for arg in args:
386+
args_copy = args.copy()
387+
for arg in args_copy:
386388
if arg.startswith("flux_"):
387389
raise ValueError("The votable fields 'flux_***(filtername)' are removed and replaced "
388390
"by 'flux' that will add all information for every filters. "
389391
"See section on filters in "
390392
"https://astroquery.readthedocs.io/en/latest/simbad/simbad_evolution.html"
391393
" to see the new ways to interact with SIMBAD's fluxes.")
392394
if re.match(r"^flux.*\(.+\)$", arg):
393-
warnings.warn("The notation 'flux(U)' is deprecated since 0.4.8 in favor of 'U'. "
394-
"See section on filters in "
395+
filter_name = re.findall(r"\((\w+)\)", arg)[0]
396+
warnings.warn(f"The notation 'flux({filter_name})' is deprecated since 0.4.8 in favor of "
397+
f"'{filter_name}'. You will see the column appearing with its new name "
398+
"in the output. See section on filters in "
395399
"https://astroquery.readthedocs.io/en/latest/simbad/simbad_evolution.html "
396400
"to see the new ways to interact with SIMBAD's fluxes.", DeprecationWarning, stacklevel=2)
397-
fluxes_to_add.append(re.findall(r"\((\w+)\)", arg)[0])
401+
fluxes_to_add.append(filter_name)
398402
args.remove(arg)
399403

400404
# output options
401405
output_options = self.list_votable_fields()
402406
# fluxes are case-dependant
403-
fluxes = output_options[output_options["type"] == "filter name"]["name"]
407+
fluxes = set(output_options[output_options["type"] == "filter name"]["name"])
404408
# add fluxes
405-
fluxes_to_add += [flux for flux in args if flux in fluxes]
409+
fluxes_from_names = set(flux for flux in args if flux in fluxes)
410+
fluxes_to_add += fluxes_from_names
406411
if fluxes_to_add:
407412
self.joins.append(_Join("allfluxes", _Column("basic", "oid"),
408413
_Column("allfluxes", "oidref")))
@@ -413,6 +418,10 @@ def add_votable_fields(self, *args):
413418
self.columns_in_output.append(_Column("allfluxes", flux + "_", flux))
414419
else:
415420
self.columns_in_output.append(_Column("allfluxes", flux))
421+
# remove the arguments already added
422+
args -= fluxes_from_names
423+
# remove filters from output options
424+
output_options = output_options[output_options["type"] != "filter name"]
416425

417426
# casefold args because we allow case difference for every other argument (legacy behavior)
418427
args = set(map(str.casefold, args))

astroquery/simbad/data/query_criteria_fields.json

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
"tap_column": ["ra", "dec", "ra_prec", "dec_prec"],
3434
"type": "bundle"
3535
},
36+
"dec(d)": {
37+
"tap_column": "dec",
38+
"type": "alias"
39+
},
40+
"dec_prec": {
41+
"description": "precision code for the coordinates (ra and dec are no longer distinct)",
42+
"tap_column": "coo_qual",
43+
"type": "alias"
44+
},
45+
"diameter": {
46+
"descriptions": "all measurements of diameter",
47+
"tap_table": "mesdiameter",
48+
"type": "alias table"
49+
},
3650
"dim": {
3751
"description": "major and minor axis, angle and inclination",
3852
"tap_startswith": "galdim_",
@@ -187,14 +201,22 @@
187201
"tap_column": "morph_type",
188202
"type": "alias"
189203
},
190-
"otype(V)": {
204+
"otype(v)": {
191205
"tap_table": "otypedef",
192206
"type": "alias table"
193207
},
194-
"otype(S)": {
208+
"otype(n)": {
195209
"tap_table": "otypedef",
196210
"type": "alias table"
197211
},
212+
"otype(3)": {
213+
"tap_column": "otype",
214+
"type": "alias"
215+
},
216+
"otype(s)": {
217+
"tap_column": "otype",
218+
"type": "alias"
219+
},
198220
"parallax": {
199221
"description": "all fields related to parallaxes",
200222
"tap_startswith": "plx_",
@@ -210,6 +232,11 @@
210232
"tap_column": "plx_err",
211233
"type": "alias"
212234
},
235+
"pm": {
236+
"description": "proper motion values in right ascension and declination",
237+
"tap_column": ["pmra", "pmdec"],
238+
"type": "bundle"
239+
},
213240
"pm_err_maja": {
214241
"description": "major axis of the error ellipse",
215242
"tap_column": "pm_err_maj",
@@ -225,11 +252,20 @@
225252
"tap_startswith": "pm",
226253
"type": "bundle"
227254
},
255+
"ra(d)": {
256+
"tap_column": "ra",
257+
"type": "alias"
258+
},
228259
"radvel": {
229260
"description": "Radial velocity",
230261
"tap_column": "rvz_radvel",
231262
"type": "alias"
232263
},
264+
"ra_prec": {
265+
"description": "precision code for the coordinates (ra and dec are no longer distinct)",
266+
"tap_column": "coo_qual",
267+
"type": "alias"
268+
},
233269
"redshift": {
234270
"type": "alias",
235271
"tap_column": "rvz_redshift"
@@ -268,6 +304,10 @@
268304
"type": "alias",
269305
"tap_column": "sp_type"
270306
},
307+
"td1": {
308+
"description": "UV fluxes from TD1 satellite,by Thompson et al.",
309+
"type": "historical measurement"
310+
},
271311
"v*": {
272312
"description": "variable stars parameters extracted mainly from the General Catalog of Variable Stars by Kukarkin et al. USSR Academy of Sciences (3rd edition in 1969,and continuations)",
273313
"type": "alias table",

astroquery/simbad/tests/test_simbad.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,26 @@ def test_add_votable_fields():
261261
# a table which name has changed should raise a warning too
262262
with pytest.warns(DeprecationWarning, match="'distance' has been renamed 'mesdistance'*"):
263263
simbad_instance.add_votable_fields("distance")
264+
265+
266+
@pytest.mark.usefixtures("_mock_simbad_class")
267+
@pytest.mark.usefixtures("_mock_basic_columns")
268+
@pytest.mark.usefixtures("_mock_linked_to_basic")
269+
def test_add_votable_fields_errors():
264270
# errors are raised for the deprecated fields with options
265271
simbad_instance = simbad.SimbadClass()
266272
with pytest.raises(ValueError, match=r"The votable fields \'flux_\*\*\*\(filtername\)\' are removed *"):
267273
simbad_instance.add_votable_fields("flux_error(u)")
268-
with pytest.warns(DeprecationWarning, match=r"The notation \'flux\(U\)\' is deprecated since 0.4.8 *"):
274+
with pytest.warns(DeprecationWarning, match=r"The notation \'flux\(u\)\' is deprecated since 0.4.8 *"):
269275
simbad_instance.add_votable_fields("flux(u)")
270276
assert "u_" in str(simbad_instance.columns_in_output)
277+
# big letter J filter exists, but not small letter j
278+
with pytest.raises(ValueError, match="'j' is not one of the accepted options *"):
279+
simbad_instance.add_votable_fields("j")
271280
with pytest.raises(ValueError, match="Coordinates conversion and formatting is no longer supported*"):
272-
simbad_instance.add_votable_fields("coo(s)", "dec(d)")
281+
simbad_instance.add_votable_fields("coo(s)")
282+
with pytest.warns(DeprecationWarning, match=r"\'dec\(d\)\' has been renamed \'dec\'. *"):
283+
simbad_instance.add_votable_fields("dec(d)")
273284
with pytest.raises(ValueError, match="Catalog Ids are no longer supported as an output option.*"):
274285
simbad_instance.add_votable_fields("ID(Gaia)")
275286
with pytest.raises(ValueError, match="Selecting a range of years for bibcode is removed.*"):
@@ -281,7 +292,28 @@ def test_add_votable_fields():
281292
with pytest.raises(ValueError, match="'alltype' is not one of the accepted options which can be "
282293
"listed with 'list_votable_fields'. Did you mean 'alltypes' or 'otype' or 'otypes'?"):
283294
simbad_instance.add_votable_fields("ALLTYPE")
284-
# bundles and tables require a connection to the tap_schema and are thus tested in test_simbad_remote
295+
# successive positions no longer ins SIMBAD (for years)
296+
with pytest.raises(ValueError, match="Successive measurements of the positions *"):
297+
simbad_instance.add_votable_fields("pos")
298+
# no longer stores sp_nature
299+
with pytest.raises(ValueError, match="Spectral nature is no longer stored in SIMBAD. *"):
300+
simbad_instance.add_votable_fields("sp_nature")
301+
# typed_id had only been added for astroquery's interaction with the old API
302+
with pytest.raises(ValueError, match="'typed_id' is no longer a votable field. *"):
303+
simbad_instance.add_votable_fields("typed_id")
304+
# uvb and others no longer have their table in SIMBAD
305+
with pytest.raises(ValueError, match="Magnitudes are now handled very differently in SIMBAD. *"):
306+
simbad_instance.add_votable_fields("ubv")
307+
308+
309+
@pytest.mark.usefixtures("_mock_simbad_class")
310+
@pytest.mark.usefixtures("_mock_basic_columns")
311+
@pytest.mark.usefixtures("_mock_linked_to_basic")
312+
def test_add_list_of_fluxes():
313+
# regression test for https://github.com/astropy/astroquery/issues/3185#issuecomment-2599191953
314+
simbad_instance = simbad.Simbad()
315+
with pytest.warns(DeprecationWarning, match=r"The notation \'flux\([UJ]\)\' is deprecated since 0.4.8 *"):
316+
simbad_instance.add_votable_fields("flux(U)", "flux(J)")
285317

286318

287319
def test_list_wildcards(capsys):

astroquery/simbad/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,29 @@ def _catch_deprecated_fields_with_arguments(votable_field):
3333
"Coordinates are now per default in degrees and in the ICRS frame.")
3434
if votable_field.startswith("id("):
3535
raise ValueError("Catalog Ids are no longer supported as an output option. "
36-
"A good replacement can be `~astroquery.simbad.SimbadClass.query_cat`")
36+
"Good replacements can be `~astroquery.simbad.SimbadClass.query_cat` "
37+
"or `~astroquery.simbad.SimbadClass.query_objectids`.")
3738
if votable_field.startswith("bibcodelist("):
3839
raise ValueError("Selecting a range of years for bibcode is removed. You can still use "
3940
"bibcodelist without parenthesis and get the full list of bibliographic references.")
4041
if votable_field in ["membership", "link_bibcode"]:
4142
raise ValueError("The hierarchy information is no longer an additional field. "
4243
"It has been replaced by the 'query_hierarchy' method.")
44+
if votable_field in ["pos", "posa"]:
45+
raise ValueError("Successive measurements of the positions are no longer stored "
46+
"in SIMBAD. The columns 'ra' and 'dec' contain the most precise "
47+
"measurement recorded by the SIMBAD team. For historical values, "
48+
"search within VizieR (accessible via 'astroquery.vizier').")
49+
if votable_field == "sp_nature":
50+
raise ValueError("Spectral nature is no longer stored in SIMBAD. You can get the "
51+
"of the spectral type classification in 'sp_bibcode'.")
52+
if votable_field == "typed_id":
53+
raise ValueError("'typed_id' is no longer a votable field. It is now added by "
54+
"default in 'query_objects' and 'query_region'")
55+
if votable_field in ["ubv", "uvby1", "uvby"]:
56+
raise ValueError("Magnitudes are now handled very differently in SIMBAD. See this "
57+
"section of the documentation: "
58+
"https://astroquery.readthedocs.io/en/latest/simbad/simbad_evolution.html#optical-filters")
4359

4460
# ----------------------------
4561
# Support wildcard argument

docs/simbad/simbad.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ For example to get the 10 biggest catalogs in SIMBAD, it looks like this:
383383

384384
Where you can remove ``TOP 10`` to get **all** the catalogues (there's a lot of them).
385385

386+
.. warning::
387+
This method is case-sensitive since version 0.4.8
388+
386389
Bibliographic queries
387390
---------------------
388391

0 commit comments

Comments
 (0)