def test_query_criteria_numeric_calibration(self):
     parameters1 = {
         'calibration_level': 1,
         'data_product_type': "image",
         'intent': "SCIENCE",
         'obs_collection': ['HST'],
         'instrument_name': ['WFC3'],
         'filters': ['F555W'],
         'async_job': False,
         'output_file': "output_test_query_by_criteria.vot.gz",
         'output_format': "votable",
         'verbose': True,
         'get_query': True
     }
     ehst = ESAHubbleClass(self.get_dummy_tap_handler())
     test_query = ehst.query_criteria(
         parameters1['calibration_level'], parameters1['data_product_type'],
         parameters1['intent'], parameters1['obs_collection'],
         parameters1['instrument_name'], parameters1['filters'],
         parameters1['async_job'], parameters1['output_file'],
         parameters1['output_format'], parameters1['verbose'],
         parameters1['get_query'])
     parameters2 = {
         'query': test_query,
         '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 from ehst.observation "
         "AS o LEFT JOIN ehst.plane as p on "
         "o.observation_uuid=p.observation_uuid 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 "
         "LIKE '%F555W%'))",
         'output_file':
         "output_test_query_by_criteria.vot.gz",
         'output_format':
         "votable",
         'verbose':
         False
     }
     dummy_tap_handler = DummyHubbleTapHandler("launch_job", parameters2)
     dummy_tap_handler.check_call("launch_job", parameters3)
     parameters1['calibration_level'] = 4
     with pytest.raises(KeyError) as err:
         ehst.query_criteria(
             parameters1['calibration_level'],
             parameters1['data_product_type'], parameters1['intent'],
             parameters1['obs_collection'], parameters1['instrument_name'],
             parameters1['filters'], parameters1['async_job'],
             parameters1['output_file'], parameters1['output_format'],
             parameters1['verbose'], parameters1['get_query'])
     assert "Calibration level must be between 0 and 3" in err.value.args[0]
