@@ -158,7 +158,7 @@ def logout(self):
158
158
"""
159
159
self .tap ._session .logout (logout_url = conf .ISLA_LOGOUT_SERVER )
160
160
161
- def query_tap (self , query , * , async_job = False , output_file = None , output_format = None ):
161
+ def query_tap (self , query , * , async_job = False , output_file = None , output_format = 'votable' ):
162
162
"""Launches a synchronous or asynchronous job to query the ISLA tap
163
163
164
164
Parameters
@@ -254,8 +254,10 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
254
254
end time of the observation
255
255
start_revno: string, optional
256
256
start revolution number, as a four-digit string with leading zeros
257
+ e.g. 0352
257
258
end_revno: string, optional
258
259
end revolution number, as a four-digit string with leading zeros
260
+ e.g. 0353
259
261
async_job : bool, optional, default 'False'
260
262
executes the query (job) in asynchronous/synchronous mode (default
261
263
synchronous)
@@ -323,7 +325,7 @@ def get_observations(self, *, target_name=None, coordinates=None, radius=14.0, s
323
325
output_format = output_format )
324
326
325
327
def download_science_windows (self , * , science_windows = None , observation_id = None , revolution = None , proposal = None ,
326
- output_file = None ):
328
+ output_file = None , read_fits = True ):
327
329
"""Method to download science windows associated to one of these parameters:
328
330
science_windows, observation_id, revolution or proposal
329
331
@@ -339,6 +341,8 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
339
341
Proposal ID associated to science windows
340
342
output_file: str, optional
341
343
File name and path for the downloaded file
344
+ read_fits: bool, optional, default True
345
+ Open the downloaded file and parse the existing FITS files
342
346
343
347
Returns
344
348
-------
@@ -350,8 +354,13 @@ def download_science_windows(self, *, science_windows=None, observation_id=None,
350
354
params ['RETRIEVAL_TYPE' ] = 'SCW'
351
355
try :
352
356
353
- return esautils .download_file (url = conf .ISLA_DATA_SERVER , session = self .tap ._session ,
354
- filename = output_file , params = params , verbose = True )
357
+ downloaded_file = esautils .download_file (url = conf .ISLA_DATA_SERVER , session = self .tap ._session ,
358
+ filename = output_file , params = params , verbose = True )
359
+ if read_fits :
360
+ return esautils .read_downloaded_fits ([downloaded_file ])
361
+ else :
362
+ return downloaded_file
363
+
355
364
except Exception as e :
356
365
log .error ('No science windows have been found with these inputs. {}' .format (e ))
357
366
@@ -386,22 +395,27 @@ def get_timeline(self, coordinates, *, radius=14):
386
395
"radius" : radius
387
396
}
388
397
389
- # Execute the request to the servlet
390
- request_result = esautils .execute_servlet_request (url = conf .ISLA_SERVLET ,
391
- tap = self .tap ,
392
- query_params = query_params )
393
- total_items = request_result ['totalItems' ]
394
- data = request_result ['data' ]
395
- fraFC = data ['fraFC' ]
396
- totEffExpo = data ['totEffExpo' ]
397
- timeline = Table ({
398
- "scwExpo" : data ["scwExpo" ],
399
- "scwRevs" : data ["scwRevs" ],
400
- "scwTimes" : [datetime .fromtimestamp (scwTime / 1000 ) for scwTime in data ["scwTimes" ]],
401
- "scwOffAxis" : data ["scwOffAxis" ]
402
- })
403
-
404
- return {'total_items' : total_items , 'fraFC' : fraFC , 'totEffExpo' : totEffExpo , 'timeline' : timeline }
398
+ try :
399
+ # Execute the request to the servlet
400
+ request_result = esautils .execute_servlet_request (url = conf .ISLA_SERVLET ,
401
+ tap = self .tap ,
402
+ query_params = query_params )
403
+ total_items = request_result ['totalItems' ]
404
+ data = request_result ['data' ]
405
+ fraFC = data ['fraFC' ]
406
+ totEffExpo = data ['totEffExpo' ]
407
+ timeline = Table ({
408
+ "scwExpo" : data ["scwExpo" ],
409
+ "scwRevs" : data ["scwRevs" ],
410
+ "scwTimes" : [datetime .fromtimestamp (scwTime / 1000 ) for scwTime in data ["scwTimes" ]],
411
+ "scwOffAxis" : data ["scwOffAxis" ]
412
+ })
413
+ return {'total_items' : total_items , 'fraFC' : fraFC , 'totEffExpo' : totEffExpo , 'timeline' : timeline }
414
+ except HTTPError as e :
415
+ if 'None science windows have been selected' in e .response .text :
416
+ raise ValueError (f"No timeline is available for the current coordinates and radius." )
417
+ else :
418
+ raise e
405
419
406
420
def get_epochs (self , * , target_name = None , instrument = None , band = None ):
407
421
"""Retrieve the INTEGRAL epochs associated to a target and an instrument or a band
@@ -420,6 +434,7 @@ def get_epochs(self, *, target_name=None, instrument=None, band=None):
420
434
An astropy.table object containing the available epochs
421
435
"""
422
436
437
+
423
438
value = self .__get_instrument_or_band (instrument = instrument , band = band )
424
439
instrument_oid , band_oid = self .__get_oids (value )
425
440
if target_name :
@@ -503,11 +518,10 @@ def get_short_term_timeseries(self, target_name, epoch, instrument=None, band=No
503
518
504
519
"""
505
520
521
+ value = self .__get_instrument_or_band (instrument = instrument , band = band )
506
522
self .__validate_epoch (target_name = target_name , epoch = epoch ,
507
523
instrument = instrument , band = band )
508
524
509
- value = self .__get_instrument_or_band (instrument = instrument , band = band )
510
-
511
525
params = {'RETRIEVAL_TYPE' : 'short_timeseries' ,
512
526
'source' : target_name ,
513
527
'band_oid' : self .instrument_band_map [value ]['band_oid' ],
@@ -556,11 +570,9 @@ def get_spectra(self, target_name, epoch, instrument=None, band=None, *, path=''
556
570
If read_fits=False, return a list of paths of the downloaded files
557
571
"""
558
572
573
+ value = self .__get_instrument_or_band (instrument = instrument , band = band )
559
574
self .__validate_epoch (target_name = target_name , epoch = epoch ,
560
575
instrument = instrument , band = band )
561
-
562
- value = self .__get_instrument_or_band (instrument = instrument , band = band )
563
-
564
576
query_params = {
565
577
'REQUEST' : 'spectra' ,
566
578
"source" : target_name ,
@@ -675,9 +687,15 @@ def get_source_metadata(self, target_name):
675
687
'REQUEST' : 'sources' ,
676
688
"SOURCE" : target_name
677
689
}
678
- return esautils .execute_servlet_request (url = conf .ISLA_SERVLET ,
679
- tap = self .tap ,
680
- query_params = query_params )
690
+ try :
691
+ return esautils .execute_servlet_request (url = conf .ISLA_SERVLET ,
692
+ tap = self .tap ,
693
+ query_params = query_params )
694
+ except HTTPError as e :
695
+ if 'Source not found in the database' in e .response .text :
696
+ raise ValueError (f"Target { target_name } cannot be resolved for ISLA" )
697
+ else :
698
+ raise e
681
699
682
700
def get_instrument_band_map (self ):
683
701
"""
@@ -792,7 +810,7 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
792
810
793
811
Parameters
794
812
----------
795
- science_windows : list of str, mandat
813
+ science_windows : list of str or str, mandatory
796
814
Science Windows to download
797
815
observation_id: str, optional
798
816
Observation ID associated to science windows
@@ -823,10 +841,10 @@ def __get_science_window_parameter(self, science_windows, observation_id, revolu
823
841
if observation_id is not None and isinstance (observation_id , str ):
824
842
return {'obsid' : observation_id }
825
843
826
- if revolution is not None and isinstance (observation_id , str ):
844
+ if revolution is not None and isinstance (revolution , str ):
827
845
return {'REVID' : revolution }
828
846
829
- if proposal is not None and isinstance (observation_id , str ):
847
+ if proposal is not None and isinstance (proposal , str ):
830
848
return {'PROPID' : proposal }
831
849
832
850
raise ValueError ("Input parameters are wrong" )
0 commit comments