コード例 #1
0
def test_references_context(references_file):
    """
    Test handling of REFERENCEs within GLOBAL and TEMPLATE
      o Elements in GLOBAL and TEMPLATE
        - reference element in GLOBAL
    """
    sky = references_file.find_instances( SkyCoordinate )
    assert len(sky) == 2

    assert not is_template( sky[0] )
    assert not is_template( sky[0].frame )
    assert is_template( sky[1] )
    assert not is_template( sky[1].frame )
コード例 #2
0
def test_global_source_position(source_data, recwarn):
    positions = source_data.find_instances(SourcePosition)

    assert len(positions) == 1
    pos = positions[0]
    assert not is_template(pos)  # positions are direct
    assert pos.coord.frame.name == 'icrs'
    assert pos.coord.ra.degree == 123.45
    assert pos.coord.dec.degree == 67.89
コード例 #3
0
def test_is_template(time_series, recwarn):
    gavo = time_series
    positions = gavo.find_instances(SkyPosition)
    cube_points = gavo.find_instances(NDPoint)
    axes = gavo.find_instances(DataAxis)

    assert not is_template(positions[0])  # positions are direct
    assert is_template(cube_points[0])  # ndpoint is a template
    assert is_template(axes[0])  # time
    assert not is_template(axes[1])  # position
    assert is_template(axes[2])  # magnitude
    assert is_template(axes[3])  # flux

    assert not is_template(gavo)  # an unrelated instance is never a template

    assert "W20" in str(recwarn[0].message)
    assert "W41" in str(recwarn[1].message)
    for i in range(2, 12):
        assert "W10" in str(recwarn[i].message)
コード例 #4
0
def test_source_unroll(context_test5, recwarn):
    template_source = context_test5.find_instances(Source)[0]
    assert is_template(template_source)
    assert count(template_source) == 3

    frame = context_test5.find_instances(SkyCoordinateFrame)[0]
    filters = context_test5.find_instances(PhotometryFilter)
    h_filter = filters[0]
    j_filter = filters[1]
    k_filter = filters[2]

    sources = unroll(template_source)

    assert len(sources) == 3
    source = sources[0]
    assert source.name == '08120809-0206132'
    assert source.position.longitude == template_source.position.longitude[0]
    assert source.position.latitude == template_source.position.latitude[0]
    assert source.position.frame is frame
    h_mag = source.luminosity[0]
    assert h_mag.type == 'magnitude'
    assert h_mag.filter is h_filter
    assert h_mag.value == template_source.luminosity[0].value[0]
    assert h_mag.error == template_source.luminosity[0].error[0]

    j_mag = source.luminosity[1]
    assert j_mag.type == 'magnitude'
    assert j_mag.filter is j_filter
    assert j_mag.value == template_source.luminosity[1].value[0]
    assert j_mag.error == template_source.luminosity[1].error[0]

    k_mag = source.luminosity[2]
    assert k_mag.type == 'magnitude'
    assert k_mag.filter is k_filter
    assert k_mag.value == template_source.luminosity[2].value[0]
    assert k_mag.error == template_source.luminosity[2].error[0]

    source = sources[1]
    assert source.name == '08115683-0205428'
    assert source.position.longitude == template_source.position.longitude[1]
    assert source.position.latitude == template_source.position.latitude[1]
    assert source.position.frame is frame
    h_mag = source.luminosity[0]
    assert h_mag.type == 'magnitude'
    assert h_mag.filter is h_filter
    assert h_mag.value == template_source.luminosity[0].value[1]
    assert h_mag.error == template_source.luminosity[0].error[1]

    j_mag = source.luminosity[1]
    assert j_mag.type == 'magnitude'
    assert j_mag.filter is j_filter
    assert j_mag.value == template_source.luminosity[1].value[1]
    assert j_mag.error == template_source.luminosity[1].error[1]

    k_mag = source.luminosity[2]
    assert k_mag.type == 'magnitude'
    assert k_mag.filter is k_filter
    assert k_mag.value == template_source.luminosity[2].value[1]
    assert k_mag.error == template_source.luminosity[2].error[1]

    source = sources[2]
    assert source.name == '08115826-0205336'
    assert source.position.longitude == template_source.position.longitude[2]
    assert source.position.latitude == template_source.position.latitude[2]
    assert source.position.frame is frame
    h_mag = source.luminosity[0]
    assert h_mag.type == 'magnitude'
    assert h_mag.filter is h_filter
    assert h_mag.value == template_source.luminosity[0].value[2]
    assert h_mag.error == template_source.luminosity[0].error[2]

    j_mag = source.luminosity[1]
    assert j_mag.type == 'magnitude'
    assert j_mag.filter is j_filter
    assert j_mag.value == template_source.luminosity[1].value[2]
    assert j_mag.error == template_source.luminosity[1].error[2]

    k_mag = source.luminosity[2]
    assert k_mag.type == 'magnitude'
    assert k_mag.filter is k_filter
    assert k_mag.value == template_source.luminosity[2].value[2]
    assert k_mag.error == template_source.luminosity[2].error[2]
