Beispiel #1
0
def test_gen_science_sql():
    common_select = 'select * from ivoa.obscore'
    assert _gen_sql({'science_observation': None}) == common_select
    assert _gen_sql({'science_observation': True}) == common_select +\
        " WHERE science_observation='T'"
    assert _gen_sql({'science_observation': False}) == common_select +\
        " WHERE science_observation='F'"
Beispiel #2
0
def test_gen_public_sql():
    common_select = 'select * from ivoa.obscore'
    assert _gen_sql({'public_data': None}) == common_select
    assert _gen_sql({'public_data': True}) == common_select +\
        " WHERE data_rights='Public'"
    assert _gen_sql({'public_data': False}) == common_select + \
        " WHERE data_rights='Proprietary'"
Beispiel #3
0
def test_gen_datetime_sql():
    common_select = 'select * from ivoa.obscore WHERE '
    assert _gen_sql({'start_date': '01-01-2020'}) == common_select + \
        "t_min=58849.0"
    assert _gen_sql({'start_date': '>01-01-2020'}) == common_select + \
        "t_min>=58849.0"
    assert _gen_sql({'start_date': '<01-01-2020'}) == common_select + \
        "t_min<=58849.0"
    assert _gen_sql({'start_date': '(01-01-2020 .. 01-02-2020)'}) == \
        common_select + "(58849.0<=t_min AND t_min<=58880.0)"
Beispiel #4
0
def test_gen_spec_res_sql():
    common_select = 'select * from ivoa.obscore WHERE '
    assert _gen_sql({'spectral_resolution': 70}) == common_select + \
        "em_resolution=20985472.06"
    assert _gen_sql({'spectral_resolution': '<70'}) == common_select + \
        "em_resolution>=20985472.06"
    assert _gen_sql({'spectral_resolution': '>70'}) == common_select + \
        "em_resolution<=20985472.06"
    assert _gen_sql({'spectral_resolution': '(70 .. 80)'}) == common_select + \
        "(23983396.64<=em_resolution AND em_resolution<=20985472.06)"
    assert _gen_sql({'spectral_resolution': '(70|80)'}) == common_select + \
        "(em_resolution=20985472.06 OR em_resolution=23983396.64)"
Beispiel #5
0
def test_gen_str_sql():
    common_select = 'select * from ivoa.obscore WHERE '
    assert _gen_sql({'pub_title': '*Cosmic*'}) == common_select + \
        "pub_title LIKE '%Cosmic%'"
    assert _gen_sql({'pub_title': 'Galaxy'}) == common_select + \
        "pub_title='Galaxy'"
    assert _gen_sql({'pub_abstract': '*50% of the mass*'}) == common_select + \
        r"pub_abstract LIKE '%50\% of the mass%'"
    assert _gen_sql({'project_code': '2012.* | 2013.?3*'}) == common_select + \
        "(proposal_id LIKE '2012.%' OR proposal_id LIKE '2013._3%')"
    # test with brackets like the form example
    assert _gen_sql({'project_code': '(2012.* | 2013.?3*)'}) == common_select + \
        "(proposal_id LIKE '2012.%' OR proposal_id LIKE '2013._3%')"
Beispiel #6
0
def test_gen_numeric_sql():
    common_select = 'select * from ivoa.obscore WHERE '
    assert _gen_sql({'bandwidth': '23'}) == common_select + 'bandwidth=23.0'
    assert _gen_sql({'bandwidth': '22 .. 23'}) == common_select +\
        '(22.0<=bandwidth AND bandwidth<=23.0)'
    assert _gen_sql({'bandwidth':
                     '<100'}) == common_select + 'bandwidth<=100.0'
    assert _gen_sql({'bandwidth':
                     '>100'}) == common_select + 'bandwidth>=100.0'
    assert _gen_sql({'bandwidth': '!(20 .. 30)'}) == common_select + \
        '(bandwidth<=20.0 OR bandwidth>=30.0)'
    assert _gen_sql({'bandwidth': '<10 | >20'}) == common_select + \
        '(bandwidth<=10.0 OR bandwidth>=20.0)'
    assert _gen_sql({'bandwidth': 100, 'frequency': '>3'}) == common_select +\
        "bandwidth=100 AND frequency>=3.0"
Beispiel #7
0
def test_pol_sql():
    common_select = 'select * from ivoa.obscore'
    assert _gen_sql({'polarisation_type': 'Stokes I'}) == common_select +\
        " WHERE pol_states LIKE '%I%'"
    assert _gen_sql({'polarisation_type': 'Single'}) == common_select + \
        " WHERE pol_states='/XX/'"
    assert _gen_sql({'polarisation_type': 'Dual'}) == common_select + \
        " WHERE pol_states='/XX/YY/'"
    assert _gen_sql({'polarisation_type': 'Full'}) == common_select + \
        " WHERE pol_states='/XX/XY/YX/YY/'"
    assert _gen_sql({'polarisation_type': ['Single', 'Dual']}) == \
        common_select + " WHERE (pol_states='/XX/' OR pol_states='/XX/YY/')"
    assert _gen_sql({'polarisation_type': 'Single, Dual'}) == \
        common_select + " WHERE (pol_states='/XX/' OR pol_states='/XX/YY/')"
