@@ -40,7 +40,7 @@ class MastMissionsClass(MastQueryWithLogin):
40
40
41
41
# Static class variables
42
42
_search = 'search'
43
- _list_products = 'list_products '
43
+ _list_products = 'post_list_products '
44
44
45
45
# Workaround so that observation_id is returned in ULLYSES queries that do not specify columns
46
46
_default_ulysses_cols = ['target_name_ulysses' , 'target_classification' , 'targ_ra' , 'targ_dec' , 'host_galaxy_name' ,
@@ -59,8 +59,8 @@ def __init__(self, *, mission='hst', mast_token=None):
59
59
60
60
# Service attributes
61
61
self .service = self ._search # current API service
62
- self .service_dict = {self ._search : {'path' : 'search' },
63
- self ._list_products : {'path' : 'list_products' }}
62
+ self .service_dict = {self ._search : {'path' : self . _search },
63
+ self ._list_products : {'path' : self . _list_products }}
64
64
65
65
# Search attributes
66
66
self ._search_option_fields = ['limit' , 'offset' , 'sort_by' , 'search_key' , 'sort_desc' , 'select_cols' ,
@@ -190,7 +190,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs
190
190
191
191
# Dataset ID column should always be returned
192
192
if select_cols :
193
- select_cols .append (self .dataset_kwds [ self .mission ] )
193
+ select_cols .append (self .dataset_kwds . get ( self .mission , None ) )
194
194
elif self .mission == 'ullyses' :
195
195
select_cols = self ._default_ulysses_cols
196
196
@@ -267,7 +267,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
267
267
268
268
# Dataset ID column should always be returned
269
269
if select_cols :
270
- select_cols .append (self .dataset_kwds [ self .mission ] )
270
+ select_cols .append (self .dataset_kwds . get ( self .mission , None ) )
271
271
elif self .mission == 'ullyses' :
272
272
select_cols = self ._default_ulysses_cols
273
273
@@ -349,32 +349,38 @@ def get_product_list_async(self, datasets):
349
349
350
350
self .service = self ._list_products
351
351
352
+ if isinstance (datasets , Table ) or isinstance (datasets , Row ):
353
+ dataset_kwd = self .get_dataset_kwd ()
354
+ if not dataset_kwd :
355
+ log .warning ('Please input dataset IDs as a string, list of strings, or `~astropy.table.Column`.' )
356
+ return None
357
+
352
358
# Extract dataset IDs based on input type and mission
353
359
if isinstance (datasets , Table ):
354
- datasets = datasets [self . dataset_kwds [ self . mission ]]
360
+ datasets = datasets [dataset_kwd ]. tolist ()
355
361
elif isinstance (datasets , Row ):
356
- datasets = np . array ( [datasets [self . dataset_kwds [ self . mission ]]])
357
- elif isinstance (datasets , str ) or isinstance ( datasets , Column ):
358
- datasets = np . array ([ datasets ] )
359
- elif isinstance (datasets , list ):
360
- datasets = np . array ( datasets )
361
- else :
362
+ datasets = [datasets [dataset_kwd ]]
363
+ elif isinstance (datasets , Column ):
364
+ datasets = datasets . tolist ( )
365
+ elif isinstance (datasets , str ):
366
+ datasets = [ datasets ]
367
+ elif not isinstance ( datasets , list ) :
362
368
raise TypeError ('Unsupported data type for `datasets`. Expected string, '
363
- 'list of strings, Astropy row , or Astropy Table.' )
369
+ 'list of strings, Astropy Row, Astropy Column , or Astropy Table.' )
364
370
365
371
# Filter out empty strings from IDs
366
- datasets = datasets [ np . char . strip (datasets ) != '' ]
367
- if datasets . size == 0 :
372
+ datasets = [ item . strip () for item in datasets if item . strip ( ) != '' and item is not None ]
373
+ if not len ( datasets ) :
368
374
raise InvalidQueryError ("Dataset list is empty, no associated products." )
369
375
370
376
# Send async service request
371
- params = {'dataset_ids' : ',' . join ( datasets ) }
377
+ params = {'dataset_ids' : datasets }
372
378
return self ._service_api_connection .missions_request_async (self .service , params )
373
379
374
380
def get_unique_product_list (self , datasets ):
375
381
"""
376
382
Given a dataset ID or list of dataset IDs, returns a list of associated data products with unique
377
- URIs .
383
+ filenames .
378
384
379
385
Parameters
380
386
----------
@@ -443,6 +449,7 @@ def filter_products(self, products, *, extension=None, **filters):
443
449
def download_file (self , uri , * , local_path = None , cache = True , verbose = True ):
444
450
"""
445
451
Downloads a single file based on the data URI.
452
+
446
453
Parameters
447
454
----------
448
455
uri : str
@@ -453,6 +460,7 @@ def download_file(self, uri, *, local_path=None, cache=True, verbose=True):
453
460
Default is True. If file is found on disk, it will not be downloaded again.
454
461
verbose : bool, optional
455
462
Default is True. Whether to show download progress in the console.
463
+
456
464
Returns
457
465
-------
458
466
status: str
@@ -550,7 +558,7 @@ def _download_files(self, products, base_dir, *, flat=False, cache=True, verbose
550
558
local_path = local_file_path ,
551
559
cache = cache ,
552
560
verbose = verbose )
553
- manifest_entries .append ([local_file_path , status , msg or '' , url or '' ])
561
+ manifest_entries .append ([local_file_path , status , msg , url ])
554
562
555
563
# Return manifest as Astropy Table
556
564
manifest = Table (rows = manifest_entries , names = ('Local Path' , 'Status' , 'Message' , 'URL' ))
@@ -627,7 +635,6 @@ def get_column_list(self):
627
635
-------
628
636
response : `~astropy.table.Table` that contains columns names, types, and descriptions
629
637
"""
630
-
631
638
if not self .columns .get (self .mission ):
632
639
try :
633
640
# Send server request to get column list for current mission
@@ -659,5 +666,20 @@ def get_column_list(self):
659
666
660
667
return self .columns [self .mission ]
661
668
669
+ def get_dataset_kwd (self ):
670
+ """
671
+ Return the Dataset ID keyword for the selected mission. If the keyword is unknown, returns None.
672
+
673
+ Returns
674
+ -------
675
+ keyword : str or None
676
+ Dataset ID keyword or None if unknown.
677
+ """
678
+ if self .mission not in self .dataset_kwds :
679
+ log .warning ('The mission "%s" does not have a known dataset ID keyword.' , self .mission )
680
+ return None
681
+
682
+ return self .dataset_kwds [self .mission ]
683
+
662
684
663
685
MastMissions = MastMissionsClass ()
0 commit comments