diff --git a/src/kete/rust/fitting.rs b/src/kete/rust/fitting.rs index e9a0fe6..2be4e2a 100644 --- a/src/kete/rust/fitting.rs +++ b/src/kete/rust/fitting.rs @@ -2,7 +2,6 @@ use kete_core::{fitting, stats}; use pyo3::pyfunction; - /// Perform a KS test between two vectors of values. #[pyfunction] #[pyo3(name = "ks_test")] diff --git a/src/kete/rust/fovs/checks.rs b/src/kete/rust/fovs/checks.rs index f3a9fa5..535ff0b 100644 --- a/src/kete/rust/fovs/checks.rs +++ b/src/kete/rust/fovs/checks.rs @@ -110,7 +110,7 @@ pub fn fov_checks_py( } /// Check if a list of loaded spice kernel objects are visible in the provided FOVs. -/// +/// /// Returns only the objects which are visible to the observer, adding a correction /// for optical light delay. /// diff --git a/src/kete/rust/vector.rs b/src/kete/rust/vector.rs index 0bdd149..3cbd41c 100644 --- a/src/kete/rust/vector.rs +++ b/src/kete/rust/vector.rs @@ -71,7 +71,7 @@ impl VectorLike { #[pymethods] impl Vector { - /// create new vector + /// create new vector #[new] #[pyo3(signature = (raw, frame=None))] pub fn py_new(raw: VectorLike, frame: Option) -> PyResult { diff --git a/src/kete_core/benches/propagation.rs b/src/kete_core/benches/propagation.rs index 1bc4c91..18a4639 100644 --- a/src/kete_core/benches/propagation.rs +++ b/src/kete_core/benches/propagation.rs @@ -2,9 +2,9 @@ extern crate criterion; use std::time::Duration; use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; -use lazy_static::lazy_static; use kete_core::prelude::*; use kete_core::*; +use lazy_static::lazy_static; use pprof::criterion::{Output, PProfProfiler}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; diff --git a/src/kete_core/src/elements.rs b/src/kete_core/src/elements.rs index e687dc7..6fa89c6 100644 --- a/src/kete_core/src/elements.rs +++ b/src/kete_core/src/elements.rs @@ -1,7 +1,7 @@ //! # Orbital Elements //! This allows conversion to and from cometary orbital elements to [`State`]. use crate::constants::GMS_SQRT; -use crate::prelude::{Desig, Frame, NeosResult, State}; +use crate::prelude::{Desig, Frame, KeteResult, State}; use crate::propagation::{compute_eccentric_anomaly, compute_true_anomaly, PARABOLIC_ECC_LIMIT}; use nalgebra::Vector3; @@ -173,7 +173,7 @@ impl CometElements { /// Convert cometary elements to an [`State`] if possible. /// /// Center ID is set to 10. - pub fn try_to_state(&self) -> NeosResult { + pub fn try_to_state(&self) -> KeteResult { let [pos, vel] = self.to_pos_vel()?; Ok(State::new( self.desig.to_owned(), @@ -187,7 +187,7 @@ impl CometElements { /// Convert orbital elements into a cartesian coordinate position and velocity. /// Units are in AU and AU/Day. - fn to_pos_vel(&self) -> NeosResult<[[f64; 3]; 2]> { + fn to_pos_vel(&self) -> KeteResult<[[f64; 3]; 2]> { let elliptical = self.eccentricity < 1.0 - PARABOLIC_ECC_LIMIT; let hyperbolic = self.eccentricity > 1.0 + PARABOLIC_ECC_LIMIT; let parabolic = !elliptical & !hyperbolic; @@ -264,7 +264,7 @@ impl CometElements { } /// Compute the eccentric anomaly for the cometary elements. - pub fn eccentric_anomaly(&self) -> NeosResult { + pub fn eccentric_anomaly(&self) -> KeteResult { compute_eccentric_anomaly(self.eccentricity, self.mean_anomaly(), self.peri_dist).map(|x| { match self.eccentricity { ecc if ecc > 1.0 - PARABOLIC_ECC_LIMIT => x, @@ -315,7 +315,7 @@ impl CometElements { /// Compute the True Anomaly /// The angular distance between perihelion and the current position as seen /// from the origin. - pub fn true_anomaly(&self) -> NeosResult { + pub fn true_anomaly(&self) -> KeteResult { compute_true_anomaly(self.eccentricity, self.mean_anomaly(), self.peri_dist) } } diff --git a/src/kete_core/src/errors.rs b/src/kete_core/src/errors.rs index 3b68371..f6e2bd2 100644 --- a/src/kete_core/src/errors.rs +++ b/src/kete_core/src/errors.rs @@ -7,7 +7,7 @@ use chrono::ParseError; use std::{error, fmt, io}; /// kete specific result. -pub type NeosResult = Result; +pub type KeteResult = Result; /// Possible Errors which may be raised by this crate. #[derive(Debug, Clone)] diff --git a/src/kete_core/src/fitting/halley.rs b/src/kete_core/src/fitting/halley.rs index b981fee..7a3ddb5 100644 --- a/src/kete_core/src/fitting/halley.rs +++ b/src/kete_core/src/fitting/halley.rs @@ -3,7 +3,7 @@ //! Third order root finding algorithm. //! This is the next order method of newton-raphson. -use crate::{errors::Error, prelude::NeosResult}; +use crate::{errors::Error, prelude::KeteResult}; /// Solve root using Halley's method. /// @@ -27,7 +27,7 @@ pub fn halley( sec_der: SecDer, start: f64, atol: f64, -) -> NeosResult +) -> KeteResult where Func: Fn(f64) -> f64, Der: Fn(f64) -> f64, diff --git a/src/kete_core/src/fitting/newton.rs b/src/kete_core/src/fitting/newton.rs index 74dc1bb..c74776b 100644 --- a/src/kete_core/src/fitting/newton.rs +++ b/src/kete_core/src/fitting/newton.rs @@ -1,4 +1,4 @@ -use crate::{errors::Error, prelude::NeosResult}; +use crate::{errors::Error, prelude::KeteResult}; /// Solve root using the Newton-Raphson method. /// @@ -15,7 +15,7 @@ use crate::{errors::Error, prelude::NeosResult}; /// ``` /// #[inline(always)] -pub fn newton_raphson(func: Func, der: Der, start: f64, atol: f64) -> NeosResult +pub fn newton_raphson(func: Func, der: Der, start: f64, atol: f64) -> KeteResult where Func: Fn(f64) -> f64, Der: Fn(f64) -> f64, diff --git a/src/kete_core/src/flux/reflected.rs b/src/kete_core/src/flux/reflected.rs index 723c5d7..6bc4615 100644 --- a/src/kete_core/src/flux/reflected.rs +++ b/src/kete_core/src/flux/reflected.rs @@ -1,7 +1,7 @@ use super::sun::solar_flux_black_body; use crate::{ constants::{AU_KM, C_V}, - prelude::{Error, NeosResult}, + prelude::{Error, KeteResult}, }; use nalgebra::Vector3; @@ -117,7 +117,7 @@ impl HGParams { c_hg: Option, vis_albedo: Option, diam: Option, - ) -> NeosResult { + ) -> KeteResult { let (h_mag, vis_albedo, diam, c_hg) = Self::fill(h_mag, vis_albedo, diam, c_hg)?; Ok(Self { desig, @@ -151,7 +151,7 @@ impl HGParams { vis_albedo: Option, diam: Option, c_hg: Option, - ) -> NeosResult<(f64, Option, Option, f64)> { + ) -> KeteResult<(f64, Option, Option, f64)> { if h_mag.is_none() && (vis_albedo.is_none() || diam.is_none()) { Err(Error::ValueError( "h_mag must be defined unless both vis_albedo and diam are provided.".into(), diff --git a/src/kete_core/src/fov/fov_like.rs b/src/kete_core/src/fov/fov_like.rs index 8db6401..46dc61f 100644 --- a/src/kete_core/src/fov/fov_like.rs +++ b/src/kete_core/src/fov/fov_like.rs @@ -28,7 +28,7 @@ pub trait FovLike: Sync + Sized { fn n_patches(&self) -> usize; /// Change the target frame to the new frame. - fn try_frame_change_mut(&mut self, new_frame: Frame) -> NeosResult<()>; + fn try_frame_change_mut(&mut self, new_frame: Frame) -> KeteResult<()>; /// Check if a static source is visible. This assumes the vector passed in is at an /// infinite distance from the observer. @@ -68,7 +68,7 @@ pub trait FovLike: Sync + Sized { /// Assuming the object undergoes two-body motion, check to see if it is within the /// field of view. #[inline] - fn check_two_body(&self, state: &State) -> NeosResult<(usize, Contains, State)> { + fn check_two_body(&self, state: &State) -> KeteResult<(usize, Contains, State)> { let obs = self.observer(); let obs_pos: Vector3<_> = obs.pos.into(); @@ -91,7 +91,7 @@ pub trait FovLike: Sync + Sized { &self, state: &State, include_asteroids: bool, - ) -> NeosResult<(usize, Contains, State)> { + ) -> KeteResult<(usize, Contains, State)> { let obs = self.observer(); let obs_pos = Vector3::from(obs.pos); diff --git a/src/kete_core/src/fov/generic.rs b/src/kete_core/src/fov/generic.rs index 1fc6aaf..96d1fcb 100644 --- a/src/kete_core/src/fov/generic.rs +++ b/src/kete_core/src/fov/generic.rs @@ -6,7 +6,7 @@ use std::fmt::Debug; use nalgebra::Vector3; use serde::{Deserialize, Serialize}; -use super::{Contains, FovLike, Frame, NeosResult, OnSkyRectangle, SkyPatch, SphericalCone, FOV}; +use super::{Contains, FovLike, Frame, KeteResult, OnSkyRectangle, SkyPatch, SphericalCone, FOV}; use crate::state::State; /// Generic rectangular FOV @@ -85,7 +85,7 @@ impl FovLike for GenericRectangle { 1 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { self.observer.try_change_frame_mut(target_frame)?; self.patch = self.patch.try_frame_change(target_frame)?; Ok(()) @@ -129,7 +129,7 @@ impl FovLike for OmniDirectional { 1 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { self.observer.try_change_frame_mut(target_frame)?; Ok(()) } @@ -182,7 +182,7 @@ impl FovLike for GenericCone { 1 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { self.observer.try_change_frame_mut(target_frame)?; self.patch = self.patch.try_frame_change(target_frame)?; Ok(()) diff --git a/src/kete_core/src/fov/mod.rs b/src/kete_core/src/fov/mod.rs index 21e1d2d..4316a1b 100644 --- a/src/kete_core/src/fov/mod.rs +++ b/src/kete_core/src/fov/mod.rs @@ -112,7 +112,7 @@ impl FOV { } /// Change the frame of this FOV - pub fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + pub fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { match self { FOV::Wise(fov) => fov.try_frame_change_mut(target_frame), FOV::NeosCmos(fov) => fov.try_frame_change_mut(target_frame), diff --git a/src/kete_core/src/fov/neos.rs b/src/kete_core/src/fov/neos.rs index 1e7dbef..5585c7e 100644 --- a/src/kete_core/src/fov/neos.rs +++ b/src/kete_core/src/fov/neos.rs @@ -126,7 +126,7 @@ impl FovLike for NeosCmos { 1 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { self.observer.try_change_frame_mut(target_frame)?; self.patch = self.patch.try_frame_change(target_frame)?; Ok(()) @@ -170,7 +170,7 @@ pub struct NeosVisit { impl NeosVisit { /// Construct a new NeosVisit from a list of cmos fovs. /// These cmos fovs must be from the same metadata when appropriate. - pub fn new(chips: Vec) -> NeosResult { + pub fn new(chips: Vec) -> KeteResult { if chips.len() != 4 { Err(Error::ValueError( "Visit must contains 4 NeosCmos fovs".into(), @@ -416,12 +416,12 @@ impl FovLike for NeosVisit { 4 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { let _ = self .chips .iter_mut() .map(|ccd| ccd.try_frame_change_mut(target_frame)) - .collect::>>()?; + .collect::>>()?; self.observer.try_change_frame_mut(target_frame)?; Ok(()) } diff --git a/src/kete_core/src/fov/patches.rs b/src/kete_core/src/fov/patches.rs index 6349298..dd415cc 100644 --- a/src/kete_core/src/fov/patches.rs +++ b/src/kete_core/src/fov/patches.rs @@ -6,7 +6,7 @@ use nalgebra::{UnitVector3, Vector3}; use serde::{Deserialize, Serialize}; use std::f64::consts::FRAC_PI_2; -use super::NeosResult; +use super::KeteResult; /// Bounded areas can either contains a vector or not. /// This enum specifies if the vector is within the area, or @@ -53,7 +53,7 @@ pub trait SkyPatch: Sized { fn frame(&self) -> Frame; /// Change the frame of the bounded area to the new target frame. - fn try_frame_change(&self, target_frame: Frame) -> NeosResult; + fn try_frame_change(&self, target_frame: Frame) -> KeteResult; /// Center of the field of view fn pointing(&self) -> UnitVector3; @@ -237,7 +237,7 @@ impl SkyPatch for SphericalPolygon { self.frame } - fn try_frame_change(&self, target_frame: Frame) -> NeosResult { + fn try_frame_change(&self, target_frame: Frame) -> KeteResult { let new_edges = self .edge_normals .iter() @@ -245,7 +245,7 @@ impl SkyPatch for SphericalPolygon { self.frame .try_vec_frame_change(Vector3::from(*vec), target_frame) }) - .collect::>>()?; + .collect::>>()?; let new_edges: Vec<[f64; 3]> = new_edges.into_iter().map(|e| e.into()).collect(); let new_edges: [[f64; 3]; D] = new_edges.try_into().unwrap(); @@ -342,7 +342,7 @@ impl SkyPatch for SphericalCone { self.frame } - fn try_frame_change(&self, target_frame: Frame) -> NeosResult { + fn try_frame_change(&self, target_frame: Frame) -> KeteResult { let pointing = self .frame .try_vec_frame_change(Vector3::from(self.pointing), target_frame)?; diff --git a/src/kete_core/src/fov/wise.rs b/src/kete_core/src/fov/wise.rs index 96490c7..e007ce9 100644 --- a/src/kete_core/src/fov/wise.rs +++ b/src/kete_core/src/fov/wise.rs @@ -87,7 +87,7 @@ impl FovLike for WiseCmos { 1 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { self.observer.try_change_frame_mut(target_frame)?; self.patch = self.patch.try_frame_change(target_frame)?; Ok(()) diff --git a/src/kete_core/src/fov/ztf.rs b/src/kete_core/src/fov/ztf.rs index c8c9b87..1842477 100644 --- a/src/kete_core/src/fov/ztf.rs +++ b/src/kete_core/src/fov/ztf.rs @@ -94,7 +94,7 @@ impl FovLike for ZtfCcdQuad { 1 } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { self.observer.try_change_frame_mut(target_frame)?; self.patch = self.patch.try_frame_change(target_frame)?; Ok(()) @@ -127,7 +127,7 @@ impl ZtfField { /// Construct a new ZtfField from a list of ccd quads. /// These ccd quads must be from the same field and having matching value as /// appropriate. - pub fn new(ccd_quads: Vec) -> NeosResult { + pub fn new(ccd_quads: Vec) -> KeteResult { if ccd_quads.is_empty() { Err(Error::ValueError( "Ztf Field must contains ZtfCcdQuads".into(), @@ -174,7 +174,7 @@ impl FovLike for ZtfField { &self.observer } - fn try_frame_change_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + fn try_frame_change_mut(&mut self, target_frame: Frame) -> KeteResult<()> { let _ = self .ccd_quads .iter_mut() diff --git a/src/kete_core/src/frames/definitions.rs b/src/kete_core/src/frames/definitions.rs index 516efc1..474e92b 100644 --- a/src/kete_core/src/frames/definitions.rs +++ b/src/kete_core/src/frames/definitions.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::f64::consts::{PI, TAU}; use std::fmt::{self, Debug, Display}; -use crate::prelude::{Error, NeosResult}; +use crate::prelude::{Error, KeteResult}; use crate::time::Time; /// Coordinate frames. @@ -43,13 +43,26 @@ pub enum Frame { // Other non inertial frames will require multi-step conversions } +impl From for i32 { + fn from(value: Frame) -> Self { + match value { + Frame::Unknown(_) => 0, + Frame::Equatorial => 1, + Frame::Ecliptic => 2, + Frame::FK4 => 3, + Frame::Galactic => 4, + Frame::EclipticNonInertial(..) => 5, + } + } +} + impl Frame { /// Change a vector from the current frame into the target frame. pub fn try_vec_frame_change( &self, mut vec: Vector3, target: Frame, - ) -> NeosResult> { + ) -> KeteResult> { match self { Frame::Equatorial => { vec = equatorial_to_ecliptic(&vec); diff --git a/src/kete_core/src/io/mod.rs b/src/kete_core/src/io/mod.rs index 439cafc..8dc0565 100644 --- a/src/kete_core/src/io/mod.rs +++ b/src/kete_core/src/io/mod.rs @@ -3,7 +3,7 @@ pub mod obs_codes; pub mod serde_const_arr; -use crate::prelude::{Error, NeosResult}; +use crate::prelude::{Error, KeteResult}; use bincode::serde::{decode_from_std_read, encode_into_std_write}; use serde::{Deserialize, Serialize}; use std::fs::File; @@ -15,21 +15,21 @@ where for<'de> Self: Deserialize<'de>, { /// Save into a file. - fn save(&self, filename: String) -> NeosResult { + fn save(&self, filename: String) -> KeteResult { let mut f = BufWriter::new(File::create(filename)?); encode_into_std_write(self, &mut f, bincode::config::legacy()) .map_err(|_| Error::IOError("Failed to write to file".into())) } /// Load from a file. - fn load(filename: String) -> NeosResult { + fn load(filename: String) -> KeteResult { let mut f = BufReader::new(File::open(filename)?); decode_from_std_read(&mut f, bincode::config::legacy()) .map_err(|_| Error::IOError("Failed to read from file".into())) } /// Save a vector of this object. - fn save_vec(vec: &[Self], filename: String) -> NeosResult<()> { + fn save_vec(vec: &[Self], filename: String) -> KeteResult<()> { let mut f = BufWriter::new(File::create(filename)?); let _ = encode_into_std_write(vec, &mut f, bincode::config::legacy()) @@ -38,7 +38,7 @@ where } /// load a vector of this object. - fn load_vec(filename: String) -> NeosResult> { + fn load_vec(filename: String) -> KeteResult> { let mut f = BufReader::new(File::open(filename)?); let res: Vec = decode_from_std_read(&mut f, bincode::config::legacy()) diff --git a/src/kete_core/src/io/obs_codes.rs b/src/kete_core/src/io/obs_codes.rs index 1d63984..ceb378e 100644 --- a/src/kete_core/src/io/obs_codes.rs +++ b/src/kete_core/src/io/obs_codes.rs @@ -2,7 +2,7 @@ use lazy_static::lazy_static; use serde::Deserialize; -use crate::prelude::{Error, NeosResult}; +use crate::prelude::{Error, KeteResult}; use std::str; use std::str::FromStr; @@ -29,7 +29,7 @@ impl FromStr for ObsCode { type Err = Error; /// Load an ObsCode from a single string. - fn from_str(row: &str) -> NeosResult { + fn from_str(row: &str) -> KeteResult { let code = row[3..6].to_string(); let lon = f64::from_str(row[8..19].trim()).unwrap(); let lat = f64::from_str(row[18..29].trim()).unwrap(); diff --git a/src/kete_core/src/lib.rs b/src/kete_core/src/lib.rs index 7c0e354..a6b7850 100644 --- a/src/kete_core/src/lib.rs +++ b/src/kete_core/src/lib.rs @@ -48,7 +48,7 @@ pub mod time; /// Common useful imports pub mod prelude { pub use crate::elements::CometElements; - pub use crate::errors::{Error, NeosResult}; + pub use crate::errors::{Error, KeteResult}; pub use crate::flux::{ black_body_flux, frm_facet_temperature, lambertian_flux, neatm_facet_temperature, CometMKParams, FrmParams, HGParams, NeatmParams, diff --git a/src/kete_core/src/propagation/acceleration.rs b/src/kete_core/src/propagation/acceleration.rs index 178ed81..bbe29ec 100644 --- a/src/kete_core/src/propagation/acceleration.rs +++ b/src/kete_core/src/propagation/acceleration.rs @@ -18,7 +18,7 @@ //! thinks that the object should actually be. These times are when close encounter //! information should be recorded. //! -use crate::prelude::NeosResult; +use crate::prelude::KeteResult; use crate::spice::get_spk_singleton; use crate::{constants::*, errors::Error, frames::Frame, propagation::nongrav::NonGravModel}; use nalgebra::allocator::Allocator; @@ -69,7 +69,7 @@ pub fn central_accel( vel: &Vector3, meta: &mut CentralAccelMeta, exact_eval: bool, -) -> NeosResult> { +) -> KeteResult> { if exact_eval { meta.times.push(time); meta.pos.push(*pos); @@ -124,7 +124,7 @@ pub fn spk_accel( vel: &Vector3, meta: &mut AccelSPKMeta, exact_eval: bool, -) -> NeosResult> { +) -> KeteResult> { let mut accel = Vector3::::zeros(); if exact_eval { @@ -200,7 +200,7 @@ pub fn vec_accel( vel: &OVector, meta: &mut AccelVecMeta, exact_eval: bool, -) -> NeosResult> +) -> KeteResult> where DefaultAllocator: Allocator + Allocator, { diff --git a/src/kete_core/src/propagation/kepler.rs b/src/kete_core/src/propagation/kepler.rs index b527992..338b1c5 100644 --- a/src/kete_core/src/propagation/kepler.rs +++ b/src/kete_core/src/propagation/kepler.rs @@ -7,7 +7,7 @@ use crate::errors::Error; use crate::fitting::newton_raphson; use crate::prelude::CometElements; use crate::state::State; -use crate::{constants::*, prelude::NeosResult}; +use crate::{constants::*, prelude::KeteResult}; use argmin::solver::neldermead::NelderMead; use core::f64; use nalgebra::{ComplexField, Vector3}; @@ -24,7 +24,7 @@ pub const PARABOLIC_ECC_LIMIT: f64 = 1e-3; /// * `mean_anomaly` - Mean anomaly. /// * `peri_dist` - Perihelion Distance in AU, only used for parabolic orbits. /// -pub fn compute_eccentric_anomaly(ecc: f64, mean_anom: f64, peri_dist: f64) -> NeosResult { +pub fn compute_eccentric_anomaly(ecc: f64, mean_anom: f64, peri_dist: f64) -> KeteResult { match ecc { ecc if !ecc.is_finite() => Err(Error::ValueError( "Eccentricity must be a finite value".into(), @@ -67,7 +67,7 @@ pub fn compute_eccentric_anomaly(ecc: f64, mean_anom: f64, peri_dist: f64) -> Ne /// * `mean_anomaly` - Mean anomaly, between 0 and 2 pi. /// * `peri_dist` - Perihelion Distance in AU, only used for parabolic orbits. /// -pub fn compute_true_anomaly(ecc: f64, mean_anom: f64, peri_dist: f64) -> NeosResult { +pub fn compute_true_anomaly(ecc: f64, mean_anom: f64, peri_dist: f64) -> KeteResult { let ecc_anom = compute_eccentric_anomaly(ecc, mean_anom, peri_dist)?; let anom = match ecc { @@ -93,7 +93,7 @@ pub fn compute_true_anomaly(ecc: f64, mean_anom: f64, peri_dist: f64) -> NeosRes /// * `true_anomaly` - true anomaly, between 0 and 2 pi. /// * `peri_dist` - Perihelion Distance in AU, only used for parabolic orbits. /// -pub fn eccentric_anomaly_from_true(ecc: f64, true_anom: f64, peri_dist: f64) -> NeosResult { +pub fn eccentric_anomaly_from_true(ecc: f64, true_anom: f64, peri_dist: f64) -> KeteResult { let ecc_anom = match ecc { ecc if !ecc.is_finite() => Err(Error::ValueError( "Eccentricity must be a finite value".into(), @@ -176,7 +176,7 @@ fn g_2(s: f64, beta: f64) -> f64 { /// * `v0` - Velocity with respect to the central body (AU/day) /// * `rv0` - R vector dotted with the V vector, not normalized. /// -fn solve_kepler_universal(mut dt: f64, r0: f64, v0: f64, rv0: f64) -> NeosResult<(f64, f64)> { +fn solve_kepler_universal(mut dt: f64, r0: f64, v0: f64, rv0: f64) -> KeteResult<(f64, f64)> { // beta is GMS / semi_major let beta = 2.0 * GMS / r0 - v0.powi(2); let b_sqrt = beta.abs().sqrt(); @@ -256,7 +256,7 @@ pub fn analytic_2_body( pos: &Vector3, vel: &Vector3, depth: Option, -) -> NeosResult<(Vector3, Vector3)> { +) -> KeteResult<(Vector3, Vector3)> { let mut depth = depth.to_owned().unwrap_or(0); if depth >= 10 { Err(Error::Convergence( @@ -303,7 +303,7 @@ pub fn analytic_2_body( /// recommended to use a center of the Sun (10) for this computation. /// /// This is the fastest method for getting a relatively good estimate of the orbits. -pub fn propagate_two_body(state: &State, jd_final: f64) -> NeosResult { +pub fn propagate_two_body(state: &State, jd_final: f64) -> KeteResult { let (pos, vel) = analytic_2_body( jd_final - state.jd, &state.pos.into(), @@ -345,7 +345,7 @@ impl CostFunction for MoidCost { /// Compute the MOID between two states in au. /// MOID = Minimum Orbital Intersection Distance -pub fn moid(mut state_a: State, mut state_b: State) -> NeosResult { +pub fn moid(mut state_a: State, mut state_b: State) -> KeteResult { state_a.try_change_frame_mut(crate::frames::Frame::Ecliptic)?; state_b.try_change_frame_mut(crate::frames::Frame::Ecliptic)?; diff --git a/src/kete_core/src/propagation/mod.rs b/src/kete_core/src/propagation/mod.rs index 984f872..4ca1e06 100644 --- a/src/kete_core/src/propagation/mod.rs +++ b/src/kete_core/src/propagation/mod.rs @@ -6,7 +6,7 @@ use crate::constants::{MASSES, PLANETS, SIMPLE_PLANETS}; use crate::errors::Error; use crate::frames::Frame; -use crate::prelude::{Desig, NeosResult}; +use crate::prelude::{Desig, KeteResult}; use crate::spice::get_spk_singleton; use crate::state::State; use nalgebra::{DVector, Vector3}; @@ -49,7 +49,7 @@ pub fn propagate_two_body_radau(dt: f64, pos: &[f64; 3], vel: &[f64; 3]) -> ([f6 /// /// This is a very poor approximation over more than a few minutes/hours, however it /// is very fast. -pub fn propagate_linear(state: &State, jd_final: f64) -> NeosResult { +pub fn propagate_linear(state: &State, jd_final: f64) -> KeteResult { let dt = jd_final - state.jd; let mut pos: Vector3 = state.pos.into(); pos.iter_mut() @@ -72,7 +72,7 @@ pub fn propagate_n_body_spk( jd_final: f64, include_extended: bool, non_grav_model: Option, -) -> NeosResult { +) -> KeteResult { let center = state.center_id; let frame = state.frame; let spk = get_spk_singleton().try_read().unwrap(); @@ -123,7 +123,7 @@ pub fn propagate_n_body_spk( /// /// It is *strongly recommended* to use the `kepler.rs` code for this, as /// it will be much more computationally efficient. -pub fn propagation_central(state: &State, jd_final: f64) -> NeosResult<[[f64; 3]; 2]> { +pub fn propagation_central(state: &State, jd_final: f64) -> KeteResult<[[f64; 3]; 2]> { let pos: Vector3 = state.pos.into(); let vel: Vector3 = state.vel.into(); let (pos, vel, _meta) = RadauIntegrator::integrate( @@ -144,7 +144,7 @@ pub fn propagate_n_body_vec( jd_final: f64, planet_states: Option>, non_gravs: Vec>, -) -> NeosResult<(Vec, Vec)> { +) -> KeteResult<(Vec, Vec)> { if states.is_empty() { Err(Error::ValueError( "State vector is empty, propagation cannot continue".into(), diff --git a/src/kete_core/src/propagation/radau.rs b/src/kete_core/src/propagation/radau.rs index bdbdf8a..ac8d2a4 100644 --- a/src/kete_core/src/propagation/radau.rs +++ b/src/kete_core/src/propagation/radau.rs @@ -1,7 +1,7 @@ /// Gauss-Radau Spacing Numerical Integrator /// This solves a second-order initial value problem. use crate::errors::Error; -use crate::prelude::NeosResult; +use crate::prelude::KeteResult; use itertools::izip; use lazy_static::lazy_static; use nalgebra::allocator::Allocator; @@ -16,10 +16,10 @@ pub type RadauFunc<'a, MType, D> = &'a dyn Fn( &OVector, &mut MType, bool, -) -> NeosResult>; +) -> KeteResult>; /// Integrator will return a result of this type. -pub type RadauResult = NeosResult<(OVector, OVector, MType)>; +pub type RadauResult = KeteResult<(OVector, OVector, MType)>; const GAUSS_RADAU_SPACINGS: [f64; 8] = [ 0.0, @@ -123,7 +123,7 @@ where time_init: f64, final_time: f64, metadata: MType, - ) -> NeosResult { + ) -> KeteResult { let (dim, _) = state_init.shape_generic(); if state_init.len() != state_der_init.len() { Err(Error::ValueError( @@ -222,7 +222,7 @@ where /// This function will update the current b matrices to be correct for the /// step guess provided. /// - fn step(&mut self, step_size: f64) -> NeosResult { + fn step(&mut self, step_size: f64) -> KeteResult { self.g_scratch.fill(0.0); self.state_scratch.fill(0.0); self.state_der_scratch.fill(0.0); diff --git a/src/kete_core/src/propagation/runge_kutta.rs b/src/kete_core/src/propagation/runge_kutta.rs index 2716a96..017ed8a 100644 --- a/src/kete_core/src/propagation/runge_kutta.rs +++ b/src/kete_core/src/propagation/runge_kutta.rs @@ -1,14 +1,14 @@ -use crate::{errors::Error, prelude::NeosResult}; +use crate::{errors::Error, prelude::KeteResult}; use nalgebra::SVector; /// Function will be of the form y' = F(t, y, metadata, exact_eval). /// Metadata is passed for every evaluation. The `exact_eval` bool indicates to the /// function that the input parameters are known to be solutions for the IVP. pub type FirstOrderFunc<'a, MType, const D: usize> = - &'a dyn Fn(f64, &SVector, &mut MType, bool) -> NeosResult>; + &'a dyn Fn(f64, &SVector, &mut MType, bool) -> KeteResult>; /// Integrator will return a result of this type. -pub type FirstOrderResult = NeosResult<(SVector, MType)>; +pub type FirstOrderResult = KeteResult<(SVector, MType)>; /// Runge-Kutta-Fehlberg Integrator - RK4(5) /// @@ -30,11 +30,9 @@ impl<'a, MType, const D: usize> RK45Integrator<'a, MType, D> { /// Attempt to integrate by the provided step size. /// This may take a smaller step that specified if it failed to converge with the /// specified tolerance. - fn step(&mut self, step_size: f64) -> NeosResult { + fn step(&mut self, step_size: f64) -> KeteResult { if step_size < 1e-30 { - Err(Error::Convergence( - "Runge-Kutta step size too small".into(), - ))?; + Err(Error::Convergence("Runge-Kutta step size too small".into()))?; } let k2 = step_size @@ -153,7 +151,7 @@ impl<'a, MType, const D: usize> RK45Integrator<'a, MType, D> { mod tests { use nalgebra::Vector1; - use crate::prelude::NeosResult; + use crate::prelude::KeteResult; use crate::propagation::RK45Integrator; #[test] @@ -163,7 +161,7 @@ mod tests { state: &Vector1, _meta: &mut (), _eval: bool, - ) -> NeosResult> { + ) -> KeteResult> { Ok(-state) } @@ -188,7 +186,7 @@ mod tests { _state: &Vector1, _meta: &mut (), _eval: bool, - ) -> NeosResult> { + ) -> KeteResult> { Ok(Vector1::::repeat(2.0)) } diff --git a/src/kete_core/src/propagation/state_transition.rs b/src/kete_core/src/propagation/state_transition.rs index 4b37f9e..f9f6aa0 100644 --- a/src/kete_core/src/propagation/state_transition.rs +++ b/src/kete_core/src/propagation/state_transition.rs @@ -1,5 +1,5 @@ use crate::constants::GMS_SQRT; -use crate::prelude::{NeosResult, State}; +use crate::prelude::{KeteResult, State}; use crate::propagation::{central_accel, central_accel_grad, CentralAccelMeta, RK45Integrator}; use nalgebra::{Const, Matrix6, SVector, Vector3, U1, U6}; @@ -8,7 +8,7 @@ fn stm_ivp_eqn( state: &SVector, meta: &mut CentralAccelMeta, exact_eval: bool, -) -> NeosResult> { +) -> KeteResult> { let mut res = SVector::::zeros(); // first 6 values of the state are pos and vel respectively. diff --git a/src/kete_core/src/simult_states.rs b/src/kete_core/src/simult_states.rs index b4b89c1..bc08dbf 100644 --- a/src/kete_core/src/simult_states.rs +++ b/src/kete_core/src/simult_states.rs @@ -3,7 +3,7 @@ use crate::fov::FOV; use crate::io::FileIO; -use crate::prelude::{Error, Frame, NeosResult, State}; +use crate::prelude::{Error, Frame, KeteResult, State}; use serde::{Deserialize, Serialize}; /// Collection of [`State`] at the same time. @@ -31,7 +31,7 @@ impl SimultaneousStates { /// Create a new Exact SimultaneousStates /// Simultaneous States occur at the same JD, which is defined by either the time /// in the optional fov, or the time of the first state. - pub fn new_exact(mut states: Vec, fov: Option) -> NeosResult { + pub fn new_exact(mut states: Vec, fov: Option) -> KeteResult { if states.is_empty() { return Err(Error::ValueError( "SimultaneousStates must contain at least one state.".into(), diff --git a/src/kete_core/src/spice/binary.rs b/src/kete_core/src/spice/binary.rs index 1340d3e..b525d37 100644 --- a/src/kete_core/src/spice/binary.rs +++ b/src/kete_core/src/spice/binary.rs @@ -1,8 +1,8 @@ -use crate::errors::{Error, NeosResult}; +use crate::errors::{Error, KeteResult}; use std::io::Read; /// Read the exact number of specified bytes from the file. -pub fn read_bytes_exact(buffer: T, n_bytes: usize) -> NeosResult> { +pub fn read_bytes_exact(buffer: T, n_bytes: usize) -> KeteResult> { let mut bytes = Vec::with_capacity(n_bytes); let n_read = buffer.take(n_bytes as u64).read_to_end(&mut bytes)?; if n_read != n_bytes { @@ -13,7 +13,7 @@ pub fn read_bytes_exact(buffer: T, n_bytes: usize) -> NeosResult NeosResult { +pub fn bytes_to_f64(bytes: &[u8], little_endian: bool) -> KeteResult { let bytes: [u8; 8] = bytes .try_into() .map_err(|_| Error::IOError("File is not correctly formatted".into()))?; @@ -25,31 +25,31 @@ pub fn bytes_to_f64(bytes: &[u8], little_endian: bool) -> NeosResult { } /// Change a collection of bytes into a vector of f64s. -pub fn bytes_to_f64_vec(bytes: &[u8], little_endian: bool) -> NeosResult> { +pub fn bytes_to_f64_vec(bytes: &[u8], little_endian: bool) -> KeteResult> { let byte_len = bytes.len(); if byte_len % 8 != 0 { Err(Error::IOError("File is not correctly formatted".into()))?; } let res: Box<[f64]> = (0..byte_len / 8) .map(|idx| bytes_to_f64(&bytes[8 * idx..(8 + 8 * idx)], little_endian)) - .collect::>()?; + .collect::>()?; Ok(res) } /// Change a collection of bytes into a vector of i32s. -pub fn bytes_to_i32_vec(bytes: &[u8], little_endian: bool) -> NeosResult> { +pub fn bytes_to_i32_vec(bytes: &[u8], little_endian: bool) -> KeteResult> { let byte_len = bytes.len(); if byte_len % 4 != 0 { Err(Error::IOError("File is not correctly formatted".into()))?; } let res: Box<[i32]> = (0..byte_len / 4) .map(|idx| bytes_to_i32(&bytes[4 * idx..(4 + 4 * idx)], little_endian)) - .collect::>()?; + .collect::>()?; Ok(res) } /// Change a collection of bytes into a i32. -pub fn bytes_to_i32(bytes: &[u8], little_endian: bool) -> NeosResult { +pub fn bytes_to_i32(bytes: &[u8], little_endian: bool) -> KeteResult { let bytes: [u8; 4] = bytes .try_into() .map_err(|_| Error::IOError("File is not correctly formatted".into()))?; @@ -76,7 +76,7 @@ pub fn read_f64_vec( buffer: T, n_floats: usize, little_endian: bool, -) -> NeosResult> { +) -> KeteResult> { let bytes = read_bytes_exact(buffer, 8 * n_floats)?; bytes_to_f64_vec(&bytes, little_endian) } @@ -84,7 +84,7 @@ pub fn read_f64_vec( /// Read a string of the specified length from the file. /// 0x00 are replaced with new lines, and new lines are stripped from the end of the /// string. -pub fn read_str(buffer: T, length: usize) -> NeosResult { +pub fn read_str(buffer: T, length: usize) -> KeteResult { let bytes = read_bytes_exact(buffer, length)?; Ok(bytes_to_string(&bytes)) } diff --git a/src/kete_core/src/spice/daf.rs b/src/kete_core/src/spice/daf.rs index b3a4249..d1a9acd 100644 --- a/src/kete_core/src/spice/daf.rs +++ b/src/kete_core/src/spice/daf.rs @@ -16,7 +16,7 @@ use super::binary::{ use super::pck_segments::PckSegment; use super::spk_segments::SpkSegment; -use crate::errors::{Error, NeosResult}; +use crate::errors::{Error, KeteResult}; use std::fmt::Debug; use std::io::{Cursor, Read, Seek}; use std::ops::Index; @@ -137,13 +137,13 @@ pub struct DafFile { impl DafFile { /// Try to load a single record from the DAF. - pub fn try_load_record(file: &mut T, idx: u64) -> NeosResult> { + pub fn try_load_record(file: &mut T, idx: u64) -> KeteResult> { let _ = file.seek(std::io::SeekFrom::Start(1024 * (idx - 1)))?; read_bytes_exact(file, 1024) } /// Load the contents of a DAF file. - pub fn from_buffer(mut buffer: T) -> NeosResult { + pub fn from_buffer(mut buffer: T) -> KeteResult { let bytes = Self::try_load_record(&mut buffer, 1)?; let daf_type: DAFType = bytes_to_string(&bytes[0..8]).as_str().into(); @@ -201,7 +201,7 @@ impl DafFile { } /// Load DAF file from the specified filename. - pub fn from_file(filename: &str) -> NeosResult { + pub fn from_file(filename: &str) -> KeteResult { let mut file = std::fs::File::open(filename)?; let mut buffer = Vec::new(); let _ = file.read_to_end(&mut buffer)?; @@ -213,7 +213,7 @@ impl DafFile { /// These are tuples containing a series of f64s and i32s along with arrays of data. /// The meaning of these values depends on the particular implementation of the DAF. /// - pub fn try_load_segments(&mut self, file: &mut T) -> NeosResult<()> { + pub fn try_load_segments(&mut self, file: &mut T) -> KeteResult<()> { let summary_size = self.n_doubles + (self.n_ints + 1) / 2; let mut next_idx = self.init_summary_record_index; @@ -288,7 +288,7 @@ impl DafArray { summary_floats: Box<[f64]>, summary_ints: Box<[i32]>, little_endian: bool, - ) -> NeosResult { + ) -> KeteResult { if summary_floats.len() != 2 || summary_ints.len() != 6 { Err(Error::IOError("SPK File incorrectly Formatted.".into()))?; } @@ -310,7 +310,7 @@ impl DafArray { summary_floats: Box<[f64]>, summary_ints: Box<[i32]>, little_endian: bool, - ) -> NeosResult { + ) -> KeteResult { if summary_floats.len() != 2 || summary_ints.len() != 5 { Err(Error::IOError("PCK File incorrectly Formatted.".into()))?; } @@ -334,7 +334,7 @@ impl DafArray { array_start: u64, array_end: u64, little_endian: bool, - ) -> NeosResult { + ) -> KeteResult { let _ = buffer.seek(std::io::SeekFrom::Start(8 * (array_start - 1)))?; let n_floats = (array_end - array_start + 1) as usize; diff --git a/src/kete_core/src/spice/interpolation.rs b/src/kete_core/src/spice/interpolation.rs index a7bba39..416e4e4 100644 --- a/src/kete_core/src/spice/interpolation.rs +++ b/src/kete_core/src/spice/interpolation.rs @@ -2,7 +2,7 @@ //! //! It is unlikely to be useful outside of reading these files. //! -use crate::{errors::Error, prelude::NeosResult}; +use crate::{errors::Error, prelude::KeteResult}; use nalgebra::DVector; /// Given a list of chebyshev polynomial coefficients, compute the value of the function @@ -27,7 +27,7 @@ pub fn chebyshev3_evaluate_both( coefx: &[f64], coefy: &[f64], coefz: &[f64], -) -> NeosResult<([f64; 3], [f64; 3])> { +) -> KeteResult<([f64; 3], [f64; 3])> { let n_coef = coefx.len(); if n_coef < 2 { diff --git a/src/kete_core/src/spice/naif_ids.rs b/src/kete_core/src/spice/naif_ids.rs index cc5e7b7..0c62b1b 100644 --- a/src/kete_core/src/spice/naif_ids.rs +++ b/src/kete_core/src/spice/naif_ids.rs @@ -4,7 +4,7 @@ use lazy_static::lazy_static; use serde::Deserialize; -use crate::prelude::{Error, NeosResult}; +use crate::prelude::{Error, KeteResult}; use std::str; use std::str::FromStr; @@ -22,7 +22,7 @@ impl FromStr for NaifId { type Err = Error; /// Load an NaifId from a single string. - fn from_str(row: &str) -> NeosResult { + fn from_str(row: &str) -> KeteResult { let id = i32::from_str(row[0..10].trim()).unwrap(); let name = row[11..].trim().to_string(); Ok(NaifId { id, name }) diff --git a/src/kete_core/src/spice/pck.rs b/src/kete_core/src/spice/pck.rs index c25d5fd..aa02139 100644 --- a/src/kete_core/src/spice/pck.rs +++ b/src/kete_core/src/spice/pck.rs @@ -7,7 +7,7 @@ //! use super::daf::{DAFType, DafFile}; use super::pck_segments::PckSegment; -use crate::errors::{Error, NeosResult}; +use crate::errors::{Error, KeteResult}; use crate::frames::Frame; use crossbeam::sync::ShardedLock; @@ -33,7 +33,7 @@ pub type PckSingleton = ShardedLock; impl PckCollection { /// Given an PCK filename, load all the segments present inside of it. /// These segments are added to the PCK singleton in memory. - pub fn load_file(&mut self, filename: &str) -> NeosResult<()> { + pub fn load_file(&mut self, filename: &str) -> KeteResult<()> { let file = DafFile::from_file(filename)?; if !matches!(file.daf_type, DAFType::Pck) { Err(Error::IOError(format!( @@ -48,7 +48,7 @@ impl PckCollection { /// Get the raw orientation from the loaded PCK files. /// This orientation will have the frame of what was originally present in the file. - pub fn try_get_orientation(&self, id: isize, jd: f64) -> NeosResult { + pub fn try_get_orientation(&self, id: isize, jd: f64) -> KeteResult { for segment in self.segments.iter() { if id == segment.center_id && segment.contains(jd) { return segment.try_get_orientation(jd); diff --git a/src/kete_core/src/spice/pck_segments.rs b/src/kete_core/src/spice/pck_segments.rs index 4852dc7..e7a9d75 100644 --- a/src/kete_core/src/spice/pck_segments.rs +++ b/src/kete_core/src/spice/pck_segments.rs @@ -18,7 +18,7 @@ use super::interpolation::*; use super::{jd_to_spice_jd, spice_jds_to_jd}; use crate::errors::Error; use crate::frames::Frame; -use crate::prelude::NeosResult; +use crate::prelude::KeteResult; use std::fmt::Debug; #[derive(Debug)] @@ -28,7 +28,7 @@ pub enum PckSegmentType { impl PckSegmentType { /// Load PCK Segment data from an array. - pub fn from_array(segment_type: i32, array: DafArray) -> NeosResult { + pub fn from_array(segment_type: i32, array: DafArray) -> KeteResult { match segment_type { 2 => Ok(PckSegmentType::Type2(array.into())), v => Err(Error::IOError(format!( @@ -71,7 +71,7 @@ pub struct PckSegment { impl TryFrom for PckSegment { type Error = Error; - fn try_from(array: DafArray) -> NeosResult { + fn try_from(array: DafArray) -> KeteResult { let summary_floats = &array.summary_floats; let summary_ints = &array.summary_ints; let jd_start = spice_jds_to_jd(summary_floats[0]); @@ -107,7 +107,7 @@ impl PckSegment { /// Return the [`Frame`] at the specified JD. If the requested time is not within /// the available range, this will fail. - pub fn try_get_orientation(&self, jd: f64) -> NeosResult { + pub fn try_get_orientation(&self, jd: f64) -> KeteResult { if jd < self.jd_start || jd > self.jd_end { Err(Error::DAFLimits( "JD is not present in this record.".to_string(), @@ -148,7 +148,7 @@ impl PckSegmentType2 { } /// Return the stored orientation, along with the rate of change of the orientation. - fn try_get_orientation(&self, segment: &PckSegment, jd: f64) -> NeosResult { + fn try_get_orientation(&self, segment: &PckSegment, jd: f64) -> KeteResult { // Records in the segment contain information about the central position of the // north pole, as well as the position of the prime meridian. These values for // type 2 segments are stored as chebyshev polynomials of the first kind, in diff --git a/src/kete_core/src/spice/spk.rs b/src/kete_core/src/spice/spk.rs index a331d9d..37ff4b5 100644 --- a/src/kete_core/src/spice/spk.rs +++ b/src/kete_core/src/spice/spk.rs @@ -22,7 +22,7 @@ use super::daf::DafFile; use super::{spk_segments::*, DAFType}; use crate::errors::Error; use crate::frames::Frame; -use crate::prelude::NeosResult; +use crate::prelude::KeteResult; use crate::state::State; use pathfinding::prelude::dijkstra; use std::collections::{HashMap, HashSet}; @@ -64,7 +64,7 @@ impl SpkCollection { /// This state will have the center and frame of whatever was originally loaded /// into the file. #[inline(always)] - pub fn try_get_raw_state(&self, id: i64, jd: f64) -> NeosResult { + pub fn try_get_raw_state(&self, id: i64, jd: f64) -> KeteResult { for segment in self.segments.iter() { if id == segment.obj_id && segment.contains(jd) { return segment.try_get_state(jd); @@ -79,7 +79,7 @@ impl SpkCollection { /// Load a state from the file, then attempt to change the center to the center id /// specified. #[inline(always)] - pub fn try_get_state(&self, id: i64, jd: f64, center: i64, frame: Frame) -> NeosResult { + pub fn try_get_state(&self, id: i64, jd: f64, center: i64, frame: Frame) -> KeteResult { let mut state = self.try_get_raw_state(id, jd)?; self.try_change_center(&mut state, center)?; state.try_change_frame_mut(frame)?; @@ -88,7 +88,7 @@ impl SpkCollection { /// Use the data loaded in the SPKs to change the center ID of the provided state. #[inline(always)] - pub fn try_change_center(&self, state: &mut State, new_center: i64) -> NeosResult<()> { + pub fn try_change_center(&self, state: &mut State, new_center: i64) -> KeteResult<()> { match (state.center_id, new_center) { (a, b) if a == b => (), (i, 0) if i <= 10 => { @@ -177,7 +177,7 @@ impl SpkCollection { /// Given a NAIF ID, and a target NAIF ID, find the intermediate SPICE Segments /// which need to be loaded to find a path from one object to the other. /// Use Dijkstra plus the known segments to calculate a path. - fn find_path(&self, start: i64, goal: i64) -> NeosResult> { + fn find_path(&self, start: i64, goal: i64) -> KeteResult> { // first we check to see if the cache contains the lookup we need. if let Some(path) = self.map_cache.get(&(start, goal)) { return Ok(path.clone()); @@ -270,7 +270,7 @@ impl SpkCollection { /// Given an SPK filename, load all the segments present inside of it. /// These segments are added to the SPK singleton in memory. - pub fn load_file(&mut self, filename: &str) -> NeosResult<()> { + pub fn load_file(&mut self, filename: &str) -> KeteResult<()> { let file = DafFile::from_file(filename)?; if !matches!(file.daf_type, DAFType::Spk) { diff --git a/src/kete_core/src/spice/spk_segments.rs b/src/kete_core/src/spice/spk_segments.rs index ec9714e..2a45b35 100644 --- a/src/kete_core/src/spice/spk_segments.rs +++ b/src/kete_core/src/spice/spk_segments.rs @@ -17,7 +17,7 @@ use super::{jd_to_spice_jd, spice_jds_to_jd, DafArray}; use crate::constants::AU_KM; use crate::errors::Error; use crate::frames::Frame; -use crate::prelude::{Desig, NeosResult}; +use crate::prelude::{Desig, KeteResult}; use crate::state::State; use crate::time::scales::TDB; use crate::time::Time; @@ -36,7 +36,7 @@ pub enum SpkSegmentType { impl SpkSegmentType { /// Create a Segment from a DafArray, the segment type must be specified. - pub fn from_array(segment_type: i32, array: DafArray) -> NeosResult { + pub fn from_array(segment_type: i32, array: DafArray) -> KeteResult { match segment_type { 1 => Ok(SpkSegmentType::Type1(array.into())), 2 => Ok(SpkSegmentType::Type2(array.into())), @@ -106,7 +106,7 @@ impl From for DafArray { impl TryFrom for SpkSegment { type Error = Error; - fn try_from(value: DafArray) -> NeosResult { + fn try_from(value: DafArray) -> KeteResult { let summary_floats = &value.summary_floats; let summary_ints = &value.summary_ints; let jd_start = spice_jds_to_jd(summary_floats[0]); @@ -144,7 +144,7 @@ impl SpkSegment { /// Return the [`State`] object at the specified JD. If the requested time is /// not within the available range, this will fail. #[inline(always)] - pub fn try_get_state(&self, jd: f64) -> NeosResult { + pub fn try_get_state(&self, jd: f64) -> KeteResult { // this is faster than calling contains, probably because the || instead of && if jd < self.jd_start || jd > self.jd_end { return Err(Error::DAFLimits( @@ -198,7 +198,7 @@ impl SpkSegmentType1 { } #[inline(always)] - fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> NeosResult<([f64; 3], [f64; 3])> { + fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> KeteResult<([f64; 3], [f64; 3])> { // Records are laid out as so: // // Size Description @@ -346,7 +346,7 @@ impl SpkSegmentType2 { } #[inline(always)] - fn try_get_pos_vel(&self, segment: &SpkSegment, jd: f64) -> NeosResult<([f64; 3], [f64; 3])> { + fn try_get_pos_vel(&self, segment: &SpkSegment, jd: f64) -> KeteResult<([f64; 3], [f64; 3])> { let jd = jd_to_spice_jd(jd); let jd_start = jd_to_spice_jd(segment.jd_start); let record_index = ((jd - jd_start) / self.jd_step).floor() as usize; @@ -454,7 +454,7 @@ impl SpkSegmentType10 { } #[inline(always)] - fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> NeosResult<([f64; 3], [f64; 3])> { + fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> KeteResult<([f64; 3], [f64; 3])> { // TODO: this does not yet implement the interpolation between two neighboring states // which is present in the cSPICE implementation. // This currently matches the cspice implementation to within about 20km, where the error @@ -572,7 +572,7 @@ impl SpkSegmentType13 { } #[inline(always)] - fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> NeosResult<([f64; 3], [f64; 3])> { + fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> KeteResult<([f64; 3], [f64; 3])> { let jd = jd_to_spice_jd(jd); let times = self.get_times(); let start_idx: isize = match times.binary_search_by(|probe| probe.total_cmp(&jd)) { @@ -655,7 +655,7 @@ impl SpkSegmentType21 { } #[inline(always)] - fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> NeosResult<([f64; 3], [f64; 3])> { + fn try_get_pos_vel(&self, _: &SpkSegment, jd: f64) -> KeteResult<([f64; 3], [f64; 3])> { // Records are laid out as so: // // Size Description @@ -850,7 +850,7 @@ impl GenericSegment { impl TryFrom for GenericSegment { type Error = Error; - fn try_from(array: DafArray) -> NeosResult { + fn try_from(array: DafArray) -> KeteResult { // The very last value of this array is an int (cast to f64) which indicates the number // of meta-data values. diff --git a/src/kete_core/src/state.rs b/src/kete_core/src/state.rs index b9c2af4..da24216 100644 --- a/src/kete_core/src/state.rs +++ b/src/kete_core/src/state.rs @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Display}; -use crate::errors::{Error, NeosResult}; +use crate::errors::{Error, KeteResult}; use crate::frames::{ ecliptic_to_equatorial, ecliptic_to_fk4, ecliptic_to_galactic, equatorial_to_ecliptic, fk4_to_ecliptic, galactic_to_ecliptic, inertial_to_noninertial, noninertial_to_inertial, Frame, @@ -142,7 +142,7 @@ impl State { /// /// * `target_frame` - Target frame from the [`Frame`] enum. #[inline(always)] - pub fn try_change_frame_mut(&mut self, target_frame: Frame) -> NeosResult<()> { + pub fn try_change_frame_mut(&mut self, target_frame: Frame) -> KeteResult<()> { if self.frame == target_frame { return Ok(()); } @@ -211,7 +211,7 @@ impl State { /// Trade the center ID and ID values, and flip the direction of the position and /// velocity vectors. #[inline(always)] - pub fn try_flip_center_id(&mut self) -> NeosResult<()> { + pub fn try_flip_center_id(&mut self) -> KeteResult<()> { if let Desig::Naif(mut id) = self.desig { (id, self.center_id) = (self.center_id, id); for i in 0..3 { @@ -238,7 +238,7 @@ impl State { /// /// * `state` - [`State`] object which defines the new center point. #[inline(always)] - pub fn try_change_center(&mut self, mut state: Self) -> NeosResult<()> { + pub fn try_change_center(&mut self, mut state: Self) -> KeteResult<()> { if self.jd != state.jd { return Err(Error::ValueError("States don't have matching jds.".into())); } diff --git a/src/kete_core/src/stats/quantile.rs b/src/kete_core/src/stats/quantile.rs index 3ca2b72..6642439 100644 --- a/src/kete_core/src/stats/quantile.rs +++ b/src/kete_core/src/stats/quantile.rs @@ -1,4 +1,4 @@ -use crate::{errors::Error, prelude::NeosResult}; +use crate::{errors::Error, prelude::KeteResult}; /// Calculate desired quantile of the provided data. /// @@ -9,7 +9,7 @@ use crate::{errors::Error, prelude::NeosResult}; /// Quantiles are linearly interpolated between the two closest ranked values. /// /// If only one valid data point is provided, all quantiles evaluate to that value. -pub fn quantile(data: &[f64], quant: f64) -> NeosResult { +pub fn quantile(data: &[f64], quant: f64) -> KeteResult { if quant <= 0.0 || quant >= 1.0 { Err(Error::ValueError( "Quantile must be between 0.0 and 1.0".into(), @@ -46,7 +46,7 @@ pub fn quantile(data: &[f64], quant: f64) -> NeosResult { /// Compute the median value of the data. /// /// This ignores non-finite values such as inf and nan. -pub fn median(data: &[f64]) -> NeosResult { +pub fn median(data: &[f64]) -> KeteResult { quantile(data, 0.5) } @@ -55,7 +55,7 @@ pub fn median(data: &[f64]) -> NeosResult { /// /// #[allow(dead_code)] -pub fn mad(data: &[f64]) -> NeosResult { +pub fn mad(data: &[f64]) -> KeteResult { let median = quantile(data, 0.5)?; let abs_deviation_from_med: Box<[f64]> = data.iter().map(|d| d - median).collect(); quantile(&abs_deviation_from_med, 0.5) diff --git a/src/kete_core/src/time/leap_second.rs b/src/kete_core/src/time/leap_second.rs index a52e150..9426230 100644 --- a/src/kete_core/src/time/leap_second.rs +++ b/src/kete_core/src/time/leap_second.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use lazy_static::lazy_static; use serde::Deserialize; -use crate::prelude::{Error, NeosResult}; +use crate::prelude::{Error, KeteResult}; /// Leap Second Information /// This is parsed from the contents of the `leap_second.dat` file. @@ -22,7 +22,7 @@ impl FromStr for LeapSecond { type Err = Error; /// Load an LeapSecond from a single string. - fn from_str(row: &str) -> NeosResult { + fn from_str(row: &str) -> KeteResult { let (mjd, _, _, _, tai_m_utc) = row.split_whitespace().next_tuple().ok_or( Error::IOError("Leap Second file incorrectly formatted.".into()), )?; diff --git a/src/kete_core/src/time/mod.rs b/src/kete_core/src/time/mod.rs index d7f1834..4cd106d 100644 --- a/src/kete_core/src/time/mod.rs +++ b/src/kete_core/src/time/mod.rs @@ -11,7 +11,7 @@ pub mod scales; use chrono::{DateTime, Datelike, NaiveDate, Timelike, Utc}; use scales::{TimeScale, JD_TO_MJD, TAI, TDB, UTC}; -use crate::prelude::{Error, NeosResult}; +use crate::prelude::{Error, KeteResult}; /// Representation of Time. /// @@ -72,18 +72,18 @@ pub fn frac_day_to_hmsms(mut frac: f64) -> Option<(u32, u32, u32, u32)> { impl Time { /// Read time from the standard ISO format for time. - pub fn from_iso(s: &str) -> NeosResult { + pub fn from_iso(s: &str) -> KeteResult { let time = DateTime::parse_from_rfc3339(s)?.to_utc(); Self::from_datetime(&time) } /// Construct time from the current time. - pub fn now() -> NeosResult { + pub fn now() -> KeteResult { Self::from_datetime(&Utc::now()) } /// Construct a Time object from a UTC DateTime. - pub fn from_datetime(time: &DateTime) -> NeosResult { + pub fn from_datetime(time: &DateTime) -> KeteResult { let frac_day = hour_min_sec_to_day( time.hour(), time.minute(), @@ -143,7 +143,7 @@ impl Time { } /// Create a DateTime object - pub fn to_datetime(&self) -> NeosResult> { + pub fn to_datetime(&self) -> KeteResult> { let (y, month, d, f) = self.year_month_day(); let (h, m, s, ms) = frac_day_to_hmsms(f).unwrap(); Ok(NaiveDate::from_ymd_opt(y as i32, month, d) @@ -154,7 +154,7 @@ impl Time { } /// Construct a ISO compliant UTC string. - pub fn to_iso(&self) -> NeosResult { + pub fn to_iso(&self) -> KeteResult { let datetime = self.to_datetime()?; Ok(datetime.to_rfc3339()) }