예제 #1
0
파일: hec.py 프로젝트: Rapternmn/sunpy
def votable_handler(xml_table):
    """
    Returns a VOtable object from a VOtable style xml string

    In order to get a VOtable object, it has to be parsed from an xml file or
    file-like object. This function creates a file-like object via the
    StringIO module, writes the xml data to it, then passes the file-like
    object to parse_single_table() from the astropy.io.votable.table module
    and thereby creates a VOtable object.

    Parameters
    ----------
    xml_table: str
        Contains the VOtable style xml data

    Returns
    -------
    votable: astropy.io.votable.tree.Table
        A properly formatted VOtable object

    Examples
    --------
    >>> temp = hec.suds_unwrapper(xml_string)
    >>> type(temp)
    unicode
    >>> temp = hec.votable_handler(temp)
    >>> type(temp)
    astropy.io.votable.tree.Table
    """
    fake_file = io.StringIO()
    fake_file.write(xml_table)
    votable = parse_single_table(fake_file)
    fake_file.close()
    return votable
예제 #2
0
def test_parse_single_table2():
    table2 = parse_single_table(get_pkg_data_filename('data/regression.xml'),
                                table_number=1,
                                pedantic=False)
    assert isinstance(table2, tree.Table)
    assert len(table2.array) == 1
    assert len(table2.array.dtype.names) == 28
예제 #3
0
파일: hec.py 프로젝트: Cadair/sunpy
def votable_handler(xml_table):
    """
    Returns a VOtable object from a VOtable style xml string

    In order to get a VOtable object, it has to be parsed from an xml file or
    file-like object. This function creates a file-like object via the
    StringIO module, writes the xml data to it, then passes the file-like
    object to parse_single_table() from the astropy.io.votable.table module
    and thereby creates a VOtable object.

    Parameters
    ----------
    xml_table : `bytes`
        Contains the VOtable style xml data

    Returns
    -------
    votable : `astropy.io.votable.tree.Table`
        A properly formatted VOtable object

    """
    fake_file = io.BytesIO()
    fake_file.write(xml_table)
    votable = parse_single_table(fake_file)
    fake_file.close()
    return votable
예제 #4
0
파일: hec.py 프로젝트: vatch123/sunpy
def votable_handler(xml_table):
    """
    Returns a VOtable object from a VOtable style xml string

    In order to get a VOtable object, it has to be parsed from an xml file or
    file-like object. This function creates a file-like object via the
    StringIO module, writes the xml data to it, then passes the file-like
    object to parse_single_table() from the astropy.io.votable.table module
    and thereby creates a VOtable object.

    Parameters
    ----------
    xml_table : `bytes`
        Contains the VOtable style xml data

    Returns
    -------
    votable : `astropy.io.votable.tree.Table`
        A properly formatted VOtable object

    """
    fake_file = io.BytesIO()
    fake_file.write(xml_table)
    votable = parse_single_table(fake_file)
    fake_file.close()
    return votable
예제 #5
0
def votable_handler(xml_table):
    """
    Returns a VOtable object from a VOtable style xml string

    In order to get a VOtable object, it has to be parsed from an xml file or
    file-like object. This function creates a file-like object via the
    StringIO module, writes the xml data to it, then passes the file-like
    object to parse_single_table() from the astropy.io.votable.table module
    and thereby creates a VOtable object.

    Parameters
    ----------
    xml_table : str
        Contains the VOtable style xml data

    Returns
    -------
    votable : `astropy.io.votable.tree.Table`
        A properly formatted VOtable object

    Examples
    --------
    >>> from sunpy.net.helio import hec
    >>> temp = hec.suds_unwrapper(xml_string)  # doctest: +SKIP
    >>> type(temp)  # doctest: +SKIP
    unicode
    >>> temp = hec.votable_handler(temp)  # doctest: +SKIP
    >>> type(temp)  # doctest: +SKIP
    astropy.io.votable.tree.Table
    """
    fake_file = six.BytesIO()
    fake_file.write(six.b(xml_table))
    votable = parse_single_table(fake_file)
    fake_file.close()
    return votable
