vizier-adql

Crates.iovizier-adql
lib.rsvizier-adql
version0.2.0
sourcesrc
created_at2024-04-23 18:05:25.546342
updated_at2024-04-28 16:07:32.622064
descriptionSimple Rust client for querying astronomical data from VizieR using ADQL
homepage
repositoryhttps://github.com/mclrc/vizier-rs
max_upload_size
id1217840
size9,572
Moritz (mclrc)

documentation

README

vizier-rs

Tests Crates.io

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()

// ...
Commit count: 19

cargo fmt