Skip to content

Commit f41cfaa

Browse files
committed
Fixed review comments
1 parent 9b7f976 commit f41cfaa

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

astroquery/esasky/core.py

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def query_region_spectra(self, position, radius, missions=__ALL_STRING,
563563

564564
return commons.TableList(query_result)
565565

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,
567567
get_query_payload=False, cache=True):
568568
"""
569569
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
617617

618618
return commons.TableList(query_result)
619619

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,
621621
get_query_payload=False, cache=True):
622622
"""
623623
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
671671

672672
return commons.TableList(query_result)
673673

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,
675675
get_query_payload=False, cache=True):
676676
"""
677677
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,
796796
log.info("No maps found.")
797797
return maps
798798

799-
def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
799+
def get_images(self, *, position=None, observation_ids=None, radius=__ZERO_ARCMIN_STRING,
800800
missions=__ALL_STRING, download_dir=_MAPS_DOWNLOAD_DIR,
801-
cache=True, observation_ids=None):
801+
cache=True):
802802
"""
803803
This method gets the fits files available for the selected mission and
804804
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,
812812
position : str or `astropy.coordinates` object, optional
813813
Can either be a string of the location, eg 'M51', or the coordinates
814814
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.
815819
radius : str or `~astropy.units.Quantity`, optional
816820
The radius of a region. Defaults to 0.
817821
missions : string or list, optional
@@ -824,10 +828,7 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
824828
cache : bool, optional
825829
When set to True the method will use a cache located at
826830
.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+
831832
832833
Returns
833834
-------
@@ -845,15 +846,15 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
845846
846847
Examples
847848
--------
848-
get_images("m101", "14'", "all")
849+
get_images(position="m101", radius="14'", missions="all")
849850
850851
missions = ["SUZAKU", "ISO-IR", "Chandra", "XMM-OM-OPTICAL", "XMM", "XMM-OM-UV", "HST-IR", "Herschel",
851852
"Spitzer", "HST-UV", "HST-OPTICAL"]
852853
observation_ids = ["100001010", "01500403", "21171", "0852000101", "0851180201", "0851180201", "n3tr01c3q",
853854
"1342247257", "30002561-25100", "hst_07553_3h_wfpc2_f160bw_pc", "ocli05leq"]
854855
get_images(observation_ids=observation_ids, missions=missions)
855856
"""
856-
if position == "" and observation_ids is None:
857+
if position is None and observation_ids is None:
857858
raise ValueError("An input is required for either position or observation_ids.")
858859
sanitized_position = self._sanitize_input_position(position)
859860
sanitized_radius = self._sanitize_input_radius(radius)
@@ -891,9 +892,9 @@ def get_images(self, position="", radius=__ZERO_ARCMIN_STRING,
891892
log.info("No maps found.")
892893
return maps
893894

894-
def get_spectra(self, position="", radius=__ZERO_ARCMIN_STRING,
895+
def get_spectra(self, position=None, observation_ids=None, radius=__ZERO_ARCMIN_STRING,
895896
missions=__ALL_STRING, download_dir=_SPECTRA_DOWNLOAD_DIR,
896-
cache=True, observation_ids=None):
897+
cache=True):
897898
"""
898899
This method gets the fits files available for the selected missions and
899900
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,
906907
position : str or `astropy.coordinates` object, optional
907908
Can either be a string of the location, eg 'M51', or the coordinates
908909
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.
909914
radius : str or `~astropy.units.Quantity`, optional
910915
The radius of a region. Defaults to 0.
911916
missions : string or list, optional
@@ -918,10 +923,6 @@ def get_spectra(self, position="", radius=__ZERO_ARCMIN_STRING,
918923
cache : bool, optional
919924
When set to True the method will use a cache located at
920925
.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.
925926
926927
Returns
927928
-------
@@ -941,15 +942,15 @@ def get_spectra(self, position="", radius=__ZERO_ARCMIN_STRING,
941942
942943
Examples
943944
--------
944-
get_spectra("m101", "14'", ["HST-IR", "XMM-NEWTON", "HERSCHEL"])
945+
get_spectra(position="m101", radius="14'", missions=["HST-IR", "XMM-NEWTON", "HERSCHEL"])
945946
946947
missions = ["ISO-IR", "Chandra", "IUE", "XMM-NEWTON", "HST-IR", "Herschel", "HST-UV", "HST-OPTICAL"]
947948
observation_ids = ["02101201", "1005", "LWR13178", "0001730201", "ibh706cqq", "1342253595", "z1ax0102t",
948949
"oeik2s020"]
949950
get_spectra(observation_ids=observation_ids, missions=missions)
950951
951952
"""
952-
if position == "" and observation_ids is None:
953+
if position is None and observation_ids is None:
953954
raise ValueError("An input is required for either position or observation_ids.")
954955
sanitized_position = self._sanitize_input_position(position)
955956
sanitized_radius = self._sanitize_input_radius(radius)
@@ -1057,6 +1058,8 @@ def _sanitize_input_position(self, position):
10571058
if (isinstance(position, str) or isinstance(position,
10581059
commons.CoordClasses)):
10591060
return position
1061+
if position is None:
1062+
return None
10601063
else:
10611064
raise ValueError("Position must be either a string or "
10621065
"astropy.coordinates")
@@ -1103,7 +1106,7 @@ def _sanitize_input_catalogs(self, catalogs):
11031106
"catalogs")
11041107

11051108
def _sanitize_input_ids(self, ids):
1106-
if isinstance(ids, list):
1109+
if isinstance(ids, list) and len(ids) > 0:
11071110
return ids
11081111
if isinstance(ids, str):
11091112
return [ids]
@@ -1362,13 +1365,18 @@ def _query(self, name, json, **kwargs):
13621365
return self._create_request_payload(query)
13631366

13641367
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.
13651373
return query
13661374

13671375
return self.query(query, output_format="votable")
13681376

13691377
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
13721380
radius_deg = commons.radius_to_unit(radius, unit='deg')
13731381

13741382
select_query = "SELECT "
@@ -1434,9 +1442,10 @@ def _build_id_query(self, ids, row_limit, json):
14341442
valid_ids = ids
14351443
if data_type in self._NUMBER_DATA_TYPES:
14361444
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 ""
14401449

14411450
observation_ids_query_list = ", ".join(repr(id) for id in valid_ids)
14421451
where_query = (" WHERE {} IN ({})".format(id_column, observation_ids_query_list))

0 commit comments

Comments
 (0)