@@ -563,7 +563,7 @@ def query_region_spectra(self, position, radius, missions=__ALL_STRING,
563
563
564
564
return commons .TableList (query_result )
565
565
566
- def query_ids_maps (self , observation_ids , missions = __ALL_STRING , row_limit = DEFAULT_ROW_LIMIT ,
566
+ def query_ids_maps (self , observation_ids , * , missions = __ALL_STRING , row_limit = DEFAULT_ROW_LIMIT ,
567
567
get_query_payload = False , cache = True ):
568
568
"""
569
569
This method fetches the metadata for all the given observations id's and returns a TableList.
@@ -617,7 +617,7 @@ def query_ids_maps(self, observation_ids, missions=__ALL_STRING, row_limit=DEFAU
617
617
618
618
return commons .TableList (query_result )
619
619
620
- def query_ids_catalogs (self , source_ids , catalogs = __ALL_STRING , row_limit = DEFAULT_ROW_LIMIT ,
620
+ def query_ids_catalogs (self , source_ids , * , catalogs = __ALL_STRING , row_limit = DEFAULT_ROW_LIMIT ,
621
621
get_query_payload = False , cache = True ):
622
622
"""
623
623
This method fetches the metadata for all the given source id's and returns a TableList.
@@ -671,7 +671,7 @@ def query_ids_catalogs(self, source_ids, catalogs=__ALL_STRING, row_limit=DEFAUL
671
671
672
672
return commons .TableList (query_result )
673
673
674
- def query_ids_spectra (self , observation_ids , missions = __ALL_STRING , row_limit = DEFAULT_ROW_LIMIT ,
674
+ def query_ids_spectra (self , observation_ids , * , missions = __ALL_STRING , row_limit = DEFAULT_ROW_LIMIT ,
675
675
get_query_payload = False , cache = True ):
676
676
"""
677
677
This method fetches the metadata for all the given observations id's and returns a TableList.
@@ -796,9 +796,9 @@ def get_maps(self, query_table_list, missions=__ALL_STRING,
796
796
log .info ("No maps found." )
797
797
return maps
798
798
799
- def get_images (self , position = "" , radius = __ZERO_ARCMIN_STRING ,
799
+ def get_images (self , * , position = None , observation_ids = None , radius = __ZERO_ARCMIN_STRING ,
800
800
missions = __ALL_STRING , download_dir = _MAPS_DOWNLOAD_DIR ,
801
- cache = True , observation_ids = None ):
801
+ cache = True ):
802
802
"""
803
803
This method gets the fits files available for the selected mission and
804
804
position or observation_ids and downloads all maps to the the selected folder.
@@ -812,6 +812,10 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
812
812
position : str or `astropy.coordinates` object, optional
813
813
Can either be a string of the location, eg 'M51', or the coordinates
814
814
of the object. An input is required for either position or observation_ids.
815
+ observation_ids : string or list, optional
816
+ A list of observation ID's, you would like to download.
817
+ If this parameter is empty, a cone search will be performed instead using the radius and position.
818
+ An input is required for either position or observation_ids.
815
819
radius : str or `~astropy.units.Quantity`, optional
816
820
The radius of a region. Defaults to 0.
817
821
missions : string or list, optional
@@ -824,10 +828,7 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
824
828
cache : bool, optional
825
829
When set to True the method will use a cache located at
826
830
.astropy/astroquery/cache. Defaults to True.
827
- observation_ids : string or list, optional
828
- A list of observation ID's, you would like to download.
829
- If this parameter is empty, a cone search will be performed instead using the radius and position.
830
- An input is required for either position or observation_ids.
831
+
831
832
832
833
Returns
833
834
-------
@@ -845,15 +846,15 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
845
846
846
847
Examples
847
848
--------
848
- get_images("m101", "14'", "all")
849
+ get_images(position= "m101", radius= "14'", missions= "all")
849
850
850
851
missions = ["SUZAKU", "ISO-IR", "Chandra", "XMM-OM-OPTICAL", "XMM", "XMM-OM-UV", "HST-IR", "Herschel",
851
852
"Spitzer", "HST-UV", "HST-OPTICAL"]
852
853
observation_ids = ["100001010", "01500403", "21171", "0852000101", "0851180201", "0851180201", "n3tr01c3q",
853
854
"1342247257", "30002561-25100", "hst_07553_3h_wfpc2_f160bw_pc", "ocli05leq"]
854
855
get_images(observation_ids=observation_ids, missions=missions)
855
856
"""
856
- if position == "" and observation_ids is None :
857
+ if position is None and observation_ids is None :
857
858
raise ValueError ("An input is required for either position or observation_ids." )
858
859
sanitized_position = self ._sanitize_input_position (position )
859
860
sanitized_radius = self ._sanitize_input_radius (radius )
@@ -891,9 +892,9 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
891
892
log .info ("No maps found." )
892
893
return maps
893
894
894
- def get_spectra (self , position = "" , radius = __ZERO_ARCMIN_STRING ,
895
+ def get_spectra (self , position = None , observation_ids = None , radius = __ZERO_ARCMIN_STRING ,
895
896
missions = __ALL_STRING , download_dir = _SPECTRA_DOWNLOAD_DIR ,
896
- cache = True , observation_ids = None ):
897
+ cache = True ):
897
898
"""
898
899
This method gets the fits files available for the selected missions and
899
900
position or observation_ids and downloads all spectra to the the selected folder.
@@ -906,6 +907,10 @@ def get_spectra(self, position="", radius=__ZERO_ARCMIN_STRING,
906
907
position : str or `astropy.coordinates` object, optional
907
908
Can either be a string of the location, eg 'M51', or the coordinates
908
909
of the object. An input is required for either position or observation_ids.
910
+ observation_ids : string or list, optional
911
+ A list of observation ID's, you would like to download.
912
+ If this parameter is empty, a cone search will be performed instead using the radius and position.
913
+ An input is required for either position or observation_ids.
909
914
radius : str or `~astropy.units.Quantity`, optional
910
915
The radius of a region. Defaults to 0.
911
916
missions : string or list, optional
@@ -918,10 +923,6 @@ def get_spectra(self, position="", radius=__ZERO_ARCMIN_STRING,
918
923
cache : bool, optional
919
924
When set to True the method will use a cache located at
920
925
.astropy/astroquery/cache. Defaults to True.
921
- observation_ids : string or list, optional
922
- A list of observation ID's, you would like to download.
923
- If this parameter is empty, a cone search will be performed instead using the radius and position.
924
- An input is required for either position or observation_ids.
925
926
926
927
Returns
927
928
-------
@@ -941,15 +942,15 @@ def get_spectra(self, position="", radius=__ZERO_ARCMIN_STRING,
941
942
942
943
Examples
943
944
--------
944
- get_spectra("m101", "14'", ["HST-IR", "XMM-NEWTON", "HERSCHEL"])
945
+ get_spectra(position= "m101", radius= "14'", missions= ["HST-IR", "XMM-NEWTON", "HERSCHEL"])
945
946
946
947
missions = ["ISO-IR", "Chandra", "IUE", "XMM-NEWTON", "HST-IR", "Herschel", "HST-UV", "HST-OPTICAL"]
947
948
observation_ids = ["02101201", "1005", "LWR13178", "0001730201", "ibh706cqq", "1342253595", "z1ax0102t",
948
949
"oeik2s020"]
949
950
get_spectra(observation_ids=observation_ids, missions=missions)
950
951
951
952
"""
952
- if position == "" and observation_ids is None :
953
+ if position is None and observation_ids is None :
953
954
raise ValueError ("An input is required for either position or observation_ids." )
954
955
sanitized_position = self ._sanitize_input_position (position )
955
956
sanitized_radius = self ._sanitize_input_radius (radius )
@@ -1057,6 +1058,8 @@ def _sanitize_input_position(self, position):
1057
1058
if (isinstance (position , str ) or isinstance (position ,
1058
1059
commons .CoordClasses )):
1059
1060
return position
1061
+ if position is None :
1062
+ return None
1060
1063
else :
1061
1064
raise ValueError ("Position must be either a string or "
1062
1065
"astropy.coordinates" )
@@ -1103,7 +1106,7 @@ def _sanitize_input_catalogs(self, catalogs):
1103
1106
"catalogs" )
1104
1107
1105
1108
def _sanitize_input_ids (self , ids ):
1106
- if isinstance (ids , list ):
1109
+ if isinstance (ids , list ) and len ( ids ) > 0 :
1107
1110
return ids
1108
1111
if isinstance (ids , str ):
1109
1112
return [ids ]
@@ -1362,13 +1365,18 @@ def _query(self, name, json, **kwargs):
1362
1365
return self ._create_request_payload (query )
1363
1366
1364
1367
if not query :
1368
+ # Could not create query. The most common reason for this is a type mismatch between user specified ID and
1369
+ # data type of database column.
1370
+ # For example query_ids_catalogs(source_ids=["2CXO J090341.1-322609"], mission=["CHANDRA", "HSC"])
1371
+ # would be able to create a query for Chandra, but not for Hubble because the hubble source id column type
1372
+ # is a number and "2CXO J090341.1-322609" cannot be converted to a number.
1365
1373
return query
1366
1374
1367
1375
return self .query (query , output_format = "votable" )
1368
1376
1369
1377
def _build_region_query (self , coordinates , radius , row_limit , json ):
1370
- ra_hours , dec = commons . coord_to_radec ( coordinates )
1371
- ra = ra_hours * 15.0 # Converts to degrees
1378
+ ra = coordinates . transform_to ( 'icrs' ). ra . deg
1379
+ dec = coordinates . transform_to ( 'icrs' ). dec . deg
1372
1380
radius_deg = commons .radius_to_unit (radius , unit = 'deg' )
1373
1381
1374
1382
select_query = "SELECT "
@@ -1434,9 +1442,10 @@ def _build_id_query(self, ids, row_limit, json):
1434
1442
valid_ids = ids
1435
1443
if data_type in self ._NUMBER_DATA_TYPES :
1436
1444
valid_ids = [int (obs_id ) for obs_id in ids if obs_id .isdigit ()]
1437
-
1438
- if not valid_ids :
1439
- return ""
1445
+ if not valid_ids :
1446
+ log .info ("Could not construct query for mission {}. Database column type is a number, "
1447
+ "while none of the input id's could be interpreted as numbers." .format (json ['mission' ]))
1448
+ return ""
1440
1449
1441
1450
observation_ids_query_list = ", " .join (repr (id ) for id in valid_ids )
1442
1451
where_query = (" WHERE {} IN ({})" .format (id_column , observation_ids_query_list ))
0 commit comments