Skip to content

Commit db603f7

Browse files
jespinosaar“Javier
authored andcommitted
EHSTPCR-901: conesearch VOTable not being saved
1 parent 293617e commit db603f7

File tree

3 files changed

+371
-13
lines changed

3 files changed

+371
-13
lines changed

astroquery/esa/hubble/core.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,42 @@ def get_postcard(self, observation_id, calibration_level="RAW",
215215
shutil.move(response, filename)
216216

217217
def cone_search(self, coordinates, radius=0.0, filename=None,
218-
output_format='votable', cache=True):
218+
output_format='votable', save=False, cache=True):
219219
"""
220+
To execute a cone search defined by a coordinate and a radius
221+
222+
Parameters
223+
----------
224+
coordinates : astropy.coordinate, mandatory
225+
coordinates of the center in the cone search
226+
radius : float, default 0
227+
radius in arcmin of the cone_search
228+
filename : str, default None
229+
Path and name of the file to store the results.
230+
If the filename is defined, the file will be
231+
automatically saved
232+
output_format : string
233+
results format. Options are:
234+
'votable': str, binary VOTable format
235+
'csv': str, comma-separated values format
236+
save : bool
237+
optional, default 'False'
238+
Flag to save the result in a file. If the filename
239+
is not defined, it will use a formatted name to save
240+
the file
241+
cache : bool
242+
optional, default 'True'
243+
Flag to save the results in the local cache
244+
245+
Returns
246+
-------
247+
astropy.table.Table with the result of the cone_search
220248
"""
221249
coord = self._getCoordInput(coordinates, "coordinate")
222-
radiusInGrades = float(radius/60) # Converts to degrees
250+
radius_in_grades = float(radius/60) # Converts to degrees
223251

224-
raHours, dec = commons.coord_to_radec(coord)
225-
ra = raHours * 15.0 # Converts to degrees
252+
ra_hours, dec = commons.coord_to_radec(coord)
253+
ra = ra_hours * 15.0 # Converts to degrees
226254
payload = {"RESOURCE_CLASS": "OBSERVATION",
227255
"ADQLQUERY": "SELECT DISTINCT OBSERVATION,OBSERVATION.TYPE,"
228256
"TARGET.MOVING_TARGET"
@@ -243,22 +271,26 @@ def cone_search(self, coordinates, radius=0.0, filename=None,
243271
" AND INTERSECTS(CIRCLE('ICRS', {0}, {1}, {2}"
244272
"),POSITION)=1 AND PLANE.MAIN_SCIENCE_PLANE='true' "
245273
"ORDER BY PROPOSAL.PROPOSAL_ID "
246-
"DESC".format(str(ra), str(dec), str(radiusInGrades)),
274+
"DESC".format(str(ra), str(dec), str(radius_in_grades)),
247275
"RETURN_TYPE": str(output_format)}
248276
response = self._request('GET',
249277
self.metadata_url,
250278
params=payload,
279+
save=save or filename is not None,
251280
cache=cache,
252281
timeout=self.TIMEOUT)
253-
254-
if filename is None:
255-
filename = "cone." + str(output_format)
256-
257282
if response is None:
258283
table = None
259284
else:
260-
fileobj = BytesIO(response.content)
261-
table = Table.read(fileobj, format=output_format)
285+
if save or filename is not None:
286+
if filename is None:
287+
filename = "cone." + str(output_format)
288+
shutil.move(response, filename)
289+
table = Table.read(filename, format=output_format)
290+
log.info("File has been saved in " + os.path.abspath(filename))
291+
else:
292+
fileobj = BytesIO(response.content)
293+
table = Table.read(fileobj, format=output_format)
262294
# TODO: add "correct units" material here
263295

264296
return table
@@ -504,7 +536,7 @@ def get_hap_observations(self, async_job=True, output_file=None,
504536
table = job.get_results()
505537
except Exception:
506538
raise ValueError('There are not HAP observations in this DB')
507-
539+
508540
return table
509541

510542
def get_hap_proposals(self, async_job=True, output_file=None,

0 commit comments

Comments
 (0)