Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename NeosResult to KeteResult #140

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/kete/rust/fitting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/kete/rust/fovs/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion src/kete/rust/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PyFrames>) -> PyResult<Self> {
Expand Down
2 changes: 1 addition & 1 deletion src/kete_core/benches/propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
10 changes: 5 additions & 5 deletions src/kete_core/src/elements.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<State> {
pub fn try_to_state(&self) -> KeteResult<State> {
let [pos, vel] = self.to_pos_vel()?;
Ok(State::new(
self.desig.to_owned(),
Expand All @@ -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;
Expand Down Expand Up @@ -264,7 +264,7 @@ impl CometElements {
}

/// Compute the eccentric anomaly for the cometary elements.
pub fn eccentric_anomaly(&self) -> NeosResult<f64> {
pub fn eccentric_anomaly(&self) -> KeteResult<f64> {
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,
Expand Down Expand Up @@ -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<f64> {
pub fn true_anomaly(&self) -> KeteResult<f64> {
compute_true_anomaly(self.eccentricity, self.mean_anomaly(), self.peri_dist)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kete_core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use chrono::ParseError;
use std::{error, fmt, io};

/// kete specific result.
pub type NeosResult<T> = Result<T, Error>;
pub type KeteResult<T> = Result<T, Error>;

/// Possible Errors which may be raised by this crate.
#[derive(Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions src/kete_core/src/fitting/halley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -27,7 +27,7 @@ pub fn halley<Func, Der, SecDer>(
sec_der: SecDer,
start: f64,
atol: f64,
) -> NeosResult<f64>
) -> KeteResult<f64>
where
Func: Fn(f64) -> f64,
Der: Fn(f64) -> f64,
Expand Down
4 changes: 2 additions & 2 deletions src/kete_core/src/fitting/newton.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{errors::Error, prelude::NeosResult};
use crate::{errors::Error, prelude::KeteResult};

/// Solve root using the Newton-Raphson method.
///
Expand All @@ -15,7 +15,7 @@ use crate::{errors::Error, prelude::NeosResult};
/// ```
///
#[inline(always)]
pub fn newton_raphson<Func, Der>(func: Func, der: Der, start: f64, atol: f64) -> NeosResult<f64>
pub fn newton_raphson<Func, Der>(func: Func, der: Der, start: f64, atol: f64) -> KeteResult<f64>
where
Func: Fn(f64) -> f64,
Der: Fn(f64) -> f64,
Expand Down
6 changes: 3 additions & 3 deletions src/kete_core/src/flux/reflected.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -117,7 +117,7 @@ impl HGParams {
c_hg: Option<f64>,
vis_albedo: Option<f64>,
diam: Option<f64>,
) -> NeosResult<Self> {
) -> KeteResult<Self> {
let (h_mag, vis_albedo, diam, c_hg) = Self::fill(h_mag, vis_albedo, diam, c_hg)?;
Ok(Self {
desig,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl HGParams {
vis_albedo: Option<f64>,
diam: Option<f64>,
c_hg: Option<f64>,
) -> NeosResult<(f64, Option<f64>, Option<f64>, f64)> {
) -> KeteResult<(f64, Option<f64>, Option<f64>, 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(),
Expand Down
6 changes: 3 additions & 3 deletions src/kete_core/src/fov/fov_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions src/kete_core/src/fov/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/kete_core/src/fov/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions src/kete_core/src/fov/neos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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<NeosCmos>) -> NeosResult<Self> {
pub fn new(chips: Vec<NeosCmos>) -> KeteResult<Self> {
if chips.len() != 4 {
Err(Error::ValueError(
"Visit must contains 4 NeosCmos fovs".into(),
Expand Down Expand Up @@ -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::<NeosResult<Vec<_>>>()?;
.collect::<KeteResult<Vec<_>>>()?;
self.observer.try_change_frame_mut(target_frame)?;
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/kete_core/src/fov/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Self>;
fn try_frame_change(&self, target_frame: Frame) -> KeteResult<Self>;

/// Center of the field of view
fn pointing(&self) -> UnitVector3<f64>;
Expand Down Expand Up @@ -237,15 +237,15 @@ impl<const D: usize> SkyPatch for SphericalPolygon<D> {
self.frame
}

fn try_frame_change(&self, target_frame: Frame) -> NeosResult<Self> {
fn try_frame_change(&self, target_frame: Frame) -> KeteResult<Self> {
let new_edges = self
.edge_normals
.iter()
.map(|vec| {
self.frame
.try_vec_frame_change(Vector3::from(*vec), target_frame)
})
.collect::<NeosResult<Vec<_>>>()?;
.collect::<KeteResult<Vec<_>>>()?;
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();

Expand Down Expand Up @@ -342,7 +342,7 @@ impl SkyPatch for SphericalCone {
self.frame
}

fn try_frame_change(&self, target_frame: Frame) -> NeosResult<Self> {
fn try_frame_change(&self, target_frame: Frame) -> KeteResult<Self> {
let pointing = self
.frame
.try_vec_frame_change(Vector3::from(self.pointing), target_frame)?;
Expand Down
2 changes: 1 addition & 1 deletion src/kete_core/src/fov/wise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
6 changes: 3 additions & 3 deletions src/kete_core/src/fov/ztf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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<ZtfCcdQuad>) -> NeosResult<Self> {
pub fn new(ccd_quads: Vec<ZtfCcdQuad>) -> KeteResult<Self> {
if ccd_quads.is_empty() {
Err(Error::ValueError(
"Ztf Field must contains ZtfCcdQuads".into(),
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 15 additions & 2 deletions src/kete_core/src/frames/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -43,13 +43,26 @@ pub enum Frame {
// Other non inertial frames will require multi-step conversions
}

impl From<Frame> 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<f64>,
target: Frame,
) -> NeosResult<Vector3<f64>> {
) -> KeteResult<Vector3<f64>> {
match self {
Frame::Equatorial => {
vec = equatorial_to_ecliptic(&vec);
Expand Down
Loading