Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume W. Bres <[email protected]>
  • Loading branch information
gwbres committed Jul 28, 2024
2 parents 7591e85 + 0fae4d8 commit f8faabb
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 185 deletions.
5 changes: 1 addition & 4 deletions rinex-cli/src/graph/record/ionosphere.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::graph::{build_chart_epoch_axis, PlotContext};
use anise::almanac::Almanac;
// use hifitime::{Epoch, TimeScale};
use plotly::common::{
//Marker,
Expand All @@ -20,8 +19,6 @@ pub fn plot_ionospheric_delay(ctx: &QcContext, plot_ctx: &mut PlotContext) {
let lat_lon_ddeg = (ref_geo.0, ref_geo.1);
let ref_ecef_wgs84 = ref_pos.to_ecef_wgs84();

let almanac = Almanac::until_2035().unwrap();

if let Some(obs) = ctx.observation() {
if let Some(nav) = ctx.brdc_navigation() {
for (sv_index, sv) in obs.sv().enumerate() {
Expand Down Expand Up @@ -56,7 +53,7 @@ pub fn plot_ionospheric_delay(ctx: &QcContext, plot_ctx: &mut PlotContext) {
*/
let sv_position = match ctx.sp3() {
Some(sp3) => sp3.sv_position_interpolate(sv, *t, 11),
None => nav.sv_position_interpolate(sv, *t, 11, &almanac),
None => nav.sv_position_interpolate(sv, *t, 11),
};
let sv_position = sv_position?;
let (elev, azim) =
Expand Down
10 changes: 4 additions & 6 deletions rinex-cli/src/graph/record/navigation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::graph::{build_3d_chart_epoch_label, build_chart_epoch_axis, PlotContext};
use anise::almanac::Almanac;
use plotly::common::{Mode, Visible};
use rinex::navigation::Ephemeris;
use rinex::prelude::*;
Expand Down Expand Up @@ -371,7 +370,6 @@ fn plot_system_time(
pub fn plot_sv_nav_orbits(ctx: &QcContext, plot_ctx: &mut PlotContext) {
let mut pos_plot_created = false;
let mut nav_sv = Vec::<SV>::with_capacity(32);
let almanac = Almanac::until_2035().unwrap();
/*
* Plot Broadcast Orbit (x, y, z)
*/
Expand All @@ -384,7 +382,7 @@ pub fn plot_sv_nav_orbits(ctx: &QcContext, plot_ctx: &mut PlotContext) {
pos_plot_created = true;
}
let epochs: Vec<_> = nav
.sv_position(&almanac)
.sv_position()
.filter_map(
|(epoch, svnn, (_, _, _))| {
if svnn == sv {
Expand All @@ -397,7 +395,7 @@ pub fn plot_sv_nav_orbits(ctx: &QcContext, plot_ctx: &mut PlotContext) {
.collect();

let x_km: Vec<_> = nav
.sv_position(&almanac)
.sv_position()
.filter_map(
|(_epoch, svnn, (x, _, _))| {
if svnn == sv {
Expand All @@ -409,7 +407,7 @@ pub fn plot_sv_nav_orbits(ctx: &QcContext, plot_ctx: &mut PlotContext) {
)
.collect();
let y_km: Vec<_> = nav
.sv_position(&almanac)
.sv_position()
.filter_map(
|(_epoch, svnn, (_, y, _))| {
if svnn == sv {
Expand All @@ -421,7 +419,7 @@ pub fn plot_sv_nav_orbits(ctx: &QcContext, plot_ctx: &mut PlotContext) {
)
.collect();
let z_km: Vec<_> = nav
.sv_position(&almanac)
.sv_position()
.filter_map(
|(_epoch, svnn, (_, _, z))| {
if svnn == sv {
Expand Down
5 changes: 1 addition & 4 deletions rinex-cli/src/graph/record/sp3_plot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::graph::{build_chart_epoch_axis, PlotContext};
use anise::almanac::Almanac;
use plotly::common::{Mode, Visible}; //Marker, MarkerSymbol
use rinex::prelude::{Epoch, SV};
use rinex_qc::prelude::QcContext;
Expand Down Expand Up @@ -36,9 +35,7 @@ pub fn plot_residual_ephemeris(ctx: &QcContext, plot_ctx: &mut PlotContext) {

let mut residuals: HashMap<SV, (Vec<(f64, f64, f64)>, Vec<Epoch>)> = HashMap::new();

let almanac = Almanac::until_2035().unwrap();

for (t, nav_sv, (x_km, y_km, z_km)) in nav.sv_position(&almanac) {
for (t, nav_sv, (x_km, y_km, z_km)) in nav.sv_position() {
if let Some((_, _, (sp3_x, sp3_y, sp3_z))) = sp3
.sv_position()
.find(|(e_sp3, sv_sp3, (_, _, _))| *e_sp3 == t && *sv_sp3 == nav_sv)
Expand Down
8 changes: 4 additions & 4 deletions rinex-cli/src/positioning/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::cli::Context;
use anise::almanac::Almanac;
use clap::ArgMatches;
use std::cell::RefCell;
use std::fs::read_to_string;
// use anise::almanac::Almanac;

mod ppp; // precise point positioning
use ppp::Report as PPPReport;
Expand Down Expand Up @@ -312,14 +312,14 @@ a static reference position"
None
};

let almanac = Almanac::until_2035()
.unwrap_or_else(|e| panic!("failed to retrieve latest Almanac: {}", e));
//let almanac = Almanac::until_2035()
// .unwrap_or_else(|e| panic!("failed to retrieve latest Almanac: {}", e));

let solver = Solver::new(
&cfg,
apriori,
/* state vector interpolator */
|t, sv, _order| orbit.borrow_mut().next_at(t, sv, &almanac),
|t, sv, _order| orbit.borrow_mut().next_at(t, sv),
)?;

if matches.get_flag("cggtts") {
Expand Down
5 changes: 2 additions & 3 deletions rinex-cli/src/positioning/orbit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::cli::Context;
use anise::almanac::Almanac;
use gnss_rtk::prelude::{Epoch, InterpolationResult, SV};

mod sp3;
Expand All @@ -21,10 +20,10 @@ impl<'a> Orbit<'a> {
Self::NAV(NAVOrbit::from_ctx(ctx))
}
}
pub fn next_at(&mut self, t: Epoch, sv: SV, almanac: &Almanac) -> Option<InterpolationResult> {
pub fn next_at(&mut self, t: Epoch, sv: SV) -> Option<InterpolationResult> {
match self {
Self::SP3(orbit) => orbit.next_at(t, sv),
Self::NAV(orbit) => orbit.next_at(t, sv, &almanac),
Self::NAV(orbit) => orbit.next_at(t, sv),
}
}
}
14 changes: 2 additions & 12 deletions rinex-cli/src/positioning/orbit/nav.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::cli::Context;
use std::collections::HashMap;

use anise::almanac::Almanac;
use gnss_rtk::prelude::{Epoch, InterpolationResult as RTKInterpolationResult, TimeScale, SV};

use rinex::navigation::Ephemeris;
Expand Down Expand Up @@ -43,12 +42,7 @@ impl<'a> Orbit<'a> {
false
}
}
pub fn next_at(
&mut self,
t: Epoch,
sv: SV,
almanac: &Almanac,
) -> Option<RTKInterpolationResult> {
pub fn next_at(&mut self, t: Epoch, sv: SV) -> Option<RTKInterpolationResult> {
let sv_ts = sv.timescale()?;

while !self.feasible(t, sv, sv_ts) {
Expand All @@ -74,10 +68,6 @@ impl<'a> Orbit<'a> {
},
)?;

//let t_gpst = t.to_time_scale(TimeScale::GPST).duration.to_seconds();
// let toc_gpst = toc_i.to_time_scale(TimeScale::GPST).duration.to_seconds();
//let dt = t_gpst - toc_gpst;

let (x, y, z) = (
eph_i.get_orbit_f64("satPosX")? * 1.0E3,
eph_i.get_orbit_f64("satPosY")? * 1.0E3,
Expand Down Expand Up @@ -117,7 +107,7 @@ impl<'a> Orbit<'a> {
},
)?;

let (x_km, y_km, z_km) = eph_i.kepler2position(sv, t, almanac)?;
let (x_km, y_km, z_km) = eph_i.kepler2position(sv, t)?;
let (x, y, z) = (x_km * 1.0E3, y_km * 1.0E3, z_km * 1.0E3);
Some(RTKInterpolationResult::from_position((x, y, z)))
}
Expand Down
6 changes: 3 additions & 3 deletions rinex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ obs = []
# Unlocks BRDC calculations, including Keplerian calculations (Ephemeris),
# all NAV RINEX iteration and exploitation, including Ut1Provider.
nav = [
"dep:nalgebra",
"nalgebra",
"hifitime/ut1",
]

Expand Down Expand Up @@ -105,10 +105,10 @@ flate2 = { version = "1.0.24", optional = true, default-features = false, featur
geo = { version = "0.28", optional = true }
wkt = { version = "0.10.0", default-features = false, optional = true }

anise = "0.4.1"
# anise = "0.4.1"
nalgebra = { version = "0.32.3", optional = true }
hifitime = { version = "4.0.0-alpha", features = ["serde", "std"] }

nalgebra = { version = "0.32.3", optional = true }
gnss-rs = { version = "2.2.0", features = ["serde"] }

# RINEX QC dedicated traits
Expand Down
89 changes: 40 additions & 49 deletions rinex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern crate num_derive;
extern crate lazy_static;

pub mod reader;
use anise::almanac::Almanac;
// use anise::almanac::Almanac;
use reader::BufferedReader;

pub mod writer;
Expand Down Expand Up @@ -95,7 +95,7 @@ pub mod prelude {
pub use crate::types::Type as RinexType;
pub use crate::{Error, Rinex};
// pub re-export
pub use anise::prelude::Almanac;
// pub use anise::prelude::Almanac;
pub use gnss::prelude::{Constellation, DOMESTrackingPoint, COSPAR, DOMES, SV};
#[cfg(feature = "nav")]
pub use hifitime::ut1::DeltaTaiUt1;
Expand Down Expand Up @@ -2393,9 +2393,10 @@ impl Rinex {
/// Rinex::from_file("../test_resources/NAV/V3/ESBC00DNK_R_20201770000_01D_MN.rnx.gz")
/// .unwrap();
///
/// let almanac = Almanac::until_2035().unwrap();
/// // let almanac = Almanac::until_2035().unwrap();
///
/// for (epoch, sv, (x, y, z)) in rinex.sv_position(&almanac) {
/// // for (epoch, sv, (x, y, z)) in rinex.sv_position(&almanac) {
/// for (epoch, sv, (x, y, z)) in rinex.sv_position() {
/// // sv: satellite vehicle
/// // x: x(t) [km ECEF]
/// // y: y(t) [km ECEF]
Expand All @@ -2404,18 +2405,31 @@ impl Rinex {
/// ```
pub fn sv_position(
&self,
almanac: &Almanac,
// almanac: &Almanac,
) -> Box<dyn Iterator<Item = (Epoch, SV, (f64, f64, f64))> + '_> {
let almanac_clone = almanac.clone();
Box::new(self.ephemeris().filter_map(move |(e, (_, sv, ephemeris))| {
if let Some((x, y, z)) = ephemeris.sv_position(sv, *e, &almanac_clone) {
Some((*e, sv, (x, y, z)))
} else {
// non feasible calculations.
// most likely due to missing Keplerian parameters,
// at this Epoch
None
}
let (x, y, z) = ephemeris.sv_position(sv, *e)?;
Some((*e, sv, (x, y, z)))
}))
}
/// Returns Iterator over SV velocity vector, expressed in km/s ECEF.
/// ```
/// use rinex::prelude::*;
///
/// let mut rinex =
/// Rinex::from_file("../test_resources/NAV/V3/ESBC00DNK_R_20201770000_01D_MN.rnx.gz")
/// .unwrap();
///
/// for (epoch, sv, (sv_x, sv_y, sv_z)) in rinex.sv_velocity() {
/// // sv_x : km/s
/// // sv_y : km/s
/// // sv_z : km/s
/// }
/// ```
pub fn sv_velocity(&self) -> Box<dyn Iterator<Item = (Epoch, SV, (f64, f64, f64))> + '_> {
Box::new(self.ephemeris().filter_map(move |(e, (_, sv, ephemeris))| {
let (v_x, v_y, v_z) = ephemeris.sv_position_velocity(sv, *e)?.1;
Some((*e, sv, (v_x, v_y, v_z)))
}))
}
/// Interpolates SV position, expressed in meters ECEF at desired Epoch `t`.
Expand All @@ -2434,7 +2448,7 @@ impl Rinex {
sv: SV,
t: Epoch,
order: usize,
almanac: &Almanac,
// almanac: &Almanac,
) -> Option<(f64, f64, f64)> {
let odd_order = order % 2 > 0;
let dt = match self.sample_rate() {
Expand All @@ -2451,7 +2465,7 @@ impl Rinex {
};

let sv_position: Vec<_> = self
.sv_position(almanac)
.sv_position()
.filter_map(|(e, svnn, (x, y, z))| {
if sv == svnn {
Some((e, (x, y, z)))
Expand Down Expand Up @@ -2522,9 +2536,10 @@ impl Rinex {
/// Rinex::from_file("../test_resources/NAV/V3/ESBC00DNK_R_20201770000_01D_MN.rnx.gz")
/// .unwrap();
///
/// let almanac = Almanac::until_2035().unwrap();
/// // let almanac = Almanac::until_2035().unwrap();
///
/// for (epoch, sv, (lat, lon, alt)) in rinex.sv_position_geo(&almanac) {
/// // for (epoch, sv, (lat, lon, alt)) in rinex.sv_position_geo(&almanac) {
/// for (epoch, sv, (lat, lon, alt)) in rinex.sv_position_geo() {
/// // sv: satellite vehicle
/// // lat [ddeg]
/// // lon [ddeg]
Expand All @@ -2533,35 +2548,13 @@ impl Rinex {
/// ```
pub fn sv_position_geo(
&self,
almanac: &Almanac,
// almanac: &Almanac,
) -> Box<dyn Iterator<Item = (Epoch, SV, (f64, f64, f64))> + '_> {
Box::new(self.sv_position(almanac).map(|(e, sv, (x, y, z))| {
Box::new(self.sv_position().map(|(e, sv, (x, y, z))| {
let (lat, lon, alt) = ecef2geodetic(x, y, z, map_3d::Ellipsoid::WGS84);
(e, sv, (lat, lon, alt))
}))
}
/// Returns Iterator over SV speed vectors, expressed in km/s ECEF.
/// ```
/// use rinex::prelude::*;
///
/// let mut rinex =
/// Rinex::from_file("../test_resources/NAV/V3/ESBC00DNK_R_20201770000_01D_MN.rnx.gz")
/// .unwrap();
///
/// //for (epoch, (sv, sv_x, sv_y, sv_z)) in rinex.sv_speed() {
/// // // sv_x : km/s
/// // // sv_y : km/s
/// // // sv_z : km/s
/// //}
/// ```
pub fn sv_speed(&self) -> Box<dyn Iterator<Item = (Epoch, SV, (f64, f64, f64))> + '_> {
todo!("sv_speed");
//Box::new(
// self.sv_position()
// self.sv_position()
// .skip(1)
//)
}
/// Returns an Iterator over SV elevation and azimuth angles,
/// both expressed in degrees.
/// A reference ground position must be known:
Expand All @@ -2576,9 +2569,10 @@ impl Rinex {
/// let rinex = Rinex::from_file("../test_resources/NAV/V3/ESBC00DNK_R_20201770000_01D_MN.rnx.gz")
/// .unwrap();
///
/// let almanac = Almanac::until_2035().unwrap();
/// // let almanac = Almanac::until_2035().unwrap();
///
/// let data = rinex.sv_elevation_azimuth(Some(ref_pos), &almanac);
/// // let data = rinex.sv_elevation_azimuth(Some(ref_pos), &almanac);
/// let data = rinex.sv_elevation_azimuth(Some(ref_pos));
/// for (epoch, sv, (elev, azim)) in data {
/// // azim: azimuth in °
/// // elev: elevation in °
Expand All @@ -2587,7 +2581,7 @@ impl Rinex {
pub fn sv_elevation_azimuth(
&self,
ref_position: Option<GroundPosition>,
almanac: &Almanac,
// almanac: &Almanac,
) -> Box<dyn Iterator<Item = (Epoch, SV, (f64, f64))> + '_> {
let ground_position = match ref_position {
Some(pos) => pos, // user value superceeds, in case it is passed
Expand All @@ -2601,13 +2595,10 @@ impl Rinex {
}
},
};
// Cloning is cheap
let almanac_clone = almanac.clone();
Box::new(
self.ephemeris()
.filter_map(move |(epoch, (_, sv, ephemeris))| {
if let Some((elev, azim)) =
ephemeris.sv_elev_azim(sv, *epoch, ground_position, &almanac_clone)
if let Some((elev, azim)) = ephemeris.sv_elev_azim(sv, *epoch, ground_position)
{
Some((*epoch, sv, (elev, azim)))
} else {
Expand Down
Loading

0 comments on commit f8faabb

Please sign in to comment.