Skip to content

Commit 282c6b5

Browse files
Fix bugs, complete the tests and fill more documentation.
1 parent 183e692 commit 282c6b5

File tree

7 files changed

+5317
-29
lines changed

7 files changed

+5317
-29
lines changed

astroquery/ipac/irsa/most/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class Conf(_config.ConfigNamespace):
4444
conf = Conf()
4545

4646

47-
from .core import MOST, MOSTClass
47+
from .core import Most, MOSTClass
4848

49-
__all__ = ['MOST', 'MOSTClass',
49+
__all__ = ['Most', 'MOSTClass',
5050
'Conf', 'conf',
5151
]

astroquery/ipac/irsa/most/core.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,23 @@
317317
+-------------------+------------------+-------+------------------------------+
318318
319319
"""
320+
import io
320321
import re
321322

322323
from bs4 import BeautifulSoup
323324

325+
from astropy.io import votable
324326
from astropy.table import Table, Column
325327

326-
import astroquery as aq
327328
from astroquery import log
329+
from astroquery.query import BaseQuery
330+
from astroquery.utils import class_or_instance
328331
from astroquery.exceptions import RemoteServiceError, NoResultsWarning
329332

330333
from . import conf
331334

332335

333-
class MOSTClass(aq.query.BaseQuery):
336+
class MOSTClass(BaseQuery):
334337
URL = conf.server
335338
TIMEOUT = conf.timeout
336339

@@ -500,11 +503,6 @@ def _validate_input(self, params):
500503
f"`mpc_input` or `manual_input`, got {input_type} instead."
501504
)
502505

503-
# We're not supporting parsing anything else except full output atm
504-
output_mode = params.get("output_mode", False)
505-
if not output_mode or output_mode != "Full":
506-
raise ValueError("Only `Full` output mode is currently supported.")
507-
508506
def _parse_full_regular_response(self, response, withTarballs=False):
509507
"""
510508
Parses the response when output type is set to `Regular` or `Full`.
@@ -531,8 +529,8 @@ def _parse_full_regular_response(self, response, withTarballs=False):
531529
tarball archives of the fits and region images.
532530
"""
533531
retdict = {}
534-
html = BeautifulSoup(response.content)
535-
download_tags = html.find_all("a", text=re.compile(".*Download.*"))
532+
html = BeautifulSoup(response.content, "html5lib")
533+
download_tags = html.find_all("a", string=re.compile(".*Download.*"))
536534

537535
# this is "Download Results Table (above)"
538536
results_response = self._request("GET", download_tags[0]["href"])
@@ -594,7 +592,7 @@ def query(self, get_query_payload=False, **query_params):
594592
if qparams["output_mode"] in ("Brief", "Gator"):
595593
return Table.read(response.text, format="ipac")
596594
elif qparams["output_mode"] == "VOTable":
597-
return aio.votable.parse(response.content)
595+
return votable.parse(io.BytesIO(response.content))
598596
else:
599597
return self._parse_full_regular_response(response, qparams["fits_region_files"])
600598

astroquery/ipac/irsa/tests/data/MOST_VOTable.xml

Lines changed: 210 additions & 0 deletions
Large diffs are not rendered by default.

astroquery/ipac/irsa/tests/data/MOST_full_with_tarballs.html

Lines changed: 4907 additions & 0 deletions
Large diffs are not rendered by default.

astroquery/ipac/irsa/tests/data/MOST_regular_output.html renamed to astroquery/ipac/irsa/tests/data/MOST_regular.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,8 +4681,8 @@ <h2>Orbital Path Plot for Asteroid: 12 Victoria</h2></center>
46814681
<br>
46824682
<h3><hr>
46834683
</h3><h2>Download Files: </h2>
4684-
<a href="https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid26504/results.tbl" target="_blank">Download Results Table (above)</a>
4685-
<br><br><a href="https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid26504/imgframes_matched_final_table.tbl" target="_blank">Download Image Metadata with a Matched Object Position Table</a>
4684+
<a href="most_results_table.tbl" target="_blank">Download Results Table (above)</a>
4685+
<br><br><a href="most_imgframes_matched_final_table.tbl" target="_blank">Download Image Metadata with a Matched Object Position Table</a>
46864686
<br><br><a href="https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid26504/ds9region/ds9_orbit_path.reg" target="_blank">Download DS9 Region File with the Orbital Path</a>
46874687
<br><br><a href="https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid26504" target="_blank">List of All Created Files</a>
46884688
<br><br>
@@ -4700,4 +4700,4 @@ <h3><hr>
47004700
<hr>
47014701

47024702

4703-
<div id="expandedArea" class="rootStyle"></div></body></html>
4703+
<div id="expandedArea" class="rootStyle"></div></body></html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
\output_url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid12682"
2+
\catalog = "wise_merge"
3+
\user_input_begin_time = "2014-05-01"
4+
\user_input_end_time = "2014-05-30"
5+
\object_name = "12 Victoria (A850 RA)"
6+
\element_epoch = "56778.0000 (2014-May-01 00:00:00.0000)"
7+
\eccentricity = " 0.221364531529095"
8+
\inclination = " 8.368662061690546"
9+
\argument_perihelion = "69.552208865051483"
10+
\ascending_node = "235.490911873760894"
11+
\semimajor_axis = " 2.333774627713947"
12+
\mean_anomaly = "349.752560575505981"
13+
\magnitude_parameters = " 7.34 0.00"
14+
\job_time_stamp = "Wed Feb 8 14:43:58 2023"
15+
| mjd|scan_id|frame_num| ra| dec|
16+
| double| char| int| double| double|
17+
56798.29927097 49025b 143 330.347004 -2.774481
18+
56806.45842962 49273b 134 333.539704 -0.779309
19+
56806.59009666 49277b 135 333.589056 -0.747249
20+
56806.72163647 49281b 134 333.638285 -0.715250
21+
56806.85330360 49285b 135 333.687494 -0.683205
22+
56806.98484347 49289b 134 333.736580 -0.651221
Lines changed: 165 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3+
import io
34
import os
4-
import re
5-
import numpy as np
6-
75
import pytest
8-
from astropy.coordinates import SkyCoord
9-
from astropy.table import Table
10-
import astropy.units as u
116

7+
#from astropy.coordinates import SkyCoord
8+
#from astropy.table import Table
9+
#import astropy.units as u
10+
from astropy.io import votable
11+
from astropy.table import Table
1212
from astroquery.utils.mocks import MockResponse
13-
from astroquery.ipac.most import Most, conf
13+
from astroquery.ipac.irsa.most import Most, conf
14+
from astropy.utils.diff import report_diff_values
15+
1416

15-
DATA_FILES = "MOST_regular_outputs.html"
17+
DATA_FILES = {
18+
"Regular": "MOST_regular.html",
19+
"Full": "MOST_full_with_tarballs.html",
20+
"VOTable": "MOST_VOTable.xml",
21+
"Brief": "most_results_table.tbl",
22+
"Gator": "most_gator_table.tbl"
23+
}
1624

1725

1826
def data_path(filename):
@@ -27,15 +35,158 @@ def patch_get(request):
2735
return mp
2836

2937

30-
def get_mockreturn(method, url, params=None, timeout=10, cache=False, **kwargs):
31-
filename = data_path(DATA_FILES)
38+
def get_mockreturn(method=None, url=None, data=None, timeout=120, **kwargs):
39+
if method == "GET":
40+
filename = data_path(url)
41+
else:
42+
filename = data_path(DATA_FILES[data["output_mode"]])
3243
with open(filename, 'rb') as infile:
3344
content = infile.read()
3445
return MockResponse(content, **kwargs)
3546

3647

37-
def test_get_regular():
38-
response = Most.query()
39-
breakpoint()
48+
def test_validation(patch_get):
49+
with pytest.raises(ValueError):
50+
Most.query()
51+
52+
with pytest.raises(ValueError):
53+
Most.query(catalog="wise_allsky_4band")
54+
55+
# make sure no funny business happens with
56+
# overwriting of default values
57+
Most.query(
58+
catalog="wise_allsky_4band",
59+
obj_name="Victoria"
60+
)
61+
Most.query(
62+
catalog="wise_allsky_4band",
63+
obj_name="Victoria",
64+
input_type="name_input"
65+
)
66+
67+
with pytest.raises(ValueError):
68+
# fails because insufficient orbital parameters specified
69+
Most.query(
70+
catalog="wise_allsky_4band",
71+
output_mode="Brief",
72+
input_type="manual_input",
73+
obj_type="Asteroid",
74+
perih_dist=1.5,
75+
eccentricity=0.5
76+
)
77+
78+
Most.query(
79+
catalog="wise_allsky_4band",
80+
output_mode="Brief",
81+
input_type="manual_input",
82+
obj_type="Asteroid",
83+
semimajor_axis=2.68,
84+
eccentricity=0.33,
85+
)
86+
87+
with pytest.raises(ValueError):
88+
# Comets require perihel_dist keyword
89+
# instead of smimajor_axis
90+
Most.query(
91+
catalog="wise_allsky_4band",
92+
output_mode="Brief",
93+
input_type="manual_input",
94+
obj_type="Comet",
95+
semimajor_axis=2.68,
96+
eccentricity=0.33
97+
)
98+
99+
with pytest.raises(ValueError):
100+
# object type is case sensitive
101+
Most.query(
102+
catalog="wise_allsky_4band",
103+
output_mode="Brief",
104+
input_type="manual_input",
105+
obj_type="comet",
106+
semimajor_axis=2.68,
107+
eccentricity=0.33
108+
)
109+
110+
with pytest.raises(ValueError):
111+
# missing mpc_data and obj_type
112+
Most.query(
113+
catalog="wise_allsky_4band",
114+
output_mode="Brief",
115+
input_type="mpc_input"
116+
)
117+
118+
Most.query(
119+
catalog="wise_allsky_4band",
120+
output_mode="Brief",
121+
input_type="mpc_input",
122+
obj_type="Asteroid",
123+
mpc_data="K10N010+2010+08+16.1477+1.494525+0.533798+153.4910+113.2118+12.8762+20100621+17.0+4.0+P/2010+N1+(WISE)+MPC+75712"
124+
)
125+
126+
127+
def test_regular(patch_get):
128+
response = Most.query(obj_name="Victoria")
129+
130+
assert "results" in response
131+
assert "metadata" in response
132+
assert "region" in response
133+
assert "fits_tarball" not in response
134+
assert "region_tarball" not in response
135+
136+
results = Table.read(data_path("most_results_table.tbl"), format="ipac")
137+
metadata = Table.read(data_path("most_imgframes_matched_final_table.tbl"), format="ipac")
138+
url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/ds9region/ds9_orbit_path.reg"
139+
140+
silent_stream = io.StringIO()
141+
assert report_diff_values(results, response["results"], silent_stream)
142+
assert report_diff_values(metadata, response["metadata"], silent_stream)
143+
assert url == response["region"]
144+
145+
146+
def test_get_full_with_tarballs(patch_get):
147+
response = Most.query(
148+
obj_name="Victoria",
149+
output_mode="Full",
150+
fits_region_files=True
151+
)
152+
153+
assert "results" in response
154+
assert "metadata" in response
155+
assert "region" in response
156+
assert "fits_tarball" in response
157+
assert "region_tarball" in response
158+
159+
results = Table.read(data_path("most_results_table.tbl"), format="ipac")
160+
metadata = Table.read(data_path("most_imgframes_matched_final_table.tbl"), format="ipac")
161+
url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/ds9region/ds9_orbit_path.reg"
162+
region_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/ds9region_A850RA.tar"
163+
fits_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194/MOST/pid10499/fitsimage_A850RA.tar.gz"
164+
165+
silent_stream = io.StringIO()
166+
assert report_diff_values(results, response["results"], silent_stream)
167+
assert report_diff_values(metadata, response["metadata"], silent_stream)
168+
assert url == response["region"]
169+
assert region_tar == response["region_tarball"]
170+
assert fits_tar == response["fits_tarball"]
171+
172+
173+
def test_votable(patch_get):
174+
response = Most.query(
175+
output_mode="VOTable",
176+
obj_name="Victoria"
177+
)
178+
179+
vtbl = votable.parse(data_path("MOST_VOTable.xml"))
180+
silent_stream = io.StringIO()
181+
assert report_diff_values(response, vtbl, silent_stream)
182+
183+
184+
def test_gator(patch_get):
185+
response = Most.query(
186+
output_mode="Gator",
187+
obj_name="Victoria"
188+
)
40189

41-
a = 1
190+
tbl = Table.read(data_path("most_gator_table.tbl"), format="ipac")
191+
silent_stream = io.StringIO()
192+
assert report_diff_values(tbl, response, silent_stream)

0 commit comments

Comments
 (0)