Skip to main content

Results

Struct Results 

Source
pub struct Results<S: Interpolatable, R>{
    pub runs: Vec<Run<S, R>>,
    pub scenario: String,
}
Expand description

A structure of Monte Carlo results

Fields§

§runs: Vec<Run<S, R>>

Raw data from each run, sorted by run index for O(1) access to each run

§scenario: String

Name of this scenario

Implementations§

Source§

impl<S: Interpolatable> Results<S, PropResult<S>>

Source

pub fn every_value_of_between( &self, param: StateParameter, step: Duration, start: Epoch, end: Epoch, value_if_run_failed: Option<f64>, ) -> Vec<f64>

Returns the value of the requested state parameter for all trajectories from start to end every step and using the value of value_if_run_failed if set and skipping that run if the run failed

Source

pub fn every_value_of( &self, param: StateParameter, step: Duration, value_if_run_failed: Option<f64>, ) -> Vec<f64>

Returns the value of the requested state parameter for all trajectories from the start to the end of each trajectory and using the value of value_if_run_failed if set and skipping that run if the run failed

Source

pub fn first_values_of( &self, param: StateParameter, value_if_run_failed: Option<f64>, ) -> Vec<f64>

Returns the value of the requested state parameter for the first state and using the value of value_if_run_failed if set and skipping that run if the run failed

Source

pub fn last_values_of( &self, param: StateParameter, value_if_run_failed: Option<f64>, ) -> Vec<f64>

Returns the value of the requested state parameter for the first state and using the value of value_if_run_failed if set and skipping that run if the run failed

Source

pub fn dispersion_values_of( &self, param: StateParameter, ) -> Result<Vec<f64>, MonteCarloError>

Returns the dispersion values of the requested state parameter

Source

pub fn to_parquet<P: AsRef<Path>>( &self, path: P, cfg: ExportCfg, ) -> Result<PathBuf, Box<dyn Error>>

