Skip to content

Commit 1d76138

Browse files
authored
Merge pull request #3307 from bsipocz/MAINT_skybot_votable
BUG: fixing parsing special object names for skybot
2 parents 26d9e49 + bca156d commit 1d76138

File tree

9 files changed

+282
-281
lines changed

9 files changed

+282
-281
lines changed

CHANGES.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ heasarc
3535
- Heasarc.locate_data returns empty rows with an error in the error_message column if there are
3636
no data associated with that row rather than filtering it out. [#3275]
3737

38+
imcce
39+
^^^^^
40+
41+
- Fix parsing SkyBot results that include objects with special characters in
42+
their names. [#3307]
43+
44+
- Changing RuntimeError to NoResultsWarning when an empty result is
45+
returned. [#3307]
46+
3847
utils.tap
3948
^^^^^^^^^
4049

@@ -48,7 +57,7 @@ mast
4857

4958
- Added ``resolver`` parameter to query methods to specify the resolver to use when resolving object names to coordinates. [#3292]
5059

51-
- Added ``resolve_all`` parameter to ``MastClass.resolve_object`` to resolve object names and return
60+
- Added ``resolve_all`` parameter to ``MastClass.resolve_object`` to resolve object names and return
5261
coordinates for all available resolvers. [#3292]
5362

5463

astroquery/imcce/__init__.py

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99

1010
from astropy import config as _config
11-
import astropy.units as u
1211

1312

1413
class Conf(_config.ConfigNamespace):
@@ -31,45 +30,30 @@ class Conf(_config.ConfigNamespace):
3130
# SkyBoT configuration
3231

3332
# dictionary for field name and unit conversions using 'output=all`
34-
field_names = {'Num': 'Number',
35-
'Name': 'Name',
36-
'RA(h)': 'RA',
37-
'DE(deg)': 'DEC',
38-
'Class': 'Type',
39-
'Mv': 'V',
40-
'Err(arcsec)': 'posunc',
41-
'd(arcsec)': 'centerdist',
42-
'dRA(arcsec/h)': 'RA_rate',
43-
'dDEC(arcsec/h)': 'DEC_rate',
44-
'Dg(ua)': 'geodist',
45-
'Dh(ua)': 'heliodist',
46-
'Phase(deg)': 'alpha',
47-
'SunElong(deg)': 'elong',
48-
'x(au)': 'x',
49-
'y(au)': 'y',
50-
'z(au)': 'z',
51-
'vx(au/d)': 'vx',
52-
'vy(au/d)': 'vy',
53-
'vz(au/d)': 'vz',
54-
'Ref. Epoch(JD)': 'epoch'}
55-
field_units = {'RA': u.deg, # after conversion to deg
56-
'DEC': u.deg, # after conversion to deg
57-
'V': u.mag,
58-
'posunc': u.arcsec,
59-
'centerdist': u.arcsec,
60-
'RA_rate': u.arcsec/u.hour,
61-
'DEC_rate': u.arcsec/u.hour,
62-
'geodist': u.au,
63-
'heliodist': u.au,
64-
'alpha': u.degree,
65-
'elong': u.degree,
66-
'x': u.au,
67-
'y': u.au,
68-
'z': u.au,
69-
'vx': u.au/u.day,
70-
'vy': u.au/u.day,
71-
'vz': u.au/u.day,
72-
'epoch': u.day}
33+
field_names = {'num': 'Number',
34+
'name': 'Name',
35+
'ra': 'RA',
36+
'de': 'DEC',
37+
'class': 'Type',
38+
'magV': 'V',
39+
'errpos': 'posunc',
40+
'angdist': 'centerdist',
41+
'dracosdec': 'RA_rate',
42+
'ddec': 'DEC_rate',
43+
'dgeo': 'geodist',
44+
'dhelio': 'heliodist',
45+
'phase': 'alpha',
46+
'solelong': 'elong',
47+
'px': 'x',
48+
'py': 'y',
49+
'pz': 'z',
50+
'vx': 'vx',
51+
'vy': 'vy',
52+
'vz': 'vz',
53+
'jdref': 'epoch',
54+
'_raj2000': '_raj2000',
55+
'_decj2000': '_decj2000',
56+
'externallink': 'externallink'}
7357

7458

7559
conf = Conf()

astroquery/imcce/core.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
from io import BytesIO
77

88
from astropy.table import QTable, MaskedColumn
9-
from astropy.io import ascii
109
from astropy.time import Time
1110
from astropy.io.votable import parse
1211
import astropy.units as u
1312
from astropy.coordinates import SkyCoord, Angle
13+
from astropy.utils.exceptions import AstropyUserWarning
14+
15+
from astroquery.exceptions import NoResultsWarning
16+
from astroquery.query import BaseQuery
17+
from astroquery.utils import async_to_sync, commons
1418

15-
from ..query import BaseQuery
16-
from ..utils import async_to_sync, commons
1719
from . import conf
1820

1921
__all__ = ['Miriade', 'MiriadeClass', 'Skybot', 'SkybotClass']
@@ -599,7 +601,7 @@ def cone_search_async(self,
599601
+ str(int(find_comets)),
600602
'-refsys': 'EQJ2000',
601603
'-output': 'all',
602-
'-mime': 'text'}
604+
'-mime': 'votable'}
603605

604606
# check for diagnostic flags
605607
if get_query_payload:
@@ -611,42 +613,42 @@ def cone_search_async(self,
611613
params=request_payload,
612614
timeout=TIMEOUT, cache=cache)
613615

616+
response.raise_for_status()
617+
614618
self._uri = response.url
615619

616620
return response
617621

618622
def _parse_result(self, response, *, verbose=False):
619623
"""
620-
internal wrapper to parse queries
624+
internal wrapper to parse queries.
621625
"""
622626

623627
if self._get_raw_response:
624628
return response.text
625629

626-
# intercept error messages
627-
response_txt = response.text.split('\n')[2:-1]
628-
if len(response_txt) < 3 and len(response_txt[-1].split('|')) < 21:
629-
raise RuntimeError(response_txt[-1])
630+
with warnings.catch_warnings():
631+
# We deal with RA/DEC manually
632+
warnings.filterwarnings("ignore", category=AstropyUserWarning,
633+
message=r"column ra|(column de) has a unit but is kept as a MaskedColumn")
634+
results = QTable.read(BytesIO(response.content), format='votable')
630635

631-
names = response_txt[0].replace('# ', '').strip().split(' | ')
632-
results = ascii.read(response_txt[1:], delimiter='|',
633-
names=names, fast_reader=False)
634-
results = QTable(results)
636+
if len(results) == 0:
637+
warnings.warn("No objects were found with the query constraints.", NoResultsWarning)
638+
return results
635639

636640
# convert coordinates to degrees
637-
coo = SkyCoord(ra=results['RA(h)'], dec=results['DE(deg)'],
641+
coo = SkyCoord(ra=results['ra'], dec=results['de'],
638642
unit=(u.hourangle, u.deg), frame='icrs')
639-
results['RA(h)'] = coo.ra.deg
640-
results['DE(deg)'] = coo.dec.deg
643+
results['ra'] = coo.ra.deg
644+
results['ra'].unit = u.deg
645+
results['de'] = coo.dec.deg
646+
results['de'].unit = u.deg
641647

642648
colnames = results.columns[:]
643649
for fieldname in colnames:
644650
# apply field name change
645651
results.rename_column(fieldname, conf.field_names[fieldname])
646-
# apply unit, if available
647-
if conf.field_names[fieldname] in conf.field_units:
648-
results[conf.field_names[fieldname]].unit = conf.field_units[
649-
conf.field_names[fieldname]]
650652

651653
# convert object numbers to int
652654
# unnumbered asteroids return as non numeric values ('-')

0 commit comments

Comments
 (0)