@@ -185,13 +185,13 @@ def _select_composite(self, observation_id):
185
185
return oids
186
186
187
187
def __validate_product_type (self , product_type ):
188
- if (product_type not in self .product_types ):
188
+ if (product_type not in self .product_types ):
189
189
raise ValueError ("This product_type is not allowed" )
190
190
191
191
def _get_product_filename (self , product_type , filename ):
192
- if (product_type == "PRODUCT" ):
192
+ if (product_type == "PRODUCT" ):
193
193
return filename
194
- elif (product_type == "SCIENCE_PRODUCT" ):
194
+ elif (product_type == "SCIENCE_PRODUCT" ):
195
195
log .info ("This is a SCIENCE_PRODUCT, the filename will be "
196
196
"renamed to " + filename + ".fits.gz" )
197
197
return filename + ".fits.gz"
@@ -328,25 +328,25 @@ def cone_search(self, coordinates, radius, filename=None,
328
328
radius_in_grades = radius .to (units .deg ).value
329
329
ra = coord .ra .deg
330
330
dec = coord .dec .deg
331
- query = "select o.observation_id, " \
332
- "o.start_time, o.end_time, o.start_time_mjd, " \
333
- "o.end_time_mjd, o.exposure_duration, o.release_date, " \
334
- "o.run_id, o.program_id, o.set_id, o.collection, " \
335
- "o.members_number, o.instrument_configuration, " \
336
- "o.instrument_name, o.obs_type, o.target_moving, " \
337
- "o.target_name, o.target_description, o.proposal_id, " \
338
- "o.pi_name, prop.title, pl.metadata_provenance, " \
339
- "pl.data_product_type, pl.software_version, pos.ra, " \
340
- "pos.dec, pos.gal_lat, pos.gal_lon, pos.ecl_lat, " \
341
- "pos.ecl_lon, pos.fov_size, en.wave_central, " \
342
- "en.wave_bandwidth, en.wave_max, en.wave_min, " \
343
- "en.filter from ehst.observation o join ehst.proposal " \
344
- "prop on o.proposal_id=prop.proposal_id join ehst.plane " \
345
- "pl on pl.observation_id=o.observation_id join " \
346
- "ehst.position pos on pos.plane_id = pl.plane_id join " \
347
- "ehst.energy en on en.plane_id=pl.plane_id where " \
348
- "pl.main_science_plane='true' and 1=CONTAINS(POINT('ICRS', " \
349
- "pos.ra, pos.dec),CIRCLE('ICRS', {0}, {1}, {2})) order " \
331
+ query = "select o.observation_id, " \
332
+ "o.start_time, o.end_time, o.start_time_mjd, " \
333
+ "o.end_time_mjd, o.exposure_duration, o.release_date, " \
334
+ "o.run_id, o.program_id, o.set_id, o.collection, " \
335
+ "o.members_number, o.instrument_configuration, " \
336
+ "o.instrument_name, o.obs_type, o.target_moving, " \
337
+ "o.target_name, o.target_description, o.proposal_id, " \
338
+ "o.pi_name, prop.title, pl.metadata_provenance, " \
339
+ "pl.data_product_type, pl.software_version, pos.ra, " \
340
+ "pos.dec, pos.gal_lat, pos.gal_lon, pos.ecl_lat, " \
341
+ "pos.ecl_lon, pos.fov_size, en.wave_central, " \
342
+ "en.wave_bandwidth, en.wave_max, en.wave_min, " \
343
+ "en.filter from ehst.observation o join ehst.proposal " \
344
+ "prop on o.proposal_id=prop.proposal_id join ehst.plane " \
345
+ "pl on pl.observation_id=o.observation_id join " \
346
+ "ehst.position pos on pos.plane_id = pl.plane_id join " \
347
+ "ehst.energy en on en.plane_id=pl.plane_id where " \
348
+ "pl.main_science_plane='true' and 1=CONTAINS(POINT('ICRS', " \
349
+ "pos.ra, pos.dec),CIRCLE('ICRS', {0}, {1}, {2})) order " \
350
350
"by prop.proposal_id desc" .format (str (ra ), str (dec ),
351
351
str (radius_in_grades ))
352
352
if verbose :
@@ -455,9 +455,9 @@ def cone_search_criteria(self, radius, target=None,
455
455
radius_in_grades = Angle (radius , units .arcmin ).deg
456
456
else :
457
457
radius_in_grades = radius .to (units .deg ).value
458
- cone_query = "1=CONTAINS(POINT('ICRS', pos.ra, pos.dec)," \
459
- "CIRCLE('ICRS', {0}, {1}, {2}))" .\
460
- format (str (ra ), str (dec ), str (radius_in_grades ))
458
+ cone_query = "1=CONTAINS(POINT('ICRS', pos.ra, pos.dec)," \
459
+ "CIRCLE('ICRS', {0}, {1}, {2}))" . \
460
+ format (str (ra ), str (dec ), str (radius_in_grades ))
461
461
query = "{}{})" .format (crit_query , cone_query )
462
462
if verbose :
463
463
log .info (query )
@@ -487,8 +487,8 @@ def _query_tap_target(self, target):
487
487
def query_metadata (self , output_format = 'votable' , verbose = False ):
488
488
return
489
489
490
- def query_target (self , name , filename = None , output_format = 'votable' ,
491
- verbose = False ):
490
+ def query_target (self , name , filename = None , async_job = False ,
491
+ output_format = 'votable' , radius = None ):
492
492
"""
493
493
It executes a query over EHST and download the xml with the results.
494
494
@@ -510,28 +510,18 @@ def query_target(self, name, filename=None, output_format='votable',
510
510
Table with the result of the query. It downloads metadata as a file.
511
511
"""
512
512
513
- params = {"RESOURCE_CLASS" : "OBSERVATION" ,
514
- "USERNAME" : "ehst-astroquery" ,
515
- "SELECTED_FIELDS" : "OBSERVATION" ,
516
- "QUERY" : "(TARGET.TARGET_NAME=='" + name + "')" ,
517
- "RETURN_TYPE" : str (output_format )}
518
- response = self ._request ('GET' , self .metadata_url , save = True ,
519
- cache = True ,
520
- params = params )
513
+ if radius is None :
514
+ radius = 7
521
515
522
- if verbose :
523
- log .info (self .metadata_url + "?RESOURCE_CLASS=OBSERVATION&"
524
- "SELECTED_FIELDS=OBSERVATION&QUERY=(TARGET.TARGET_NAME"
525
- "=='" + name + "')&USERNAME=ehst-astroquery&"
526
- "RETURN_TYPE=" + str (output_format ))
527
- log .info (self .copying_string .format (filename ))
528
- if filename is None :
529
- filename = "target.xml"
516
+ ra , dec = self ._query_tap_target (name )
517
+ coordinates = SkyCoord (ra = str (ra ), dec = str (dec ), unit = "deg" , frame = 'icrs' )
530
518
531
- shutil .move (response , filename )
519
+ if async_job :
520
+ table = self .cone_search (coordinates , radius , filename = filename , output_format = output_format , async_job = True )
521
+ else :
522
+ table = self .cone_search (coordinates , radius , filename = filename , output_format = output_format )
532
523
533
- return modelutils .read_results_table_from_file (filename ,
534
- str (output_format ))
524
+ return table
535
525
536
526
def query_hst_tap (self , query , async_job = False , output_file = None ,
537
527
output_format = "votable" , verbose = False ):
@@ -562,7 +552,7 @@ def query_hst_tap(self, query, async_job=False, output_file=None,
562
552
output_format = output_format ,
563
553
verbose = False ,
564
554
dump_to_file = output_file
565
- is not None )
555
+ is not None )
566
556
else :
567
557
job = self ._tap .launch_job (query = query , output_file = output_file ,
568
558
output_format = output_format ,
@@ -647,9 +637,9 @@ def query_criteria(self, calibration_level=None,
647
637
parameters .append ("(o.instrument_configuration LIKE '%{}%')"
648
638
.format ("%' OR o.instrument_configuration "
649
639
"LIKE '%" .join (filters )))
650
- query = "select o.*, p.calibration_level, p.data_product_type, " \
651
- "pos.ra, pos.dec from ehst.observation AS o JOIN " \
652
- "ehst.plane as p on o.observation_uuid=p.observation_uuid " \
640
+ query = "select o.*, p.calibration_level, p.data_product_type, " \
641
+ "pos.ra, pos.dec from ehst.observation AS o JOIN " \
642
+ "ehst.plane as p on o.observation_uuid=p.observation_uuid " \
653
643
"JOIN ehst.position as pos on p.plane_id = pos.plane_id"
654
644
if parameters :
655
645
query += " where({})" .format (" AND " .join (parameters ))
@@ -665,7 +655,7 @@ def query_criteria(self, calibration_level=None,
665
655
666
656
def __get_calibration_level (self , calibration_level ):
667
657
condition = ""
668
- if (calibration_level is not None ):
658
+ if (calibration_level is not None ):
669
659
if isinstance (calibration_level , str ):
670
660
condition = calibration_level
671
661
elif isinstance (calibration_level , int ):
0 commit comments