Examples found in repository?
examples/03_geo_analysis/stationkeeping.rs (line 131)
28fn main() -> Result<(), Box<dyn Error>> {
29    pel::init();
30    // Set up the dynamics like in the orbit raise.
31    let almanac = Arc::new(MetaAlmanac::latest().map_err(Box::new)?);
32    let epoch = Epoch::from_gregorian_utc_hms(2024, 2, 29, 12, 13, 14);
33
34    // Define the GEO orbit, and we're just going to maintain it very tightly.
35    let earth_j2000 = almanac.frame_info(EARTH_J2000)?;
36    let orbit = Orbit::try_keplerian(42164.0, 1e-5, 0., 163.0, 75.0, 0.0, epoch, earth_j2000)?;
37    println!("{orbit:x}");
38
39    let sc = Spacecraft::builder()
40        .orbit(orbit)
41        .mass(Mass::from_dry_and_prop_masses(1000.0, 1000.0)) // 1000 kg of dry mass and prop, totalling 2.0 tons
42        .srp(SRPData::from_area(3.0 * 6.0)) // Assuming 1 kW/m^2 or 18 kW, giving a margin of 4.35 kW for on-propulsion consumption
43        .thruster(Thruster {
44            // "NEXT-STEP" row in Table 2
45            isp_s: 4435.0,
46            thrust_N: 0.472,
47        })
48        .mode(GuidanceMode::Thrust) // Start thrusting immediately.
49        .build();
50
51    // Set up the spacecraft dynamics like in the orbit raise example.
52
53    let prop_time = 30.0 * Unit::Day;
54
55    // Define the guidance law -- we're just using a Ruggiero controller as demonstrated in AAS-2004-5089.
56    let objectives = &[
57        Objective::within_tolerance(
58            StateParameter::Element(OrbitalElement::SemiMajorAxis),
59            42_165.0,
60            20.0,
61        ),
62        Objective::within_tolerance(
63            StateParameter::Element(OrbitalElement::Eccentricity),
64            0.001,
65            5e-5,
66        ),
67        Objective::within_tolerance(
68            StateParameter::Element(OrbitalElement::Inclination),
69            0.05,
70            1e-2,
71        ),
72    ];
73
74    let ruggiero_ctrl = Ruggiero::from_max_eclipse(objectives, sc, 0.2)?;
75    println!("{ruggiero_ctrl}");
76
77    let mut orbital_dyn = OrbitalDynamics::point_masses(vec![MOON, SUN]);
78
79    let mut jgm3_meta = MetaFile {
80        uri: "http://public-data.nyxspace.com/nyx/models/JGM3.cof.gz".to_string(),
81        crc32: Some(0xF446F027), // Specifying the CRC32 avoids redownloading it if it's cached.
82    };
83    jgm3_meta.process(true)?;
84
85    let harmonics = Harmonics::from_stor(
86        almanac.frame_info(IAU_EARTH_FRAME)?,
87        HarmonicsMem::from_cof(&jgm3_meta.uri, 8, 8, true)?,
88    );
89    orbital_dyn.accel_models.push(harmonics);
90
91    let srp_dyn = SolarPressure::default(EARTH_J2000, almanac.clone())?;
92    let sc_dynamics = SpacecraftDynamics::from_model(orbital_dyn, srp_dyn)
93        .with_guidance_law(ruggiero_ctrl.clone());
94
95    println!("{sc_dynamics}");
96
97    // Finally, let's use the Monte Carlo framework built into Nyx to propagate spacecraft.
98
99    // Let's start by defining the dispersion.
100    // The MultivariateNormal structure allows us to define the dispersions in any of the orbital parameters, but these are applied directly in the Cartesian state space.
101    // Note that additional validation on the MVN is in progress -- https://github.com/nyx-space/nyx/issues/339.
102    let mc_rv = MvnSpacecraft::new(
103        sc,
104        vec![StateDispersion::zero_mean(
105            StateParameter::Element(OrbitalElement::SemiMajorAxis),
106            3.0,
107        )],
108    )?;
109
110    let my_mc = MonteCarlo::new(
111        sc, // Nominal state
112        mc_rv,
113        "03_geo_sk".to_string(), // Scenario name
114        None, // No specific seed specified, so one will be drawn from the computer's entropy.
115    );
116
117    // Build the propagator setup.
118    let setup = Propagator::rk89(
119        sc_dynamics.clone(),
120        IntegratorOptions::builder()
121            .min_step(10.0_f64.seconds())
122            .error_ctrl(ErrorControl::RSSCartesianStep)
123            .build(),
124    );
125
126    let num_runs = 25;
127    let rslts = my_mc.run_until_epoch(setup, almanac.clone(), sc.epoch() + prop_time, num_runs);
128
129    assert_eq!(rslts.runs.len(), num_runs);
130
131    rslts.to_parquet("03_geo_sk.parquet", ExportCfg::default())?;
132
133    Ok(())
134}
More examples
Hide additional examples
examples/02_jwst_covar_monte_carlo/main.rs (line 151)
26fn main() -> Result<(), Box<dyn Error>> {
27    pel::init();
28    // Dynamics models require planetary constants and ephemerides to be defined.
29    // Let's start by grabbing those by using ANISE's latest MetaAlmanac.
30    // For details, refer to https://github.com/nyx-space/anise/blob/master/data/latest.dhall.
31
32    // Download the regularly update of the James Webb Space Telescope reconstucted (or definitive) ephemeris.
33    // Refer to https://naif.jpl.nasa.gov/pub/naif/JWST/kernels/spk/aareadme.txt for details.
34    let mut latest_jwst_ephem = MetaFile {
35        uri: "https://naif.jpl.nasa.gov/pub/naif/JWST/kernels/spk/jwst_rec.bsp".to_string(),
36        crc32: None,
37    };
38    latest_jwst_ephem.process(true)?;
39
40    // Load this ephem in the general Almanac we're using for this analysis.
41    let almanac = Arc::new(
42        MetaAlmanac::latest()
43            .map_err(Box::new)?
44            .load_from_metafile(latest_jwst_ephem, true)?,
45    );
46
47    // By loading this ephemeris file in the ANISE GUI or ANISE CLI, we can find the NAIF ID of the JWST
48    // in the BSP. We need this ID in order to query the ephemeris.
49    const JWST_NAIF_ID: i32 = -170;
50    // Let's build a frame in the J2000 orientation centered on the JWST.
51    const JWST_J2000: Frame = Frame::from_ephem_j2000(JWST_NAIF_ID);
52
53    // Since the ephemeris file is updated regularly, we'll just grab the latest state in the ephem.
54    let (earliest_epoch, latest_epoch) = almanac.spk_domain(JWST_NAIF_ID)?;
55    println!("JWST defined from {earliest_epoch} to {latest_epoch}");
56    // Fetch the state, printing it in the Earth J2000 frame.
57    let jwst_orbit = almanac.transform(JWST_J2000, EARTH_J2000, latest_epoch, None)?;
58    println!("{jwst_orbit:x}");
59
60    // Build the spacecraft
61    // SRP area assumed to be the full sunshield and mass if 6200.0 kg, c.f. https://webb.nasa.gov/content/about/faqs/facts.html
62    // SRP Coefficient of reflectivity assumed to be that of Kapton, i.e. 2 - 0.44 = 1.56, table 1 from https://amostech.com/TechnicalPapers/2018/Poster/Bengtson.pdf
63    let jwst = Spacecraft::builder()
64        .orbit(jwst_orbit)
65        .srp(SRPData {
66            area_m2: 21.197 * 14.162,
67            coeff_reflectivity: 1.56,
68        })
69        .mass(Mass::from_dry_mass(6200.0))
70        .build();
71
72    // Build up the spacecraft uncertainty builder.
73    // We can use the spacecraft uncertainty structure to build this up.
74    // We start by specifying the nominal state (as defined above), then the uncertainty in position and velocity
75    // in the RIC frame. We could also specify the Cr, Cd, and mass uncertainties, but these aren't accounted for until
76    // Nyx can also estimate the deviation of the spacecraft parameters.
77    let jwst_uncertainty = SpacecraftUncertainty::builder()
78        .nominal(jwst)
79        .frame(LocalFrame::RIC)
80        .x_km(0.5)
81        .y_km(0.3)
82        .z_km(1.5)
83        .vx_km_s(1e-4)
84        .vy_km_s(0.6e-3)
85        .vz_km_s(3e-3)
86        .build();
87
88    println!("{jwst_uncertainty}");
89
90    // Build the Kalman filter estimate.
91    // Note that we could have used the KfEstimate structure directly (as seen throughout the OD integration tests)
92    // but this approach requires quite a bit more boilerplate code.
93    let jwst_estimate = jwst_uncertainty.to_estimate()?;
94
95    // Set up the spacecraft dynamics.
96    // We'll use the point masses of the Earth, Sun, Jupiter (barycenter, because it's in the DE440), and the Moon.
97    // We'll also enable solar radiation pressure since the James Webb has a huge and highly reflective sun shield.
98
99    let orbital_dyn = OrbitalDynamics::point_masses(vec![MOON, SUN, JUPITER_BARYCENTER]);
100    let srp_dyn = SolarPressure::new(vec![EARTH_J2000, MOON_J2000], almanac.clone())?;
101
102    // Finalize setting up the dynamics.
103    let dynamics = SpacecraftDynamics::from_model(orbital_dyn, srp_dyn);
104
105    // Build the propagator set up to use for the whole analysis.
106    let setup = Propagator::default(dynamics);
107
108    // All of the analysis will use this duration.
109    let prediction_duration = 6.5 * Unit::Day;
110
111    // === Covariance mapping ===
112    // For the covariance mapping / prediction, we'll use the common orbit determination approach.
113    // This is done by setting up a spacecraft Kalman filter OD process, and predicting for the analysis duration.
114
115    // Build the propagation instance for the OD process.
116    let odp = SpacecraftKalmanOD::new(
117        setup.clone(),
118        KalmanVariant::DeviationTracking,
119        None,
120        BTreeMap::new(),
121        almanac.clone(),
122    );
123
124    // The prediction step is 1 minute by default, configured in the OD process, i.e. how often we want to know the covariance.
125    assert_eq!(odp.max_step, 1_i64.minutes());
126    // Finally, predict, and export the trajectory with covariance to a parquet file.
127    let od_sol = odp.predict_for(jwst_estimate, prediction_duration)?;
128    od_sol.to_parquet("./02_jwst_covar_map.parquet", ExportCfg::default())?;
129
130    // === Monte Carlo framework ===
131    // Nyx comes with a complete multi-threaded Monte Carlo frame. It's blazing fast.
132
133    let my_mc = MonteCarlo::new(
134        jwst, // Nominal state
135        jwst_estimate.to_random_variable()?,
136        "02_jwst".to_string(), // Scenario name
137        None, // No specific seed specified, so one will be drawn from the computer's entropy.
138    );
139
140    let num_runs = 5_000;
141    let rslts = my_mc.run_until_epoch(
142        setup,
143        almanac.clone(),
144        jwst.epoch() + prediction_duration,
145        num_runs,
146    );
147
148    assert_eq!(rslts.runs.len(), num_runs);
149    // Finally, export these results, computing the eclipse percentage for all of these results.
150
151    rslts.to_parquet("02_jwst_monte_carlo.parquet", ExportCfg::default())?;
152
153    Ok(())
154}

Auto Trait Implementations§

§

impl<S, R> Freeze for Results<S, R>

§

impl<S, R> !RefUnwindSafe for Results<S, R>

§

impl<S, R> Send for Results<S, R>

§

impl<S, R> Sync for Results<S, R>

§

impl<S, R> Unpin for Results<S, R>

§

impl<S, R> UnsafeUnpin for Results<S, R>

§

impl<S, R> !UnwindSafe for Results<S, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more