Ejemplo n.º 1
0
def test_vararray():
    votable = tree.VOTableFile()
    resource = tree.Resource()
    votable.resources.append(resource)
    table = tree.Table(votable)
    resource.tables.append(table)

    tabarr = []
    heads = ['headA', 'headB', 'headC']
    types = ["char", "double", "int"]

    vals = [["A", 1.0, 2], ["B", 2.0, 3], ["C", 3.0, 4]]
    for i in range(len(heads)):
        tabarr.append(
            tree.Field(votable,
                       name=heads[i],
                       datatype=types[i],
                       arraysize="*"))

    table.fields.extend(tabarr)
    table.create_arrays(len(vals))
    for i in range(len(vals)):
        values = tuple(vals[i])
        table.array[i] = values
    buff = io.BytesIO()
    votable.to_xml(buff)
Ejemplo n.º 2
0
def test_make_Fields():
    votable = tree.VOTableFile()
    # ...with one resource...
    resource = tree.Resource()
    votable.resources.append(resource)

    # ... with one table
    table = tree.Table(votable)
    resource.tables.append(table)

    table.fields.extend(
        [tree.Field(votable, name='Test', datatype="float", unit="mag")])
Ejemplo n.º 3
0
def test_build_from_scratch(tmpdir):
    # Create a new VOTable file...
    votable = tree.VOTableFile()

    # ...with one resource...
    resource = tree.Resource()
    votable.resources.append(resource)

    # ... with one table
    table = tree.Table(votable)
    resource.tables.append(table)

    # Define some fields
    table.fields.extend([
        tree.Field(votable,
                   ID="filename",
                   name='filename',
                   datatype="char",
                   arraysize='1'),
        tree.Field(votable,
                   ID="matrix",
                   name='matrix',
                   datatype="double",
                   arraysize="2x2")
    ])

    # Now, use those field definitions to create the numpy record arrays, with
    # the given number of rows
    table.create_arrays(2)

    # Now table.array can be filled with data
    table.array[0] = ('test1.xml', [[1, 0], [0, 1]])
    table.array[1] = ('test2.xml', [[0.5, 0.3], [0.2, 0.1]])

    # Now write the whole thing to a file.
    # Note, we have to use the top-level votable file object
    votable.to_xml(str(tmpdir.join("new_votable.xml")))

    votable = parse(str(tmpdir.join("new_votable.xml")))

    table = votable.get_first_table()
    assert_array_equal(
        table.array.mask,
        np.array([(False, [[False, False], [False, False]]),
                  (False, [[False, False], [False, False]])],
                 dtype=[('filename', '?'), ('matrix', '?', (2, 2))]))
Ejemplo n.º 4
0
def test_resource_structure():
    # Based on issue #1223, as reported by @astro-friedel and @RayPlante
    from astropy.io.votable import tree as vot

    vtf = vot.VOTableFile()

    r1 = vot.Resource()
    vtf.resources.append(r1)
    t1 = vot.Table(vtf)
    t1.name = "t1"
    t2 = vot.Table(vtf)
    t2.name = 't2'
    r1.tables.append(t1)
    r1.tables.append(t2)

    r2 = vot.Resource()
    vtf.resources.append(r2)
    t3 = vot.Table(vtf)
    t3.name = "t3"
    t4 = vot.Table(vtf)
    t4.name = "t4"
    r2.tables.append(t3)
    r2.tables.append(t4)

    r3 = vot.Resource()
    vtf.resources.append(r3)
    t5 = vot.Table(vtf)
    t5.name = "t5"
    t6 = vot.Table(vtf)
    t6.name = "t6"
    r3.tables.append(t5)
    r3.tables.append(t6)

    buff = io.BytesIO()
    vtf.to_xml(buff)

    buff.seek(0)
    vtf2 = parse(buff)

    assert len(vtf2.resources) == 3

    for r in range(len(vtf2.resources)):
        res = vtf2.resources[r]
        assert len(res.tables) == 2
        assert len(res.resources) == 0
Ejemplo n.º 5
0
import numpy as np
import glob
from astropy.io.votable import parse

nm = glob.glob('./*.png')[0]
imArr = misc.imread(nm).astype(np.int32)
r, c = imArr.shape
# print imArr.dtype

votable = vo.VOTableFile()

resource = vo.Resource()

votable.resources.append(resource)  # appending resource into votable

table = vo.Table(votable)
resource.tables.append(table)
table.description = 'Lette A from non-MNIST set'

group = vo.Group(table)
table.groups.append(group)
para = vo.Param(votable,
                name='label',
                datatype='char',
                arraysize='1',
                value='A')
group.entries.append(para)

# table.fields.extend([ \
#       vo.Field(votable, name="filename", datatype="char", arraysize="*"), \
#       vo.Field(votable, name="matrix", datatype="double", arraysize="2x2")])