Skip to content

Commit

Permalink
Merge pull request #549 from RocketPy-Team/enh/dispersion-renaming
Browse files Browse the repository at this point in the history
MNT: Dispersion Renaming
  • Loading branch information
Gui-FernandesBR authored Feb 12, 2024
2 parents b16e329 + f234624 commit 0f80516
Show file tree
Hide file tree
Showing 36 changed files with 549 additions and 575 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"!git clone https://github.com/RocketPy-Team/RocketPy.git\n",
"import os\n",
"\n",
"os.chdir(\"RocketPy/docs/notebooks/dispersion_analysis\")"
"os.chdir(\"RocketPy/docs/notebooks/monte_carlo_analysis\")"
]
},
{
Expand Down Expand Up @@ -382,7 +382,7 @@
],
"source": [
"# Basic analysis info\n",
"filename = \"dispersion_analysis_outputs/valetudo_rocket_v0\"\n",
"filename = \"monte_carlo_analysis_outputs/valetudo_rocket_v0\"\n",
"number_of_simulations = 100\n",
"\n",
"# Create data files for inputs, outputs and error logging\n",
Expand All @@ -402,7 +402,7 @@
"Env.max_expected_height = 1500\n",
"Env.set_atmospheric_model(\n",
" type=\"Ensemble\",\n",
" file=\"dispersion_analysis_inputs/LASC2019_reanalysis.nc\",\n",
" file=\"monte_carlo_analysis_inputs/LASC2019_reanalysis.nc\",\n",
" dictionary=\"ECMWF\",\n",
")\n",
"\n",
Expand All @@ -426,7 +426,7 @@
"\n",
" # Create motor\n",
" Keron = SolidMotor(\n",
" thrust_source=\"dispersion_analysis_inputs/thrustCurve.csv\",\n",
" thrust_source=\"monte_carlo_analysis_inputs/thrustCurve.csv\",\n",
" burn_time=5.274,\n",
" reshape_thrust_curve=(setting[\"burn_time\"], setting[\"impulse\"]),\n",
" nozzle_radius=setting[\"nozzle_radius\"],\n",
Expand Down Expand Up @@ -458,8 +458,8 @@
" setting[\"rocket_inertia_11\"],\n",
" setting[\"rocket_inertia_33\"],\n",
" ),\n",
" power_off_drag=\"dispersion_analysis_inputs/Cd_PowerOff.csv\",\n",
" power_on_drag=\"dispersion_analysis_inputs/Cd_PowerOn.csv\",\n",
" power_off_drag=\"monte_carlo_analysis_inputs/Cd_PowerOff.csv\",\n",
" power_on_drag=\"monte_carlo_analysis_inputs/Cd_PowerOn.csv\",\n",
" center_of_mass_without_motor=0,\n",
" coordinate_system_orientation=\"tail_to_nose\",\n",
" )\n",
Expand Down Expand Up @@ -572,7 +572,7 @@
}
],
"source": [
"filename = \"dispersion_analysis_outputs/valetudo_rocket_v0\"\n",
"filename = \"monte_carlo_analysis_outputs/valetudo_rocket_v0\"\n",
"\n",
"# Initialize variable to store all results\n",
"dispersion_general_results = []\n",
Expand Down Expand Up @@ -12892,9 +12892,7 @@
")\n",
"\n",
"plt.figure()\n",
"plt.hist(\n",
" dispersion_results[\"initial_static_margin\"], label=\"Initial\", bins=int(N**0.5)\n",
")\n",
"plt.hist(dispersion_results[\"initial_static_margin\"], label=\"Initial\", bins=int(N**0.5))\n",
"plt.hist(\n",
" dispersion_results[\"out_of_rail_static_margin\"],\n",
" label=\"Out of Rail\",\n",
Expand Down Expand Up @@ -20354,7 +20352,7 @@
"from matplotlib.patches import Ellipse\n",
"\n",
"# Import background map\n",
"img = imread(\"dispersion_analysis_inputs/Valetudo_basemap_final.jpg\")\n",
"img = imread(\"monte_carlo_analysis_inputs/Valetudo_basemap_final.jpg\")\n",
"\n",
"# Retrieve dispersion data por apogee and impact XY position\n",
"apogee_x = np.array(dispersion_results[\"apogee_x\"])\n",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"!git clone https://github.com/giovaniceotto/RocketPy.git\n",
"import os\n",
"\n",
"os.chdir(\"RocketPy/docs/notebooks/dispersion_analysis\")"
"os.chdir(\"RocketPy/docs/notebooks/monte_carlo_analysis\")"
]
},
{
Expand Down Expand Up @@ -391,7 +391,7 @@
"outputs": [],
"source": [
"# Basic analysis info\n",
"filename = \"dispersion_analysis_outputs/parachute_drop_from_helicopter\"\n",
"filename = \"monte_carlo_analysis_outputs/parachute_drop_from_helicopter\"\n",
"number_of_simulations = 4000\n",
"\n",
"# Create data files for inputs, outputs and error logging\n",
Expand All @@ -413,7 +413,7 @@
"Env.maxExpectedHeight = 1500\n",
"Env.setAtmosphericModel(\n",
" type=\"Ensemble\",\n",
" file=\"dispersion_analysis_inputs/LASC2019_reanalysis.nc\",\n",
" file=\"monte_carlo_analysis_inputs/LASC2019_reanalysis.nc\",\n",
" dictionary=\"ECMWF\",\n",
")\n",
"\n",
Expand All @@ -436,7 +436,7 @@
"\n",
" # Create motor\n",
" Keron = SolidMotor(\n",
" thrustSource=\"dispersion_analysis_inputs/thrustCurve.csv\",\n",
" thrustSource=\"monte_carlo_analysis_inputs/thrustCurve.csv\",\n",
" burn_time=5.274,\n",
" reshapeThrustCurve=(setting[\"burn_time\"], setting[\"impulse\"]),\n",
" nozzle_radius=setting[\"nozzle_radius\"],\n",
Expand All @@ -459,8 +459,8 @@
" mass=setting[\"rocketMass\"],\n",
" inertiaI=setting[\"inertiaI\"],\n",
" inertiaZ=setting[\"inertiaZ\"],\n",
" powerOffDrag=\"dispersion_analysis_inputs/Cd_PowerOff.csv\",\n",
" powerOnDrag=\"dispersion_analysis_inputs/Cd_PowerOn.csv\",\n",
" powerOffDrag=\"monte_carlo_analysis_inputs/Cd_PowerOff.csv\",\n",
" powerOnDrag=\"monte_carlo_analysis_inputs/Cd_PowerOn.csv\",\n",
" centerOfDryMassPosition=0,\n",
" coordinateSystemOrientation=\"tailToNose\",\n",
" )\n",
Expand Down Expand Up @@ -581,7 +581,7 @@
},
"outputs": [],
"source": [
"filename = \"dispersion_analysis_outputs/parachute_drop_from_helicopter\"\n",
"filename = \"monte_carlo_analysis_outputs/parachute_drop_from_helicopter\"\n",
"\n",
"# Initialize variable to store all results\n",
"dispersion_general_results = []\n",
Expand Down Expand Up @@ -1165,7 +1165,7 @@
"from matplotlib.patches import Ellipse\n",
"\n",
"# Import background map\n",
"img = imread(\"dispersion_analysis_inputs/Valetudo_basemap_final.jpg\")\n",
"img = imread(\"monte_carlo_analysis_inputs/Valetudo_basemap_final.jpg\")\n",
"\n",
"# Retrieve dispersion data por apogee and impact XY position\n",
"apogeeX = np.array(dispersion_results[\"apogeeX\"])\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/user/first_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ analysis. Here we will show some examples, but much more can be done!
.. seealso::
*RocketPy* can be used to perform a Monte Carlo Dispersion Analysis.
See
`Monte Carlo Simulations <https://colab.research.google.com/github/RocketPy-Team/rocketpy/blob/master/docs/notebooks/dispersion_analysis/dispersion_analysis.html>`_
`Monte Carlo Simulations <https://colab.research.google.com/github/RocketPy-Team/rocketpy/blob/master/docs/notebooks/monte_carlo_analysis/monte_carlo_analysis.html>`_
for more information.

Apogee as a Function of Mass
Expand Down
4 changes: 2 additions & 2 deletions docs/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ RocketPy's User Guide
:maxdepth: 2
:caption: Dispersion Analysis

../notebooks/dispersion_analysis/dispersion_analysis.ipynb
../notebooks/dispersion_analysis/parachute_drop_from_helicopter.ipynb
../notebooks/monte_carlo_analysis/monte_carlo_analysis.ipynb
../notebooks/monte_carlo_analysis/parachute_drop_from_helicopter.ipynb

.. toctree::
:maxdepth: 2
Expand Down
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,8 @@ 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 +139,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 +161,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 +179,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 0f80516

Please sign in to comment.