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

Update MPC query to parse 3 digit precision motion columns #3026

Merged
merged 10 commits into from
Jun 27, 2024
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mpc
^^^

- Parse star catalog information when querying observations database [#2957]
- Parse ephemeris with sky motion with three digit precision [#3019]
- Raise NoResultWarining when empty ephemeris reponse is returned [#3019]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NoResultWarning -> EmptyResponseError

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, instead of referencing the issues, reference the PR #3026.


linelists.cdms
^^^^^^^^^^^^^^
Expand Down
27 changes: 16 additions & 11 deletions astroquery/mpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ..utils import async_to_sync, class_or_instance
from ..exceptions import InvalidQueryError, EmptyResponseError


__all__ = ['MPCClass']


Expand Down Expand Up @@ -1052,7 +1051,6 @@ def _parse_result(self, result, **kwargs):
raise InvalidQueryError(content)
table_end = content.find('</pre>')
text_table = content[table_start + 5:table_end]

SKY = 'raty=a' in result.request.body
HELIOCENTRIC = 'raty=s' in result.request.body
GEOCENTRIC = 'raty=G' in result.request.body
Expand All @@ -1061,12 +1059,20 @@ def _parse_result(self, result, **kwargs):
# find column headings
if SKY:
# slurp to newline after "h m s"
i = text_table.index('\n', text_table.index('h m s')) + 1
# raise EmptyResponseError if no ephemeris lines are found in the query response
try:
i = text_table.index('\n', text_table.index('h m s')) + 1
except ValueError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e is not used, so probably shouldn't be defined.

raise EmptyResponseError(content)
jurezakrajsek marked this conversation as resolved.
Show resolved Hide resolved
columns = text_table[:i]
data_start = columns.count('\n') - 1
else:
# slurp to newline after "JD_TT"
i = text_table.index('\n', text_table.index('JD_TT')) + 1
# raise EmptyResponseError if no ephemeris lines are found in the query response
try:
i = text_table.index('\n', text_table.index('JD_TT')) + 1
except ValueError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test that covers this exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkelley
It is difficult to create a remote test for this case as I can no longer repeate this issue by querying the MPC for the same object and date that i described in the issu (looks like something was not working on the MPC side at that time). I'm not able to find a different target or date where such a response would be returned. But if it happens I can add a remote test for this case also.

So I have manually created the test data file by removing the ephemeris lines from the result table and included a test for this in local data test_mpc.py

def test_get_ephemeris_by_name_empty(patch_post):
    with pytest.raises(NoResultsWarning):
        mpc.core.MPC.get_ephemeris('340P', location='G37')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the manual test is OK. I can't think of a successful remote test case that should return empty lines. Brigitta's impactor example is an interesting idea, but the service clearly doesn't behave that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a successful remote test case that should return empty line

well, that case I would revert my previous opinion about the warning and say that it should loudly error as an indication of something is broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkelley, @bsipocz
So we change back to EmptyResponseError?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, EmptyResponseError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkelley
I have corrected it back to EmptyResponseerror

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Finally, e is not used, so probably shouldn't be defined.

raise EmptyResponseError(content)
columns = text_table[:i]
data_start = columns.count('\n') - 1

Expand All @@ -1088,24 +1094,24 @@ def _parse_result(self, result, **kwargs):
elif 's=s' in result.request.body: # sky Motion
names += ('dRA cos(Dec)', 'dDec')
units += ('arcsec/h', 'arcsec/h')
col_starts += (73, 81)
col_ends += (80, 89)
col_starts += (73, 82)
col_ends += (81, 91)

if 'Moon' in columns:
# table includes Alt, Az, Sun and Moon geometry
names += ('Azimuth', 'Altitude', 'Sun altitude', 'Moon phase',
'Moon distance', 'Moon altitude')
col_starts += tuple((col_ends[-1] + offset for offset in
(2, 9, 14, 20, 27, 33)))
(1, 8, 13, 19, 26, 32)))
col_ends += tuple((col_ends[-1] + offset for offset in
(8, 13, 19, 26, 32, 37)))
(7, 12, 18, 25, 31, 36)))
units += ('deg', 'deg', 'deg', None, 'deg', 'deg')
if 'Uncertainty' in columns:
names += ('Uncertainty 3sig', 'Unc. P.A.')
col_starts += tuple((col_ends[-1] + offset for offset in
(2, 11)))
(1, 10)))
col_ends += tuple((col_ends[-1] + offset for offset in
(10, 16)))
(9, 15)))
units += ('arcsec', 'deg')
if ">Map</a>" in first_row and self._unc_links:
names += ('Unc. map', 'Unc. offsets')
Expand Down Expand Up @@ -1171,7 +1177,6 @@ def _parse_result(self, result, **kwargs):
else:
# convert from MPES string to Time
tab['JD'] = Time(tab['JD'], format='jd', scale='tt')

return tab