コード例 #5
0
def test_is_template( sample_file, recwarn):
    """
    Tests parser.py::is_template()
    """
    gavo = sample_file

    sources = gavo.find_instances(Source)
    assert len(sources) == 2

    # Check instance types -- method output depends on type
    #   Only VO-Objects can be tagged as templates
    assert isinstance( sources[0], Source )                       # VO Instance
    assert isinstance( sources[0].position, SkyCoordinate )       # VO Instance
    assert isinstance( sources[0].position_error, CircleError )   # VO Instance
    assert isinstance( sources[0].position.longitude, Quantity )  # Astropy Quantity
    assert isinstance( sources[0].position.latitude,  Quantity )  # Astropy Quantity

    # GLOBAL position
    assert not is_template(sources[0].position)
    assert not is_template(sources[0].position_error)
    assert not is_template(sources[0].position.longitude)
    assert not is_template(sources[0].position.latitude)
    assert not is_template(sources[0].position.latitude)
    assert not is_template(sources[0].position_error.radius)

    # TEMPLATE position
    assert is_template(sources[1].position)
    assert is_template(sources[1].position_error)
    assert not is_template(sources[1].position.longitude)
    assert not is_template(sources[1].position.latitude)
    assert not is_template(sources[1].position.latitude)
    assert not is_template(sources[1].position_error.radius)
    
    # Something totally not in Models: Reader class
    assert not is_template(gavo)

    assert len(recwarn) == 0
コード例 #6
0
def test_parsing_attributes( attributes_file ):
    """
    Test parsing of ATTRIBUTE elements 
      <ATTRIBUTE [dmrole] >
        ->(<COLUMN>|<CONSTANT>|<LITERAL>)
        -><INSTANCE>
      </ATTRIBUTE>

    NOTE: This test is for the handling of ATTRIBUTE contents
          at the high level.  Detailed testing of the contained
          elements are covered by other tests.
    """
    sources = attributes_file.find_instances(Source)
    assert len(sources) == 2

    expected_lon = numpy.array([122.99277, 122.986794, 123.033734], dtype='float64') * u.Unit('deg')
    expected_lat = numpy.array([ -2.092676, -2.095231,  -2.103671], dtype='float64') * u.Unit('deg')
    expected_ra_err  = numpy.array([0.3, 0.3, 0.3], dtype='float64')
    expected_dec_err = numpy.array([0.4, 0.4, 0.4], dtype='float64')

    # ----------------------------------------------------------------------
    # GLOBALS context:
    #
    # Check ATTRIBUTE with INSTANCE content
    #   Soure.position      == SkyCoordinate
    #   Soure.positionError == AlignedEllipse
    source = sources[0]
    assert source.position is not None
    assert source.position_error is not None

    # Check is_template assignment for each object
    assert not is_template(source)                 # - top tier object
    assert not is_template(source.position)        # - second tier child with LITERALs
    assert not is_template(source.position_error)  # - second tier child with CONSTANTs

    # Check ATTRIBUTE with LITERAL content
    position = source.position
    assert position.longitude == 122.992773 * u.Unit("deg")
    assert position.latitude ==   -2.092676 * u.Unit("deg")

    # Check ATTRIBUTE with CONSTANT content
    err = source.position_error
    assert err.long_error == 0.1
    assert err.lat_error  == 0.2

    # ----------------------------------------------------------------------
    # TEMPLATES context:
    #
    source = sources[1]
    assert source.position is not None
    assert source.position_error is not None

    # Check is_template assignment for each object
    assert is_template(source)                     # - top tier object
    assert is_template(source.position)            # - second tier child with COLUMNs
    assert is_template(source.position_error)      # - second tier child with CONSTANT/LITERAL
    
    # Check ATTRIBUTE with COLUMN content in TEMPLATE context
    assert len(source.position.longitude) == 3
    assert len(source.position.latitude)  == 3
    assert source.position.longitude[0] == expected_lon[0]
    assert source.position.longitude[1] == expected_lon[1]
    assert source.position.longitude[2] == expected_lon[2]
    assert source.position.latitude[0]  == expected_lat[0]
    assert source.position.latitude[1]  == expected_lat[1]
    assert source.position.latitude[2]  == expected_lat[2]

    # Check ATTRIBUTE with CONSTANT content
    #assert len(source.position_error.long_error) == 3
    #assert source.position_error.long_error == expected_ra_err
    assert source.position_error.long_error == expected_ra_err[0]

    # Check ATTRIBUTE with LITERAL content
    #assert len(source.position_error.lat_error) == 3
    #assert source.position_error.lat_error == expected_dec_err
    assert source.position_error.lat_error == expected_dec_err[0]
