votable or VOTLibRust
Library to read/write VOTables in Rust and to convert them in JSON, YAML, TOML and back to XML.
VOT Lib Rust is used in:
- VOTCli convert VOTables from the command line;
- VOTWasm read/write and convert VOTables in Web Browsers.
Status
This library is in an early stage of development.
We are (reasonably) open to changes in the various format, e.g.:
- we could flag attributes with a '@' prefix
- we could use upper case elements tag names
- we could remove the 's' suffix in elements arrays
- we could change the
post_infosname for something else - ...
More testing is required, especially the bit type and arrays. Please, provide us with your VOTable examples!
Why JSON, TOML, YAML in addition to XML
VOTable is an XML based format. Why other formats?
- JSON: to easily manipulate VOTable data in Web Browsers since JSON represent JavaScript objects (and all browsers parse JSON into JavaScript objects natively).
- TOML: to easily update manually VOTables (especially the metadata part of VOTables). Moreover, it is quite compact.
- YAML: because some people like it, and it was almost free to implement (thanks to serde).
Motivations
- Support natively the VOTable format in the new CDS internal tool
qat2s(tool to query and manipulate possibly large catalogues with multi-thread capabilities). - Store VizieR (large) catalogues rich metadata in a user friendly format (TOML) while
being able to return the same VOTable header as VizieR (without using a database connexion).
- for
qat2s,ExXmatch,progressive catalogue
- for
- Add a Rust VOTable parsing and writting library for Aladin Lite V3
- ...
Design choices and problems
The default provided implementation converting from JSON/YAML/TOML does not
focus on performancs since we do not use the VOTable FIELDs information but
deserialize each table field in the first succeeding VOTableValue
(see votable::impls::Schema.serialize_seed).
VOT Lib resort heavily on serde.
This library has been design to preserve the order of VOTable TAGs when
converting back on forth in XML, JSON, ...
But, so far:
- XML comments are ignored and lost ;
- CDATA block are ignored and lost.
In JSON/TOML/YAML, for the VOTABLE and RESOURCE elements, we make a difference between INFO blocks located before and after the RESOURCE element(s). We use infos (only for RESOURCE) and post_infos arrays. Quoting the IVOA document:
The INFO element may occur before the closing tags /TABLE and /RESOURCE and /VOTABLE (enables post-operational diagnostics)
(we wonder if post-operational diagnostics should not have a name different from INFO in VOTables).
In JSON/TOML/YAML, for VOTABLE, RESOURCE, TABLE and GROUP elements, we group together the "open bullet" (see 7.1 of the VOTable standard) elements in an elements array containing objects having an "elem_type" attribute set to one of: Info, Field, Coosys, Timesys, Group, Param, ...
Internally we make a difference (different struct/class) between GROUP in VOTABLE and RESOURCE from GROUP in TABLE since in the later case the GROUP may contain FIELDRef.
In JSON/TOML/YAML, there is no difference between attribute and sub-elements names (all in camel case).
WARNINGS
- TOML does not supports
null(we so far convertnullvalues by an empty string). - The default provided implementation loads all data in memory, so it is not adapted for large files!
Other way to convert from VOTable to JSON
The XML2JSON conversion has been exercised
by Laurent Michel
in the context of the processing of model annotations in VOTables
(the MIVOT).
The use case is to convert model instances, serialized in XML, into JSON messages.
The conversion is using standard Python tools (xmltodic module).
The code below is extracted from the client code project.
It is to be noted that the translation rules are not PYTHON (nor VOTable) specific,
they are also implemented in e.g. XSLT.
return
return
return
return
=
=
=
=
Advantages:
- standard
- few lines of python
Inconvenient:
- the order of elements (especially INFOs and post processing INFOs) is lost
- it is a one way conversion (not possible to then convert from JSON to VOTable)
Example
Several outputs obtained from the same API made VOTable.
Rust code (API created VOTable)
let rows = vec!;
let data_content = new;
let table = new
.set_id
.set_name
.set_description
.push_field.push_field.push_field.set_data;
let resource = default
.set_id
.set_name
.set_description
.push_coosys
.push_coosys
.push_table
.push_post_info;
let mut votable = new
.set_id
.set_version
.set_description
.push_info;
Remark: the coherence between user input VOTableValue and declared Fields is checked
only when serializing in BINARY or BINARY2.
VOTable
VizieR Astronomical Server vizier.u-strasbg.fr
Photometric and spectroscopic catalog of objects in the field around HE0226-4110
SDSS photometric catalog
Right Ascension of the object (ICRS) (ra)
[*] Multiple SDSS12 name
[4/38]? Model magnitude in u filter, AB scale (u) (5)
NaN
*
14.52
1.25
-1.2
truncated result (maxtup=2)
JSON
TOML
[]
= 'my_votable'
= '1.4'
= 'VizieR Astronomical Server vizier.u-strasbg.fr'
[[]]
= 'Info'
= 'VERSION'
= 'votable-version'
= '1.99+ (14-Oct-2013)'
[[]]
= 'yCat_17011219'
= 'J/ApJ/701/1219'
= 'Photometric and spectroscopic catalog of objects in the field around HE0226-4110'
[[]]
= 'CooSys'
= 'J2000'
= 'eq_FK4'
= 2000.0
[[]]
= 'CooSys'
= 'J2015.5'
= 'ICRS'
= 2015.5
[[]]
= 'V_147_sdss12'
= 'V/147/sdss12'
= 'SDSS photometric catalog'
[[]]
= 'Field'
= 'RA_ICRS'
= 'double'
= 'deg'
= '6'
= 10
= 'pos.eq.ra;meta.main'
= 'Right Ascension of the object (ICRS) (ra)'
[[]]
= 'Field'
= 'm_SDSS12'
= 'char'
= '6'
= 10
= 'meta.code.multip'
= '1'
= '[*] Multiple SDSS12 name'
[[]]
= 'http://vizier.u-strasbg.fr/viz-bin/VizieR-4?-info=XML&-out.add=.&-source=V/147&SDSS12=${SDSS12}'
[[]]
= 'Field'
= 'umag'
= 'float'
= 'mag'
= '3'
= 6
= 'phot.mag;em.opt.U'
= '[4/38]? Model magnitude in u filter, AB scale (u) (5)'
[]
= 'NaN'
[]
= 'TableData'
= [
[
nan,
'*',
14.52,
],
[
1.25,
'',
-1.2,
],
]
[[]]
= 'QUERY_STATUS'
= 'OVERFLOW'
= 'truncated result (maxtup=2)'
YAML
votable:
ID: my_votable
version: '1.4'
description: VizieR Astronomical Server vizier.u-strasbg.fr
elems:
- elem_type: Info
ID: VERSION
name: votable-version
value: 1.99+ (14-Oct-2013)
resources:
- ID: yCat_17011219
name: J/ApJ/701/1219
description: Photometric and spectroscopic catalog of objects in the field around
HE0226-4110
elems:
- elem_type: CooSys
ID: J2000
system: eq_FK4
equinox: 2000.0
- elem_type: CooSys
ID: J2015.5
system: ICRS
epoch: 2015.5
tables:
- id: V_147_sdss12
name: V/147/sdss12
description: SDSS photometric catalog
elems:
- elem_type: Field
name: RA_ICRS
datatype: double
unit: deg
precision: '6'
width: 10
ucd: pos.eq.ra;meta.main
description: Right Ascension of the object (ICRS) (ra)
- elem_type: Field
name: m_SDSS12
datatype: char
precision: '6'
width: 10
ucd: meta.code.multip
arraysize: '1'
description: '[*] Multiple SDSS12 name'
links:
- href: http://vizier.u-strasbg.fr/viz-bin/VizieR-4?-info=XML&-out.add=.&-source=V/147&SDSS12=${SDSS12}
- elem_type: Field
name: umag
datatype: float
unit: mag
precision: '3'
width: 6
ucd: phot.mag;em.opt.U
description: '[4/38]? Model magnitude in u filter, AB scale (u) (5)'
values:
'null': NaN
data:
data_type: TableData
rows:
- - .nan
- '*'
- 14.52
- - 1.25
- null
- -1.2
post_infos:
- name: QUERY_STATUS
value: OVERFLOW
content: truncated result (maxtup=2)
Example: Iterate on both Tables and Rows of a VOTable
let mut votable_it = from_file?;
while let Some = votable_it.next_table_row_value_iter?
let votable = votable_it.end_of_it;
println!;
To-do list
- Support
CDATA? - Fill the doc for the Rust library (but I so far do not know people interested in such a lib since Rust is not very used in the astronomy community so far, so...)
- Add a check method ensuring that user input VOTAbleValue (using the API to build a VOTable) matches the table schema (or automatically converting in the right VOTableValue)
- Add much more tests!
- Add possibility to convert to/from
TABLEDATA,BINARY,BINARY2 - Enrich
votable::impls::Schema.serialize_seed(possible bugs when deserializing JSON/TOML/YAML arrays and converting to BINARY or BINARY2) - Write a custom deserializer for
VOTableValue(look at cargo-expand output for a basis) - Implements
toCSV(but notfromCSV) - ...
License
Like most projects in Rust, this project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.