elif self.query_type == 'observations':
Expand Down
75 changes: 75 additions & 0 deletions astroquery/mpc/tests/data/2024AA_ephemeris_500-a-t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Minor Planet Ephemeris Service: Query Results</title>
</head>
<body>
<h1>Minor Planet Ephemeris Service: Query Results</h1>
Below are the results of your request from the Minor Planet Center's
Minor Planet Ephemeris Service.
<p>
Newly designated objects may take up to 1 day to show up in this service.
</p>
<p>
Orbits and ephemerides of unnumbered NEOs are up-to-date. Other orbits are in
the process of being refreshed.
</p>
<p>
The current system is not completely reliable in the case of objects
with very-close approaches with the Earth.
<br></br> We are working on a completely new system,
but for the time being we encourage the users to double check
the results with other ephemeris generators when the object is very close to
Earth.
</p>
Ephemerides are for
the geocenter.
<p><hr><p>
<p>
<b>2024 AA</b>
<p> Number of variant orbits available: 11</p>
<p>Perturbed ephemeris below is based on
1-day-arc
unperturbed elements from
<i>MPO</i> 793554.
Last observed on 2024 Jan. 2.
<p><a href="https://www.minorplanetcenter.net/iau/info/FurtherObs.html">Further observations?</a> Useful for orbit improvement.
<p><pre>
K24A00A [H=27.41]
Date UT R.A. (J2000) Decl. Delta r El. Ph. V Sky Motion Uncertainty info
h m s "/min "/min 3-sig/" P.A.
2024 06 15 000000 23 28 41.6 -05 17 07 1.451 1.819 93.3 33.9 30.9 +0.17 +0.006 169 063.5 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460476.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460476.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 16 000000 23 28 56.7 -05 17 05 1.447 1.829 94.2 33.6 30.9 +0.15 -0.003 172 063.5 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460477.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460477.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 17 000000 23 29 09.8 -05 17 16 1.444 1.838 95.1 33.4 30.9 +0.13 -0.013 175 063.6 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460478.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460478.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 18 000000 23 29 20.8 -05 17 41 1.440 1.848 96.1 33.1 30.9 +0.10 -0.022 178 063.6 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460479.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460479.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 19 000000 23 29 29.9 -05 18 19 1.437 1.858 97.0 32.9 30.9 +0.083 -0.031 181 063.6 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460480.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460480.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 20 000000 23 29 36.9 -05 19 11 1.433 1.867 97.9 32.6 30.9 +0.062 -0.041 184 063.7 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460481.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460481.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 21 000000 23 29 41.8 -05 20 16 1.429 1.877 98.8 32.3 30.9 +0.040 -0.050 187 063.7 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460482.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460482.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 22 000000 23 29 44.6 -05 21 35 1.425 1.886 99.8 32.1 30.9 +0.019 -0.059 190 063.7 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460483.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460483.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 23 000000 23 29 45.4 -05 23 07 1.422 1.896 100.8 31.8 30.9 -0.003 -0.069 193 063.8 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460484.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460484.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 24 000000 23 29 44.0 -05 24 54 1.418 1.905 101.7 31.5 30.9 -0.025 -0.079 196 063.8 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460485.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460485.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 25 000000 23 29 40.5 -05 26 54 1.414 1.914 102.7 31.2 30.9 -0.048 -0.088 199 063.8 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460486.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460486.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 26 000000 23 29 34.8 -05 29 08 1.410 1.924 103.7 30.9 30.9 -0.070 -0.098 202 063.9 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460487.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460487.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 27 000000 23 29 27.0 -05 31 37 1.406 1.933 104.7 30.6 30.9 -0.093 -0.11 205 063.9 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460488.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460488.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 28 000000 23 29 16.9 -05 34 20 1.403 1.942 105.7 30.3 30.9 -0.12 -0.12 208 064.0 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460489.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460489.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 29 000000 23 29 04.7 -05 37 17 1.399 1.952 106.7 29.9 30.9 -0.14 -0.13 211 064.0 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460490.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460490.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 06 30 000000 23 28 50.2 -05 40 28 1.395 1.961 107.8 29.6 30.9 -0.16 -0.14 214 064.0 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460491.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460491.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 07 01 000000 23 28 33.5 -05 43 54 1.391 1.970 108.8 29.2 30.9 -0.18 -0.15 217 064.1 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460492.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460492.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 07 02 000000 23 28 14.5 -05 47 34 1.387 1.979 109.8 28.9 30.9 -0.21 -0.16 220 064.1 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460493.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460493.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 07 03 000000 23 27 53.3 -05 51 29 1.384 1.988 110.9 28.5 30.9 -0.23 -0.17 223 064.2 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460494.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460494.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 07 04 000000 23 27 29.7 -05 55 38 1.380 1.997 112.0 28.2 30.9 -0.26 -0.18 226 064.2 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460495.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460495.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
2024 07 05 000000 23 27 03.9 -06 00 02 1.376 2.006 113.0 27.8 30.9 -0.28 -0.19 229 064.2 / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460496.50000&Ext=VAR2">Map</a> / <a href="https://cgi.minorplanetcenter.net/cgi-bin/uncertaintymap.cgi?Obj=K24A00A&JD=2460496.50000&Ext=VAR2&Form=Y&OC=500">Offsets</a>
</pre>
<p><hr><p>
These calculations have been performed on the
<a href="http://www.minorplanetcenter.net/iau/Ack/TamkinFoundation.html">Tamkin
Foundation Computing Network</a>.
<p><hr>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img border="0"
src="http://www.w3.org/Icons/valid-html401"
alt="Valid HTML 4.01!" height="31" width="88"></a>
</p>
</body>
</html>
Loading
Loading