Beispiel #8
0
def test_gen_science_sql():
    common_select = 'select * from ivoa.obscore'
    assert _gen_sql({'science_observations': None}) == common_select
    assert _gen_sql({'science_observations': True}) == common_select +\
        " WHERE calib_level>1"
    assert _gen_sql({'science_observations': False}) == common_select
Beispiel #9
0
def test_gen_pos_sql():
    # test circle
    # radius defaults to 1.0arcmin
    common_select = 'select * from ivoa.obscore WHERE '
    assert _gen_sql({'ra_dec': '1 2'}) == common_select + "(INTERSECTS(" \
        "CIRCLE('ICRS',1.0,2.0,0.16666666666666666), s_region) = 1)"
    assert _gen_sql({'ra_dec': '1 2, 3'}) == common_select + \
        "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,3.0), s_region) = 1)"
    assert _gen_sql({'ra_dec': '12:13:14.0 -00:01:02.1, 3'}) == \
        common_select + \
        "(INTERSECTS(CIRCLE('ICRS',12.220555555555556,-0.01725,3.0), " \
        "s_region) = 1)"
    # multiple circles
    assert _gen_sql({'ra_dec': '1 20|40, 3'}) == common_select + \
        "((INTERSECTS(CIRCLE('ICRS',1.0,20.0,3.0), s_region) = 1) OR " \
        "(INTERSECTS(CIRCLE('ICRS',1.0,40.0,3.0), s_region) = 1))"
    assert _gen_sql({'ra_dec': '1|10 20|40, 1'}) == common_select + \
        "((INTERSECTS(CIRCLE('ICRS',1.0,20.0,1.0), s_region) = 1) OR " \
        "(INTERSECTS(CIRCLE('ICRS',1.0,40.0,1.0), s_region) = 1) OR " \
        "(INTERSECTS(CIRCLE('ICRS',10.0,20.0,1.0), s_region) = 1) OR " \
        "(INTERSECTS(CIRCLE('ICRS',10.0,40.0,1.0), s_region) = 1))"

    # test range
    assert _gen_sql({'ra_dec': '0.0..20.0 >20'}) == common_select + \
        "(INTERSECTS(RANGE_S2D(0.0,20.0,20.0,90.0), s_region) = 1)"
    assert _gen_sql({'ra_dec': '12:13:14..12:13:20 <4:20:20'}) == \
        common_select +\
        "(INTERSECTS(RANGE_S2D(12.220555555555556,12.222222222222223," \
        "-90.0,4.338888888888889), s_region) = 1)"
    assert _gen_sql({'ra_dec': '!(10..20) >60'}) == common_select + \
        "((INTERSECTS(RANGE_S2D(0.0,10.0,60.0,90.0), s_region) = 1) OR " \
        "(INTERSECTS(RANGE_S2D(20.0,0.0,60.0,90.0), s_region) = 1))"
    assert _gen_sql({'ra_dec': '0..20|40..60 <-50|>50'}) == common_select + \
        "((INTERSECTS(RANGE_S2D(0.0,20.0,-90.0,-50.0), s_region) = 1) OR " \
        "(INTERSECTS(RANGE_S2D(0.0,20.0,50.0,90.0), s_region) = 1) OR " \
        "(INTERSECTS(RANGE_S2D(40.0,60.0,-90.0,-50.0), s_region) = 1) OR " \
        "(INTERSECTS(RANGE_S2D(40.0,60.0,50.0,90.0), s_region) = 1))"

    # galactic frame
    center = coord.SkyCoord(1, 2, unit=u.deg, frame='galactic')
    assert _gen_sql({'galactic': '1 2, 3'}) == common_select + "(INTERSECTS(" \
        "CIRCLE('ICRS',{},{},3.0), s_region) = 1)".format(
        center.icrs.ra.to(u.deg).value, center.icrs.dec.to(u.deg).value)
    min_point = coord.SkyCoord('12:13:14.0',
                               '-00:01:02.1',
                               unit=u.deg,
                               frame='galactic')
    max_point = coord.SkyCoord('12:14:14.0',
                               '-00:00:02.1',
                               unit=(u.deg, u.deg),
                               frame='galactic')
    assert _gen_sql(
        {'galactic': '12:13:14.0..12:14:14.0 -00:01:02.1..-00:00:02.1'}) == \
        common_select +\
        "(INTERSECTS(RANGE_S2D({},{},{},{}), s_region) = 1)".format(
            min_point.icrs.ra.to(u.deg).value,
            max_point.icrs.ra.to(u.deg).value,
            min_point.icrs.dec.to(u.deg).value,
            max_point.icrs.dec.to(u.deg).value)

    # combination of frames
    center = coord.SkyCoord(1, 2, unit=u.deg, frame='galactic')
    assert _gen_sql({'ra_dec': '1 2, 3', 'galactic': '1 2, 3'}) == \
        "select * from ivoa.obscore WHERE " \
        "(INTERSECTS(CIRCLE('ICRS',1.0,2.0,3.0), s_region) = 1) AND " \
        "(INTERSECTS(CIRCLE('ICRS',{},{},3.0), s_region) = 1)".format(
        center.icrs.ra.to(u.deg).value, center.icrs.dec.to(u.deg).value)