Exemple #2
0
 def test_query_criteria(self):
     parameters1 = {
         'calibration_level': "PRODUCT",
         'data_product_type': "image",
         'intent': "SCIENCE",
         'obs_collection': ['HST'],
         'instrument_name': ['WFC3'],
         'filters': ['F555W'],
         'async_job': False,
         'output_file': "output_test_query_by_criteria.vot.gz",
         'output_format': "votable",
         'verbose': True,
         'get_query': True
     }
     ehst = ESAHubbleClass(self.get_dummy_tap_handler())
     test_query = ehst.query_criteria(
         parameters1['calibration_level'], parameters1['data_product_type'],
         parameters1['intent'], parameters1['obs_collection'],
         parameters1['instrument_name'], parameters1['filters'],
         parameters1['async_job'], parameters1['output_file'],
         parameters1['output_format'], parameters1['verbose'],
         parameters1['get_query'])
     parameters2 = {
         'query': test_query,
         '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 "
         "LIKE '%F555W%'))",
         'output_file':
         "output_test_query_by_criteria.vot.gz",
         'output_format':
         "votable",
         'verbose':
         False
     }
     dummy_tap_handler = DummyHubbleTapHandler("launch_job", parameters2)
     dummy_tap_handler.check_call("launch_job", parameters3)
    def test_get_columns(self):
        parameters = {'query': "select top 10 * from hsc_v2.hubble_sc2",
                      'output_file': "test2.vot",
                      'output_format': "votable",
                      'verbose': False}

        parameters2 = {'table_name': "table",
                       'only_names': True,
                       'verbose': True}

        dummyTapHandler = DummyHubbleTapHandler("get_columns", parameters2)
        ehst = ESAHubbleClass(self.get_dummy_tap_handler())
        ehst.get_columns("table", True, True)
        dummyTapHandler.check_call("get_columns", parameters2)
    def test_cone_search(self):
        c = coordinates.SkyCoord("00h42m44.51s +41d16m08.45s", frame='icrs')

        parameterst = {
            'query': "select top 10 * from hsc_v2.hubble_sc2",
            'output_file': "test2.vot",
            'output_format': "votable",
            'verbose': False
        }
        dummyTapHandler = DummyHubbleTapHandler("launch_job", parameterst)

        parameters = {
            'coordinates': c,
            'radius': 0.0,
            'file_name': 'file_cone',
            'output_format': 'votable',
            'cache': True
        }

        ehst = ESAHubbleClass(dummyTapHandler)
        target_file = data_path('cone_search.vot')
        with open(target_file, mode='rb') as file:
            target_obj = file.read()
            response = Response()
            response._content = target_obj
            ehst._request = MagicMock(return_value=response)
            ehst.cone_search(parameters['coordinates'], parameters['radius'],
                             parameters['file_name'],
                             parameters['output_format'], parameters['cache'])
    def test_cone_search_coords(self):
        c = "00h42m44.51s +41d16m08.45s"

        parameterst = {
            'query': "select top 10 * from hsc_v2.hubble_sc2",
            'output_file': "test2.vot",
            'output_format': "votable",
            'verbose': False
        }
        dummyTapHandler = DummyHubbleTapHandler("launch_job", parameterst)

        parameters = {
            'coordinates': c,
            'radius': 0.0,
            'file_name': 'file_cone',
            'output_format': 'votable',
            'cache': True
        }

        ehst = ESAHubbleClass(dummyTapHandler)
        ehst.cone_search(parameters['coordinates'], parameters['radius'],
                         parameters['file_name'], parameters['output_format'],
                         parameters['cache'])
        parameters[coordinates] = 1234
        with pytest.raises(ValueError) as err:
            ehst.cone_search(parameters['coordinates'], parameters['radius'],
                             parameters['file_name'],
                             parameters['output_format'], parameters['cache'])
        assert "coordinate must be either a string or "\
               "astropy.coordinates" in err.value.args[0]
 def get_dummy_tap_handler(self):
     parameterst = {'query': "select top 10 * from hsc_v2.hubble_sc2",
                    'output_file': "test2.vot",
                    'output_format': "votable",
                    'verbose': False}
     dummyTapHandler = DummyHubbleTapHandler("launch_job", parameterst)
     return dummyTapHandler
 def test_query_criteria_no_params(self):
     ehst = ESAHubbleClass(self.get_dummy_tap_handler())
     ehst.query_criteria(async_job=False,
                         output_file="output_test_query_"
                         "by_criteria.vot.gz",
                         output_format="votable",
                         verbose=True)
     parameters = {'query': "select o.*, p.calibration_level, "
                            "p.data_product_type from ehst.observation "
                            "AS o LEFT JOIN ehst.plane as p on "
                            "o.observation_uuid=p.observation_uuid",
                   'output_file': "output_test_query_by_criteria.vot.gz",
                   'output_format': "votable",
                   'verbose': False}
     dummy_tap_handler = DummyHubbleTapHandler("launch_job", parameters)
     dummy_tap_handler.check_call("launch_job", parameters)
Exemple #8
0
 def test_cone_search(self):
     coords = coordinates.SkyCoord("00h42m44.51s +41d16m08.45s",
                                   frame='icrs')
     ehst = ESAHubbleClass(self.get_dummy_tap_handler())
     parameters = {
         'coordinates': coords,
         'radius': 0.0,
         'filename': 'file_cone',
         'output_format': 'votable',
         'cache': True
     }
     target_file = data_path('cone_search.vot')
     with open(target_file, mode='rb') as file:
         target_obj = file.read()
         response = Response()
         response._content = target_obj
         ehst._request = MagicMock(return_value=response)
         ehst.cone_search(parameters['coordinates'], parameters['radius'],
                          parameters['filename'],
                          parameters['output_format'], parameters['cache'])
         dummyTapHandler = DummyHubbleTapHandler("cone_search", parameters)
    def test_cone_search(self):
        c = coordinates.SkyCoord("00h42m44.51s +41d16m08.45s", frame='icrs')

        parameterst = {'query': "select top 10 * from hsc_v2.hubble_sc2",
                       'output_file': "test2.vot",
                       'output_format': "votable",
                       'verbose': False}
        dummyTapHandler = DummyHubbleTapHandler("launch_job", parameterst)

        parameters = {'coordinates': c,
                      'radius': 0.0,
                      'file_name': 'file_cone',
                      'output_format': 'votable',
                      'cache': True}
        dummyHandler = DummyHandler("cone_search", parameters)

        ehst = ESAHubbleClass(dummyHandler, dummyTapHandler)
        ehst.cone_search(parameters['coordinates'],
                         parameters['radius'],
                         parameters['file_name'],
                         parameters['output_format'],
                         parameters['cache'])
        dummyHandler.check_call("cone_search", parameters)