コード例 #7
0
def test_source_unroll(context_test5, recwarn):

    # Frame instance
    # - is a GLOBALS instance, only have 1 spec'd
    #   - is singular, cardinality = 0
    frame = context_test5.find_instances(SkyCoordinateFrame)[0]
    t = frame.unroll()
    assert len(t) == 0   # <== t = []

    # PhotometryFilters
    # - is a GLOBALS instance, have 3 spec'd
    # - find returns [filter,filter,filter]
    #   - each filter is singular, cardinality = 0
    filters = context_test5.find_instances(PhotometryFilter)
    h_filter = filters[0]
    j_filter = filters[1]
    k_filter = filters[2]

    t = h_filter.unroll()
    assert len(t) == 0   # <== t = []

    # SkyCoordinate
    # - is a TEMPLATE instance, have 1 spec'd with 3 rows in table.
    pos = context_test5.find_instances(SkyCoordinate)
    assert len(pos) == 1
    assert len(pos[0].longitude) == 3

    t = pos[0].unroll()  # <== t = [SkyCoordinate, SkyCoordinate, SkyCoordinate]
    assert len(t) == 3
    for n in range(len(t)):
        assert t[n].longitude == pos[0].longitude[n]
        assert t[n].latitude == pos[0].latitude[n]
        assert t[n].frame is frame
    
    # LuminosityMeasurement
    # - This just gets ALL LuminosityMeasurement instances
    # - is a TEMPLATE instance, have 3 spec'd with 3 rows each
    #                           PLUS some from EXTINSTANCES (second table)
    # - end up with 4 instances, Quantity with 3 rows in first 3
    #                            MaskedColumn with 6 rows in 4th (no units)
    lum = context_test5.find_instances(LuminosityMeasurement)
    assert len(lum) == 4
    assert len(lum[0].value) == 3
    assert len(lum[1].value) == 3
    assert len(lum[2].value) == 3
    assert len(lum[3].value) == 6

    for ii in range(len(lum)):
        t = lum[ii].unroll()
        assert len(t) == 3 if ii < 2 else 6
        for n in range(len(t)):
            assert t[n].type  == lum[ii].type      # singular.. not type[n]
            assert t[n].value == lum[ii].value[n]  # Quantity w/ n values
            assert t[n].error == lum[ii].error[n]  # Quantity w/ n values
            if ii < 3:
                assert t[n].filter is filters[ii]  # ref to filter is still reference
            else:
                assert t[n].filter is None

    # ================================================================================
    # So the atomic level seems to be OK.
    # Next unroll Source: fully within TEMPLATES, contains the above
    template_source = context_test5.find_instances(Source)[0]
    assert is_template(template_source)
    assert template_source.cardinality == 3  #<== check the no. of instances from TEMPLATE

    # unroll it
    #sources = unroll(template_source)
    sources = template_source.unroll()

    assert len(sources) == 3
    assert len(sources[0].luminosity) == 5  # 3 local + 2 external instances

    for n in range(len(sources)):
        #assert sources[n].name == '08120809-0206132'
        assert sources[n].name == template_source.name[n]
        assert sources[n].position.longitude == template_source.position.longitude[n]
        assert sources[n].position.latitude == template_source.position.latitude[n]
        assert sources[n].position.frame is frame
        h_mag = sources[n].luminosity[0]
        assert h_mag.type == 'magnitude'
        assert h_mag.filter is h_filter
        assert h_mag.value == template_source.luminosity[0].value[n]
        assert h_mag.error == template_source.luminosity[0].error[n]
        #
        j_mag = sources[n].luminosity[1]
        assert j_mag.type == 'magnitude'
        assert j_mag.filter is j_filter
        assert j_mag.value == template_source.luminosity[1].value[n]
        assert j_mag.error == template_source.luminosity[1].error[n]
        #
        k_mag = sources[n].luminosity[2]
        assert k_mag.type == 'magnitude'
        assert k_mag.filter is k_filter
        assert k_mag.value == template_source.luminosity[2].value[n]
        assert k_mag.error == template_source.luminosity[2].error[n]

        # external instances, may be None; organized differently in packed representation
        g_mag = sources[n].luminosity[3]
        if n == 1:
            assert g_mag is None
            assert g_mag == template_source.luminosity[3][n]
        else:
            assert g_mag.type == 'magnitude'
            assert g_mag.filter is None
            assert g_mag.value == template_source.luminosity[3][n].value
            assert g_mag.error == template_source.luminosity[3][n].error

        g_mag = sources[n].luminosity[4]
        if n != 2:
            assert g_mag is None
            assert g_mag == template_source.luminosity[4][n]
        else:
            assert g_mag.type == 'magnitude'
            assert g_mag.filter is None
            assert g_mag.value == template_source.luminosity[4][n].value
            assert g_mag.error == template_source.luminosity[4][n].error