Welcome to spv-rs!


This crate is a set of functions for either extracting or manipulating astronomcial data.
However it is (at least for now) mainly focused on position and velocity data.
Examples
First if you want to see a calculator like application usecase please check the sourcecode for the SPV gui utility at SPV github repo.
Now we will look at the position function as an example:
For the [position::position] function we use three input variables. Parallax for the distance to the object, you can read more about parallax here.
Right ascension and Declination is basically a dots position on a sphere where the distance we get from the Parllax is the radius of the sphere.
One easy way to use this function if you had the required variables would be like this:
use spv_rs::position::position;
use glam::f64::DVec3;
fn main() {
let parallax = 1.5_f64;
let right_ascension = 35.8_f64;
let declination = 67.3_f64;
let body_name = "x";
let position = position(parallax, right_ascension, declination).to_array();
println!("The body {} was as the position x: {}, y: {}, z: {} at epoch J2000",
body_name, position[0], position[1], position[2]);
}
The same general principles apply to most functions.
Now for a more complex example, let's say that we wanted to parse a csv with the collums
parallax, right_ascension, declination, proper_motion_ra, proper_motion_dec and radial_velocity.
Aka not the exact layout found in [input_data::parse_csv_deserialize].
We want the position and velocity of the bodies in the list in the cartesian coordinate system printed to the terminal for now.
use spv_rs::position::position;
use spv_rs::velocity::velocity;
use csv::StringRecord;
use serde::Deserialize;
use std::error::Error;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct Collums {
parallax: f64,
right_ascension: f64,
declination: f64,
proper_motion_ra: f64,
proper_motion_dec: f64,
radial_velocity: f64,
}
fn main() {
let mut data = vec![];
match spv_rs::input_data::parse_csv("some_file.csv") {
Ok(vec) => data = vec,
Err(ex) => {
println!("ERROR -> {}", ex);
}
}
let mut deserialized_data = vec![];
match deserialize(data) {
Ok(vec) => deserialized_data = vec,
Err(ex) => {
println!("ERROR -> {}", ex);
}
}
for i in deserialized_data {
let position = position(i.parallax, i.right_ascension, i.declination).to_array();
let velocity = velocity(i.parallax, i.right_ascension, i.declination,
i.proper_motion_ra, i.proper_motion_dec, i.radial_velocity).to_array();
println!("This bodies position is: ({}, {}, {}) and it's velocity is ({}, {}, {})",
position[0], position[1], position[2], velocity[0], velocity[1], velocity[2])
}
}
fn deserialize(
data: std::vec::Vec<StringRecord>
) -> Result<std::vec::Vec<Collums>, Box<dyn Error>> {
let mut vec = vec![];
for result in data {
let record: Collums = result.deserialize(None)?;
vec.push(record);
}
Ok(vec)
}
Extra
Feel free to propose additions/changes, file issues and or help with the project over on GitHub!