예제 #6
0
파일: vo_test.py 프로젝트: Cadair/astropy
def test_parse_single_table2():
    table2 = parse_single_table(
        get_pkg_data_filename('data/regression.xml'),
        table_number=1,
        pedantic=False)
    assert isinstance(table2, tree.Table)
    assert len(table2.array) == 1
    assert len(table2.array.dtype.names) == 28
예제 #7
0
def test_parse_single_table2():
    with np.errstate(over="ignore"):
        # https://github.com/astropy/astropy/issues/13341
        table2 = parse_single_table(get_pkg_data_filename('data/regression.xml'),
                                    table_number=1)
    assert isinstance(table2, tree.Table)
    assert len(table2.array) == 1
    assert len(table2.array.dtype.names) == 28
예제 #8
0
def test_gemini_v1_2():
    '''
    see Pull Request 4782 or Issue 4781 for details
    '''
    table = parse_single_table(get_pkg_data_filename('data/gemini.xml'))
    assert table is not None

    tt = table.to_table()
    assert tt['access_url'][0] == (
        'http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/data/pub/GEMINI/'
        'S20120515S0064?runid=bx9b1o8cvk1qesrt')
예제 #9
0
def getVOTable(url, table_number):
    """
    Returns VOTable from a URL and table number
    """
    tmp = tempfile.mkstemp(".xml", "pogs_fix", None, False)
    file_name = tmp[0]
    os.close(file_name)
    xml_file = tmp[1]
    try:
        req = urllib2.Request(url)
        response = urllib2.urlopen(req, timeout=10)
        with open(xml_file, 'w') as file_name:
            file_name.write(response.read())
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            table = parse_single_table(xml_file, pedantic=False, table_number=table_number)
    except:
        raise Exception("Problem contacting VOTable provider")
    finally:
        os.remove(xml_file)

    return table
예제 #10
0
def getVOTable(url, table_number):
    """
    Returns VOTable from a URL and table number
    """
    tmp = tempfile.mkstemp(".xml", "pogs_fix", None, False)
    file_name = tmp[0]
    os.close(file_name)
    xml_file = tmp[1]
    try:
        req = urllib2.Request(url)
        response = urllib2.urlopen(req, timeout=10)
        with open(xml_file, 'w') as file_name:
            file_name.write(response.read())
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            table = parse_single_table(xml_file,
                                       pedantic=False,
                                       table_number=table_number)
    except:
        raise Exception("Problem contacting VOTable provider")
    finally:
        os.remove(xml_file)

    return table
예제 #11
0
def test_gemini_v1_2():
    '''
    see Pull Request 4782 or Issue 4781 for details
    '''
    table = parse_single_table(get_pkg_data_filename('data/gemini.xml'))
    assert table is not None
예제 #12
0
def test_parse_single_table3():
    parse_single_table(get_pkg_data_filename('data/regression.xml'),
                       table_number=3)
예제 #13
0
def test_parse_single_table():
    table = parse_single_table(get_pkg_data_filename('data/regression.xml'))
    assert isinstance(table, tree.Table)
    assert len(table.array) == 5
예제 #14
0
def test_parse_single_table():
    with np.errstate(over="ignore"):
        # https://github.com/astropy/astropy/issues/13341
        table = parse_single_table(get_pkg_data_filename('data/regression.xml'))
    assert isinstance(table, tree.Table)
    assert len(table.array) == 5
예제 #15
0
def test_gemini_v1_2():
    '''
    see Pull Request 4782 or Issue 4781 for details
    '''
    table = parse_single_table(get_pkg_data_filename('data/gemini.xml'))
    assert table is not None
예제 #16
0
def test_parse_single_table3():
    with pytest.raises(IndexError):
        parse_single_table(get_pkg_data_filename('data/regression.xml'),
                           table_number=3)
예제 #17
0
파일: vo_test.py 프로젝트: Cadair/astropy
def test_parse_single_table3():
    parse_single_table(
        get_pkg_data_filename('data/regression.xml'),
        table_number=3, pedantic=False)
예제 #18
0
파일: vo_test.py 프로젝트: Cadair/astropy
def test_parse_single_table():
    table = parse_single_table(
        get_pkg_data_filename('data/regression.xml'),
        pedantic=False)
    assert isinstance(table, tree.Table)
    assert len(table.array) == 5