Skip to content

Commit

Permalink
WIP spice feature and ground based obs
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoireHENRY committed Dec 5, 2023
1 parent 94c6e10 commit b78c7d9
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 227 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dunce = "1.0"
uom = "0.35"
regex = "1.10"
kalast_macros = { path = "macros", version = "0.4.0-beta" }
strum = { version = "0.25", features = ["derive"] }

[dev-dependencies]
rstest = "0.18"
Expand Down
6 changes: 4 additions & 2 deletions examples/ground-based-lightcurve-didymos-spice/cfg/cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ simulation:
export:
step: 60
duration: 8136
pause_after_first_iteration: true

scene:
spice: true
spice: /Users/gregoireh/data/spice/dart/mk/d420.tm
camera:
!earth 2.0
from: Earth
distance: 2

bodies:
- id: Didymos
Expand Down
2 changes: 1 addition & 1 deletion examples/viewer/cfg/cfg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
win:
window:
ambient: [0.1, 0.1, 0.1]

bodies:
Expand Down
1 change: 1 addition & 0 deletions preferences.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no_check: true
4 changes: 2 additions & 2 deletions src/body/asteroid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl AirlessBody {
}
}

pub fn matrix_spin(spin: Float) -> Mat4 {
pub fn matrix_spin(spin: Float, axis: Vec3) -> Mat4 {
if spin == 0.0 {
Mat4::identity()
} else {
Mat4::new_rotation(spin * Vec3::z())
Mat4::new_rotation(spin * axis)
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/cfg/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ pub enum CfgState {

#[serde(rename = "file")]
File(PathBuf),

#[serde(rename = "spice")]
Spice(CfgStateSpice),
}

impl CfgState {
Expand Down Expand Up @@ -757,6 +760,18 @@ impl Default for CfgOrbitSpeedControl {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfgStateSpice {
#[serde(default)]
pub origin: Option<String>,

#[serde(default)]
pub frame: Option<String>,

#[serde(default)]
pub frame_to: Option<String>,
}

/**
# Configuration of the Initialisation of the Temperature of the Body.
Expand Down
14 changes: 13 additions & 1 deletion src/cfg/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{CfgBody, CfgBodyError, CfgPreferences, CfgScene, CfgSimulation, CfgWindow};
use crate::{CfgBody, CfgBodyError, CfgPreferences, CfgScene, CfgSimulation, CfgSpice, CfgWindow};

use itertools::Itertools;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand Down Expand Up @@ -168,6 +168,10 @@ pub struct Cfg {
#[serde(default)]
pub simulation: CfgSimulation,

#[cfg(feature = "spice")]
#[serde(default)]
pub spice: CfgSpice,

#[serde(default)]
pub window: CfgWindow,

Expand Down Expand Up @@ -292,6 +296,10 @@ impl Cfg {
pub fn extra(&self) -> &HashMap<String, Value> {
&self.extra
}

pub fn using_spice(&self) -> bool {
self.scene.spice.is_some()
}
}

impl Configuration for Cfg {}
Expand All @@ -303,6 +311,10 @@ impl Default for Cfg {
bodies: vec![],
scene: CfgScene::default(),
simulation: CfgSimulation::default(),

#[cfg(feature = "spice")]
spice: CfgSpice::default(),

window: CfgWindow::default(),
preferences: CfgPreferences::default(),
extra: HashMap::new(),
Expand Down
2 changes: 2 additions & 0 deletions src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ mod config;
mod preferences;
mod scene;
mod simulation;
mod spice;
mod window;

pub use body::*;
pub use config::*;
pub use preferences::*;
pub use scene::*;
pub use simulation::*;
pub use spice::*;
pub use window::*;
3 changes: 2 additions & 1 deletion src/cfg/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct CfgPreferences {
pub runs: PathBuf,

#[serde(default)]
#[serde(alias = "no_check")]
pub do_not_check_latest_version: bool,

#[serde(default)]
Expand All @@ -28,8 +29,8 @@ impl Default for CfgPreferences {
fn default() -> Self {
Self {
runs: default_runs(),
auto_update: false,
do_not_check_latest_version: false,
auto_update: false,
debug: false,
debug_cfg: false,
}
Expand Down
85 changes: 60 additions & 25 deletions src/cfg/scene.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::path::PathBuf;

use crate::{util::*, CfgBodyError, CfgStateCartesian, Configuration, Equatorial};
use crate::{util::*, CfgBodyError, Configuration, Equatorial};

use serde::{Deserialize, Serialize};
use snafu::{prelude::*, Location};
use std::path::PathBuf;
use strum::{Display, EnumString};

pub type SceneResult<T, E = CfgSceneError> = std::result::Result<T, E>;

Expand Down Expand Up @@ -41,57 +41,92 @@ impl Default for CfgScene {
impl Configuration for CfgScene {}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CfgCamera {
#[serde(rename = "position")]
Position(Vec3),

/// Camera in from the direction of the Sun (Sun behind camera).
/// The float is the distance from the center of frame to the camera.
#[serde(rename = "sun")]
Sun(Float),

#[serde(rename = "earth")]
Earth(Float),
///
/// TODO: COMPLETE DOC
#[serde(rename = "from")]
From(CfgCameraFrom),
}

impl CfgCamera {
pub fn as_earth(&self) -> SceneResult<Float> {
match self {
Self::Earth(distance) => Ok(*distance),
_ => panic!("Not in Earth mode."),
}
pub fn default_position() -> Vec3 {
Vec3::x() * 5.0
}
}

impl Default for CfgCamera {
fn default() -> Self {
Self::Sun(5.0)
Self::Position(Self::default_position())
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfgCameraFrom {
#[serde(default)]
pub from: CfgCameraFromOptions,

#[serde(default)]
#[serde(alias = "distance")]
pub distance_origin: Float,
}

#[derive(Clone, Debug, Serialize, Deserialize, EnumString, Display)]
pub enum CfgCameraFromOptions {
#[serde(rename = "sun")]
#[serde(alias = "Sun")]
Sun,

#[serde(rename = "earth")]
#[serde(alias = "Earth")]
Earth,
}

impl Default for CfgCameraFromOptions {
fn default() -> Self {
Self::Sun
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(untagged)]
pub enum CfgSun {
#[serde(rename = "cartesian")]
#[serde(alias = "cart")]
Cartesian(CfgStateCartesian),
#[serde(rename = "position")]
Position(Vec3),

#[serde(rename = "equatorial")]
#[serde(alias = "astro")]
Equatorial(Equatorial),

#[serde(rename = "from")]
From(CfgSunFrom),
}

impl CfgSun {
pub fn as_equatorial(&self) -> SceneResult<&Equatorial> {
match self {
Self::Equatorial(coords) => Ok(coords),
_ => panic!("Not equatorial coordinates."),
}
pub fn default_position() -> Vec3 {
Vec3::x() * Self::default_distance()
}

pub fn default_distance() -> Float {
1.0
}
}

impl Default for CfgSun {
fn default() -> Self {
Self::Cartesian(CfgStateCartesian::position_only(Vec3::x()))
Self::Position(Self::default_position())
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum CfgSunFrom {
#[serde(rename = "from_spice")]
Spice,

#[serde(rename = "from_orbit_body")]
OrbitBody,
}
5 changes: 3 additions & 2 deletions src/cfg/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub type SimulationResult<T, E = CfgSimulationError> = std::result::Result<T, E>
/// Errors related to Kalast config.
#[derive(Debug, Snafu)]
pub enum CfgSimulationError {
SpiceNotLoaded {},
#[snafu(display("Feature `spice` is not enabled."))]
FeatureSpiceNotEnabled {},
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -66,7 +67,7 @@ impl TimeOption {
#[cfg(feature = "spice")]
return Ok(spice::str2et(_s));
#[cfg(not(feature = "spice"))]
return Err(CfgSimulationError::SpiceNotLoaded {});
return Err(CfgSimulationError::FeatureSpiceNotEnabled {});
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/cfg/spice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::Configuration;

use serde::{Deserialize, Serialize};
use snafu::prelude::*;
use std::path::PathBuf;

pub type CfgSpiceResult<T, E = CfgSpiceError> = std::result::Result<T, E>;

/// Errors related to Kalast config.
#[derive(Debug, Snafu)]
pub enum CfgSpiceError {}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CfgSpice {
#[serde(default)]
pub kernel: Option<PathBuf>,

#[serde(default)]
pub frame: Option<String>,
}

impl Default for CfgSpice {
fn default() -> Self {
Self {
kernel: None,
frame: None,
}
}
}

impl Configuration for CfgSpice {}
2 changes: 1 addition & 1 deletion src/simu/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Export {
CsvWriter::new(&mut file).finish(&mut df).unwrap();

let mut df = df!(
"sunpos" => scene.sun_pos.as_slice(),
"sunpos" => scene.sun.as_slice(),
)
.unwrap();
let mut file = std::fs::File::options()
Expand Down
Loading

0 comments on commit b78c7d9

Please sign in to comment.