Skip to content

Commit

Permalink
MNT: renaming to monte_carlo
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano committed Feb 8, 2024
1 parent 1bae4b6 commit 3bee793
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 189 deletions.
130 changes: 59 additions & 71 deletions docs/notebooks/dispersion_analysis/dispersion_class_usage.ipynb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions rocketpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
funcify_method,
reset_funcified_methods,
)
from .monte_carlo import (
McEllipticalFins,
McEnvironment,
McFlight,
McNoseCone,
McParachute,
McRocket,
McSolidMotor,
McTail,
McTrapezoidalFins,
from .stochastic import (
StochasticEllipticalFins,
StochasticEnvironment,
StochasticFlight,
StochasticNoseCone,
StochasticParachute,
StochasticRocket,
StochasticSolidMotor,
StochasticTail,
StochasticTrapezoidalFins,
)
from .motors import (
CylindricalTank,
Expand Down Expand Up @@ -45,5 +45,5 @@
Tail,
TrapezoidalFins,
)
from .simulation import Flight, Dispersion
from .simulation import Flight, MonteCarlo
from .plots.compare import Compare, CompareFlights
14 changes: 0 additions & 14 deletions rocketpy/monte_carlo/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
__author__ = (
"Mateus Stano Junqueira, Guilherme Fernandes Alves, Bruno Abdulklech Sorban"
)
__copyright__ = "Copyright 20XX, RocketPy Team"
__license__ = "MIT"


import matplotlib.pyplot as plt

from ..tools import generate_dispersion_ellipses
from ..tools import generate_monte_carlo_ellipses


class _DispersionPlots:
"""Class to plot the dispersion results of the dispersion analysis."""
class _MonteCarloPlots:
"""Class to plot the monte carlo analysis results."""

def __init__(self, dispersion):
self.dispersion = dispersion
return None
def __init__(self, monte_carlo):
self.monte_carlo = monte_carlo

def ellipses(
self,
Expand All @@ -36,7 +28,7 @@ def ellipses(
The path to the image to be used as the background
actual_landing_point : tuple, optional
A tuple containing the actual landing point of the rocket, if known.
Useful when comparing the dispersion results with the actual landing.
Useful when comparing the monte_carlo results with the actual landing.
Must be given in tuple format, such as (x, y) in meters.
By default None.
perimeterSize : int, optional
Expand Down Expand Up @@ -76,7 +68,7 @@ def ellipses(
apogeeY,
impactX,
impactY,
) = generate_dispersion_ellipses(self.dispersion.results)
) = generate_monte_carlo_ellipses(self.monte_carlo.results)

# Create plot figure
plt.figure(num=None, figsize=(8, 6), dpi=150, facecolor="w", edgecolor="k")
Expand Down Expand Up @@ -117,7 +109,7 @@ def ellipses(

# Add title and labels to plot
ax.set_title(
"1$\\sigma$, 2$\\sigma$ and 3$\\sigma$ Dispersion Ellipses: Apogee and Landing Points"
"1$\\sigma$, 2$\\sigma$ and 3$\\sigma$ monte_carlo Ellipses: Apogee and Landing Points"
)
ax.set_ylabel("North (m)")
ax.set_xlabel("East (m)")
Expand Down Expand Up @@ -146,16 +138,15 @@ def ellipses(
# Save plot and show result
if save:
plt.savefig(
str(self.dispersion.filename) + ".png",
str(self.monte_carlo.filename) + ".png",
bbox_inches="tight",
pad_inches=0,
)
else:
plt.show()
return None

def all_results(self, keys=None):
"""Plot the results of the dispersion analysis.
"""Plot the results of the monte_carlo analysis.
Parameters
----------
Expand All @@ -169,11 +160,11 @@ def all_results(self, keys=None):
"""

if keys is None:
keys = self.dispersion.results.keys()
keys = self.monte_carlo.results.keys()
elif isinstance(keys, str):
keys = [keys]
elif isinstance(keys, (list, tuple)):
keys = list(set(keys).intersection(self.dispersion.results.keys()))
keys = list(set(keys).intersection(self.monte_carlo.results.keys()))
if len(keys) == 0:
raise ValueError(
"The selected 'keys' are not available in the results. "
Expand All @@ -187,10 +178,8 @@ def all_results(self, keys=None):
for key in keys:
plt.figure()
plt.hist(
self.dispersion.results[key],
self.monte_carlo.results[key],
)
plt.title("Histogram of " + key)
plt.ylabel("Number of Occurrences")
plt.show()

return None
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
__author__ = "Guilherme Fernandes Alves"
__copyright__ = "Copyright 20XX, RocketPy Team"
__license__ = "MIT"
class _MonteCarloPrints:
"""Class to print the monte carlo analysis results."""


class _DispersionPrints:
"""Class to print the dispersion results of the dispersion analysis."""

def __init__(self, dispersion):
self.dispersion = dispersion
def __init__(self, monte_carlo):
self.monte_carlo = monte_carlo
return None

def all_results(self):
Expand All @@ -24,12 +19,12 @@ def all_results(self):
"""
print("Monte Carlo Simulation by RocketPy")
print("Data Source: ", self.dispersion.filename)
print("Number of simulations: ", self.dispersion.num_of_loaded_sims)
print("Data Source: ", self.monte_carlo.filename)
print("Number of simulations: ", self.monte_carlo.num_of_loaded_sims)
print("Results: \n")
print("{:>25} {:>15} {:>15}".format("Parameter", "Mean", "Std. Dev."))
print("-" * 60)
for key, value in self.dispersion.processed_results.items():
for key, value in self.monte_carlo.processed_results.items():
print("{:>25} {:>15.3f} {:>15.3f}".format(key, value[0], value[1]))

return None
2 changes: 1 addition & 1 deletion rocketpy/simulation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .dispersion import Dispersion
from .monte_carlo import MonteCarlo
from .flight import Flight
from .flight_data_importer import FlightDataImporter
Loading

0 comments on commit 3bee793

Please sign in to comment.