@@ -215,14 +215,42 @@ def get_postcard(self, observation_id, calibration_level="RAW",
215
215
shutil .move (response , filename )
216
216
217
217
def cone_search (self , coordinates , radius = 0.0 , filename = None ,
218
- output_format = 'votable' , cache = True ):
218
+ output_format = 'votable' , save = False , cache = True ):
219
219
"""
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
220
248
"""
221
249
coord = self ._getCoordInput (coordinates , "coordinate" )
222
- radiusInGrades = float (radius / 60 ) # Converts to degrees
250
+ radius_in_grades = float (radius / 60 ) # Converts to degrees
223
251
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
226
254
payload = {"RESOURCE_CLASS" : "OBSERVATION" ,
227
255
"ADQLQUERY" : "SELECT DISTINCT OBSERVATION,OBSERVATION.TYPE,"
228
256
"TARGET.MOVING_TARGET"
@@ -243,22 +271,26 @@ def cone_search(self, coordinates, radius=0.0, filename=None,
243
271
" AND INTERSECTS(CIRCLE('ICRS', {0}, {1}, {2}"
244
272
"),POSITION)=1 AND PLANE.MAIN_SCIENCE_PLANE='true' "
245
273
"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 )),
247
275
"RETURN_TYPE" : str (output_format )}
248
276
response = self ._request ('GET' ,
249
277
self .metadata_url ,
250
278
params = payload ,
279
+ save = save or filename is not None ,
251
280
cache = cache ,
252
281
timeout = self .TIMEOUT )
253
-
254
- if filename is None :
255
- filename = "cone." + str (output_format )
256
-
257
282
if response is None :
258
283
table = None
259
284
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 )
262
294
# TODO: add "correct units" material here
263
295
264
296
return table
@@ -504,7 +536,7 @@ def get_hap_observations(self, async_job=True, output_file=None,
504
536
table = job .get_results ()
505
537
except Exception :
506
538
raise ValueError ('There are not HAP observations in this DB' )
507
-
539
+
508
540
return table
509
541
510
542
def get_hap_proposals (self , async_job = True , output_file = None ,
0 commit comments