Exemple #10
0
 def test_cone_search_criteria(self):
     parameters1 = {
         'target': "m31",
         'radius': 7,
         'data_product_type': "image",
         'obs_collection': ['HST'],
         'instrument_name': ['ACS/WFC'],
         'filters': ['F435W'],
         'async_job': False,
         'filename': "output_test_query_by_criteria.vot.gz",
         'output_format': "votable",
         'verbose': True
     }
     test_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((o.collection LIKE '%HST%') AND "\
                  "(o.instrument_name LIKE '%WFPC2%') AND "\
                  "(o.instrument_configuration LIKE '%F606W%') AND "\
                  "1=CONTAINS(POINT('ICRS', pos.ra, pos.dec),"\
                  "CIRCLE('ICRS', 10.6847083, 41.26875, "\
                  "0.11666666666666667)))"
     parameters3 = {
         'query': test_query,
         'output_file': "output_test_query_by_criteria.vot.gz",
         'output_format': "votable",
         'verbose': False
     }
     ehst = ESAHubbleClass(self.get_dummy_tap_handler())
     query_criteria_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((o.collection LIKE "\
                            "'%HST%') AND (o.instrument_name LIKE "\
                            "'%WFPC2%') AND (o.instrument_configuration "\
                            "LIKE '%F606W%'))"
     ehst.query_criteria = MagicMock(return_value=query_criteria_query)
     target = {'RA_DEGREES': '10.6847083', 'DEC_DEGREES': '41.26875'}
     ehst._query_tap_target = MagicMock(return_value=target)
     ehst.cone_search_criteria(
         target=parameters1['target'],
         radius=parameters1['radius'],
         data_product_type=parameters1['data_product_type'],
         obs_collection=parameters1['obs_collection'],
         instrument_name=parameters1['instrument_name'],
         filters=parameters1['filters'],
         async_job=parameters1['async_job'],
         filename=parameters1['filename'],
         output_format=parameters1['output_format'],
         verbose=parameters1['verbose'])
     dummy_tap_handler = DummyHubbleTapHandler("launch_job", parameters3)
     dummy_tap_handler.check_call("launch_job", parameters3)
     c = coordinates.SkyCoord("00h42m44.51s +41d16m08.45s", frame='icrs')
     ehst.cone_search_criteria(
         coordinates=c,
         radius=parameters1['radius'],
         data_product_type=parameters1['data_product_type'],
         obs_collection=parameters1['obs_collection'],
         instrument_name=parameters1['instrument_name'],
         filters=parameters1['filters'],
         async_job=parameters1['async_job'],
         filename=parameters1['filename'],
         output_format=parameters1['output_format'],
         verbose=parameters1['verbose'])
     with pytest.raises(TypeError) as err:
         ehst.cone_search_criteria(
             target=parameters1['target'],
             coordinates=123,
             radius=parameters1['radius'],
             data_product_type=parameters1['data_product_type'],
             obs_collection=parameters1['obs_collection'],
             instrument_name=parameters1['instrument_name'],
             filters=parameters1['filters'],
             async_job=parameters1['async_job'],
             filename=parameters1['filename'],
             output_format=parameters1['output_format'],
             verbose=parameters1['verbose'])
     assert "Please use only target or coordinates as"\
         "parameter." in err.value.args[0]