From 691fcf16edae6f0881da75e7a496cb935ecf18c1 Mon Sep 17 00:00:00 2001 From: javier-ballester Date: Mon, 12 Sep 2022 14:40:40 +0200 Subject: [PATCH 1/4] Refactored query criteria to use ehst.archive table --- astroquery/esa/hubble/core.py | 35 +++++++++--------- .../esa/hubble/tests/test_esa_hubble.py | 36 +++++++------------ 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 3eda55970f..037ed81123 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -38,8 +38,8 @@ class ESAHubbleClass(BaseQuery): metadata_url = conf.METADATA_ACTION target_url = conf.TARGET_ACTION TIMEOUT = conf.TIMEOUT - calibration_levels = {0: "AUXILIARY", 1: "RAW", 2: "CALIBRATED", - 3: "PRODUCT"} + calibration_levels = {"AUXILIARY": 0, "RAW": 1, "CALIBRATED": 2, + "PRODUCT": 3} product_types = ["PRODUCT", "SCIENCE_PRODUCT", "POSTCARD"] copying_string = "Copying file to {0}..." @@ -629,35 +629,32 @@ def query_criteria(self, calibration_level=None, parameters = [] if calibration_level is not None: - parameters.append("p.calibration_level LIKE '%{}%'".format( + parameters.append("calibration_level={}".format( self.__get_calibration_level(calibration_level))) if data_product_type is not None: if isinstance(data_product_type, str): - parameters.append("p.data_product_type LIKE '%{}%'".format( + parameters.append("data_product_type LIKE '%{}%'".format( data_product_type)) else: raise ValueError("data_product_type must be a string") if intent is not None: if isinstance(intent, str): - parameters.append("o.intent LIKE '%{}%'".format(intent)) + parameters.append("intent LIKE '%{}%'".format(intent.lower())) else: raise ValueError("intent must be a string") if self.__check_list_strings(obs_collection): - parameters.append("(o.collection LIKE '%{}%')".format( - "%' OR o.collection LIKE '%".join(obs_collection) + parameters.append("(collection LIKE '%{}%')".format( + "%' OR collection LIKE '%".join(obs_collection) )) if self.__check_list_strings(instrument_name): - parameters.append("(o.instrument_name LIKE '%{}%')".format( - "%' OR o.instrument_name LIKE '%".join(instrument_name) + parameters.append("(instrument_name LIKE '%{}%')".format( + "%' OR instrument_name LIKE '%".join(instrument_name) )) if self.__check_list_strings(filters): - parameters.append("(o.instrument_configuration LIKE '%{}%')" - .format("%' OR o.instrument_configuration " + parameters.append("(instrument_configuration LIKE '%{}%')" + .format("%' OR instrument_configuration " "LIKE '%".join(filters))) - query = "select o.*, p.calibration_level, p.data_product_type, " \ - "pos.ra, pos.dec from ehst.observation AS o JOIN " \ - "ehst.plane as p on o.observation_uuid=p.observation_uuid " \ - "JOIN ehst.position as pos on p.plane_id = pos.plane_id" + query = "select * from ehst.archive" if parameters: query += " where({})".format(" AND ".join(parameters)) if verbose: @@ -673,13 +670,13 @@ def query_criteria(self, calibration_level=None, def __get_calibration_level(self, calibration_level): condition = "" if (calibration_level is not None): - if isinstance(calibration_level, str): - condition = calibration_level - elif isinstance(calibration_level, int): + if isinstance(calibration_level, int): if calibration_level < 4: - condition = self.calibration_levels[calibration_level] + condition = calibration_level else: raise KeyError("Calibration level must be between 0 and 3") + elif isinstance(calibration_level, str): + condition = self.calibration_levels[calibration_level] else: raise KeyError("Calibration level must be either " "a string or an integer") diff --git a/astroquery/esa/hubble/tests/test_esa_hubble.py b/astroquery/esa/hubble/tests/test_esa_hubble.py index 8cd2a4abed..f16a1fe246 100644 --- a/astroquery/esa/hubble/tests/test_esa_hubble.py +++ b/astroquery/esa/hubble/tests/test_esa_hubble.py @@ -275,18 +275,12 @@ def test_query_criteria(self): 'output_file': "output_test_query_by_criteria.vot.gz", 'output_format': "votable", 'verbose': False} - parameters3 = {'query': "select o.*, p.calibration_level, " - "p.data_product_type, pos.ra, pos.dec " - "from ehst.observation " - "AS o JOIN ehst.plane as p on " - "o.observation_uuid=p.observation_uuid " - "JOIN ehst.position as pos on " - "p.plane_id = pos.plane_id where(" - "p.calibration_level LIKE '%PRODUCT%' AND " - "p.data_product_type LIKE '%image%' AND " - "o.intent LIKE '%SCIENCE%' AND (o.collection " - "LIKE '%HST%') AND (o.instrument_name LIKE " - "'%WFC3%') AND (o.instrument_configuration " + parameters3 = {'query': "select * from ehst.archive where(" + "calibration_level=3 AND " + "data_product_type LIKE '%image%' AND " + "intent LIKE '%science%' AND (collection " + "LIKE '%HST%') AND (instrument_name LIKE " + "'%WFC3%') AND (instrument_configuration " "LIKE '%F555W%'))", 'output_file': "output_test_query_by_criteria.vot.gz", 'output_format': "votable", @@ -322,18 +316,12 @@ def test_query_criteria_numeric_calibration(self): 'output_file': "output_test_query_by_criteria.vot.gz", 'output_format': "votable", 'verbose': False} - parameters3 = {'query': "select o.*, p.calibration_level, " - "p.data_product_type, pos.ra, pos.dec" - " from ehst.observation " - "AS o JOIN ehst.plane as p on " - "o.observation_uuid=p.observation_uuid " - "JOIN ehst.position as pos on p.plane_id " - "= pos.plane_id where(" - "p.calibration_level LIKE '%RAW%' AND " - "p.data_product_type LIKE '%image%' AND " - "o.intent LIKE '%SCIENCE%' AND (o.collection " - "LIKE '%HST%') AND (o.instrument_name LIKE " - "'%WFC3%') AND (o.instrument_configuration " + parameters3 = {'query': "select * from ehst.archive where(" + "calibration_level=1 AND " + "data_product_type LIKE '%image%' AND " + "intent LIKE '%science%' AND (collection " + "LIKE '%HST%') AND (instrument_name LIKE " + "'%WFC3%') AND (instrument_configuration " "LIKE '%F555W%'))", 'output_file': "output_test_query_by_criteria.vot.gz", 'output_format': "votable", From e09fbeb7262e0a3260cf6d0e4572e19f320056e8 Mon Sep 17 00:00:00 2001 From: javier-ballester Date: Mon, 12 Sep 2022 14:50:44 +0200 Subject: [PATCH 2/4] Updated CHANGES.rst --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 423a89e520..6fa6b06b79 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,12 @@ hsa Service fixes and enhancements ------------------------------ +hst +^^^ + +- Refactored query_criteria to use ehst.archive table therefore making the query + a lot faster. [#2524] + alma ^^^^ From f29fcbc9fa9ce59617e398987cbf971fcdc948f3 Mon Sep 17 00:00:00 2001 From: javier-ballester Date: Tue, 13 Sep 2022 10:52:04 +0200 Subject: [PATCH 3/4] Fixed error in hubble.rst --- astroquery/esa/hubble/core.py | 2 +- docs/esa/hubble/hubble.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/astroquery/esa/hubble/core.py b/astroquery/esa/hubble/core.py index 037ed81123..741eafb420 100644 --- a/astroquery/esa/hubble/core.py +++ b/astroquery/esa/hubble/core.py @@ -475,7 +475,7 @@ def cone_search_criteria(self, radius, target=None, radius_in_grades = Angle(radius, units.arcmin).deg else: radius_in_grades = radius.to(units.deg).value - cone_query = "1=CONTAINS(POINT('ICRS', pos.ra, pos.dec)," \ + cone_query = "1=CONTAINS(POINT('ICRS', ra, dec)," \ "CIRCLE('ICRS', {0}, {1}, {2}))". \ format(str(ra), str(dec), str(radius_in_grades)) query = "{}{})".format(crit_query, cone_query) diff --git a/docs/esa/hubble/hubble.rst b/docs/esa/hubble/hubble.rst index 7cccef569b..4c51e22d84 100644 --- a/docs/esa/hubble/hubble.rst +++ b/docs/esa/hubble/hubble.rst @@ -307,7 +307,7 @@ This last example will provide the ADQL query based on the criteria defined by t ... filters = ['F555W', 'F606W'], ... get_query = True) >>> print(result) - select o.*, p.calibration_level, p.data_product_type, pos.ra, pos.dec from ehst.observation AS o JOIN ehst.plane as p on o.observation_uuid=p.observation_uuid JOIN ehst.position as pos on p.plane_id = pos.plane_id where(p.calibration_level LIKE '%PRODUCT%' AND p.data_product_type LIKE '%image%' AND o.intent LIKE '%SCIENCE%' AND (o.collection LIKE '%HLA%') AND (o.instrument_name LIKE '%WFC3%') AND (o.instrument_configuration LIKE '%F555W%' OR o.instrument_configuration LIKE '%F606W%')) + select * from ehst.archive where(calibration_level=3 AND data_product_type LIKE '%image%' AND intent LIKE '%science%' AND (collection LIKE '%HLA%') AND (instrument_name LIKE '%WFC3%') AND (instrument_configuration LIKE '%F555W%' OR instrument_configuration LIKE '%F606W%')) -------------------------------------- 6. Cone searches in the Hubble archive From 42eea5fc01c0b74a8871c02a6e29676156f03b82 Mon Sep 17 00:00:00 2001 From: javier-ballester Date: Tue, 13 Sep 2022 10:53:47 +0200 Subject: [PATCH 4/4] Fixed CHANGES.rst hubble name --- CHANGES.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 6fa6b06b79..373f9fafe7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,8 +20,8 @@ hsa Service fixes and enhancements ------------------------------ -hst -^^^ +esa.hubble +^^^^^^^^^^ - Refactored query_criteria to use ehst.archive table therefore making the query a lot faster. [#2524]