5 releases
0.2.0 | Apr 28, 2024 |
---|---|
0.1.3 | Apr 28, 2024 |
0.1.2 | Apr 28, 2024 |
0.1.1 | Apr 23, 2024 |
0.1.0 | Apr 23, 2024 |
#8 in #astronomical
9KB
180 lines
vizier-rs
A basic VizieR client for rust
Allows easy, type-safe access to VizieR TAP APIs to query a wide variety of astronomical catalogues using ADQL.
Installation
Run $ cargo add vizier-adql
, or add vizier-adql = "0.2.0"
to Cargo.toml
under [dependencies]
.
Basic, untyped usage
use vizier_adql::Client;
use serde_json::Value;
// 1. Create a client
let client = Client::default();
// 2. Execute queries
let objects = client
.query::<Value>("SELECT TOP 100 * FROM \"I/261/fonac\"")
.await
.unwrap()
.data();
// ...
Client::default()
will use http://tapvizier.u-strasbg.fr/TAPVizieR/tap/sync
as the TAP endpoint. If you need to specify a different endpoint, use Client::new("your_endpoint_url")
.
The VizieR column metadata is also available on the result via QueryResult::meta
.
Sync/Async
If you don't want to use async, enable the is_sync
feature on the crate. The API won't change, except that Client::query
now blocks and returns the value directly.
Typed usage
To strictly parse the response, create a struct resembling an element from the response and derive Deserialize
for it.
#[derive(Deserialize)]
struct CatalogObject {
AC2000: i32,
ACT: Option<i32>,
#[serde(rename = "B-R")]
BR: Option<f64>,
#[serde(rename = "B-V")]
BV: Option<f64>,
Bmag: f64,
DEJ2000: f64,
#[serde(rename = "Ep-1900")]
Ep1900: f64,
Qflag: Option<i32>,
RAJ2000: f64,
pmDE: f64,
pmRA: f64,
q_Bmag: Option<i32>,
recno: i32,
}
Then, query and parse like so:
let objects = client
.query::<CatalogObject>("SELECT TOP 100 * FROM \"I/261/fonac\"")
.await
.unwrap()
.data()
// ...
Dependencies
~4–15MB
~221K SLoC