Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e57f825
GIT: renaming the compare_plots file
Gui-FernandesBR Nov 13, 2022
811b3f0
Merge branch 'enh/new_plots' into enh/new_plotscompare-plots
Gui-FernandesBR Nov 13, 2022
221b1bb
MAINT: adding new lines to __init__.py files
Gui-FernandesBR Nov 14, 2022
48fb4a1
ENH: update the __init__ method of CompareFlights
Gui-FernandesBR Nov 14, 2022
1864f14
ENH: auxiliary function to create figures and axes
Gui-FernandesBR Nov 14, 2022
ecca579
ENH: compare positions method
Gui-FernandesBR Nov 14, 2022
6493a41
ENH: compare velocities method
Gui-FernandesBR Nov 14, 2022
2b50940
ENH: compare stream velocities method
Gui-FernandesBR Nov 14, 2022
e55c5f2
ENH: compare accelerations method
Gui-FernandesBR Nov 14, 2022
e2de760
ENH: compare euler angles method
Gui-FernandesBR Nov 14, 2022
9886137
ENH: compare quaternions method
Gui-FernandesBR Nov 14, 2022
f053fd8
ENH: compare attitude_angles method
Gui-FernandesBR Nov 14, 2022
eedfaa5
ENH: compare angular velocities method
Gui-FernandesBR Nov 14, 2022
35a7f0b
ENH: compare angular_accelerations
Gui-FernandesBR Nov 14, 2022
35b771e
ENH: compare aero forces and moments methods
Gui-FernandesBR Nov 14, 2022
c230e4c
ENH: compare energies and compare powers methods
Gui-FernandesBR Nov 14, 2022
64c2cf8
ENH: compare rail_buttons_forces method
Gui-FernandesBR Nov 14, 2022
5506c8a
ENH: compare angles of attack method
Gui-FernandesBR Nov 14, 2022
939b897
ENH: compare fluid mechanics
Gui-FernandesBR Nov 14, 2022
1b17914
ENH: compare attitude frequency response
Gui-FernandesBR Nov 14, 2022
bbe0d6e
ENH: static method to compare 3d trajectories
Gui-FernandesBR Nov 14, 2022
82657da
ENH: compare trajectories_3d method
Gui-FernandesBR Nov 14, 2022
890c7c5
ENH: Create CompareFlights.all() method
Gui-FernandesBR Nov 14, 2022
8f3c903
ENH: adding methods that will be created in future
Gui-FernandesBR Nov 14, 2022
a66a579
FIX: removing broken import
Gui-FernandesBR Nov 16, 2022
4eef4fc
Squashed commit of the following:
Gui-FernandesBR Nov 16, 2022
8760bb1
ENH: add temporary time and solutionArray propert
Gui-FernandesBR Nov 16, 2022
d8c7b89
FIX: debugging grids and legends
Gui-FernandesBR Nov 16, 2022
a73f2d4
GIT: giving up of frequency comparison
Gui-FernandesBR Nov 16, 2022
291d479
BUG: starting with null values of retrieved accel
Gui-FernandesBR Nov 16, 2022
7b81c0e
MAINT: refactor max_time variable
Gui-FernandesBR Nov 16, 2022
4203d82
ADD: new compare flights notebook
Gui-FernandesBR Nov 16, 2022
30339cf
enh: remove plt.close()
MateusStano Dec 30, 2022
f80d7c3
enh: created compare.py super class
MateusStano Jan 3, 2023
4d4161e
enh: adapted compare_flights to inherit compare class
MateusStano Jan 3, 2023
a6df18b
Merge branch 'enh/new_plots' into enh/new_plotscompare-plots
MateusStano Jan 3, 2023
d4ec8f3
MAINT: update __init__ files
Gui-FernandesBR Jan 4, 2023
fce219f
ENH: finish compare trajectories 2d functions
Gui-FernandesBR Jan 4, 2023
2586876
MAINT: update notebook
Gui-FernandesBR Jan 4, 2023
2d086a2
maint: docstring parameters order
MateusStano Jan 4, 2023
8105234
enh: rail_buttons_forces
MateusStano Jan 4, 2023
069b136
enh: made x_attributes optional
MateusStano Jan 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
669 changes: 669 additions & 0 deletions docs/notebooks/compare_flights_usage.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ Welcome to RocketPy's user documentation!
../notebooks/environment_analysis_EuroC_example.ipynb
../notebooks/dispersion_analysis/dispersion_analysis.ipynb
../notebooks/utilities_usage.ipynb
../notebooks/compare_flights_usage.ipynb
../matlab/matlab.rst

4 changes: 1 addition & 3 deletions rocketpy/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import pytz
import requests

from .prints.environment_prints import _EnvironmentPrints
from .plots.environment_plots import _EnvironmentPlots
from .prints.environment_prints import _EnvironmentPrints

try:
import netCDF4
Expand Down Expand Up @@ -3042,8 +3042,6 @@ def allInfo(self):
"""

self.prints.all()

# Plot graphs
self.plots.all()

return None
Expand Down
4 changes: 2 additions & 2 deletions rocketpy/Flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2313,8 +2313,8 @@ def retrieve_acceleration_arrays(self):
angular acceleration in z direction
"""
# Initialize acceleration arrays
ax, ay, az = [], [], []
alpha1, alpha2, alpha3 = [], [], []
ax, ay, az = [[0, 0]], [[0, 0]], [[0, 0]]
alpha1, alpha2, alpha3 = [[0, 0]], [[0, 0]], [[0, 0]]
# Go through each time step and calculate accelerations
# Get flight phases
for phase_index, phase in self.timeIterator(self.flightPhases):
Expand Down
2 changes: 2 additions & 0 deletions rocketpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
from .Motor import HybridMotor, SolidMotor
from .Rocket import Rocket
from .utilities import *
from .plots import *
from .prints import *
4 changes: 2 additions & 2 deletions rocketpy/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .flight_plots import _FlightPlots
from .compare import *
from .environment_plots import _EnvironmentPlots
from .flight_plots import _FlightPlots
from .rocket_plots import _RocketPlots
from .compare_plots import _ComparePlots
2 changes: 2 additions & 0 deletions rocketpy/plots/compare/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .compare import Compare
from .compare_flights import CompareFlights
186 changes: 186 additions & 0 deletions rocketpy/plots/compare/compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
__author__ = "Guilherme Fernandes Alves, Mateus Stano Junqueira"
__copyright__ = "Copyright 20XX, RocketPy Team"
__license__ = "MIT"

import warnings
import matplotlib.pyplot as plt


class Compare:
"""A class to compare the results of multiple objects of the same type.

Parameters
----------
object_list : list
A list of objects of the same type to be compared.

Attributes
----------
object_list : list
A list of objects to be compared.

"""

def __init__(self, object_list):
"""Initializes the Compare class.

Parameters
----------
object_list : list
A list of objects objects to be compared.

Returns
-------
None
"""

# check if all items in object_list are the same type
if not all(isinstance(obj, type(object_list[0])) for obj in object_list[1:]):
warnings.warn(
"Trying to compare objects of different classes. Make sure are items in the list are of the same type."
)

self.object_list = object_list

return None

def create_comparison_figure(
self,
y_attributes,
n_rows,
n_cols,
figsize,
legend,
title,
x_labels,
y_labels,
x_lim,
y_lim,
x_attributes=None,
):
"""Creates a figure to compare the results of multiple objects of the same type.

Parameters
----------
y_attributes : list
The attributes of the class to be plotted as the vertical coordinates
of the data points. The attributes must be a list of strings. Each string
must be a valid attribute of the object's class, i.e., should point to a
attribute of the object's class that is a Function object or a numpy array.
For example ["x", "y", "z"].
n_rows : int
The number of rows of the figure.
n_cols : int
The number of columns of the figure.
figsize : tuple
The standard matplotlib size of the figure, where the tuple means (width, height).
For example (7, 10).
legend : bool
Whether to show the legend or not.
title : str
The title of the figure.
x_labels : list
A list of strings of the x labels of each subplot.
For example ["Time (s)", "Time (s)", "Time (s)"].
y_labels : list
A list of strings of the y labels of each subplot.
For example ["x (m)", "y (m)", "z (m)"].
x_lim : tuple
A tuple where the first item represents the x axis lower limit and second item,
the x axis upper limit. If set to None, will be calculated automatically by
matplotlib.
y_lim : tuple
A tuple where the first item represents the y axis lower limit and second item,
the y axis upper limit. If set to None, will be calculated automatically by
matplotlib.
x_attributes : list
The attributes of the class to be plotted as the horizontal coordinates
of the data points. The attributes must be a list of strings. Each string
must be a valid attribute of the object's class, i.e., should point to a
attribute of the object's class that is a Function object or a numpy array.
For example ["time", "time", "time"].

Returns
-------
fig : matplotlib.figure.Figure
The figure object.
ax : matplotlib.axes._subplots.AxesSubplot
The axes object.
"""

n_plots = len(y_attributes)

# Create the matplotlib figure
fig = plt.figure(figsize=figsize)
fig.suptitle(title, fontsize=16, y=1.02, x=0.5)

# Create the subplots
ax = []
for i in range(n_plots):
ax.append(plt.subplot(n_rows, n_cols, i + 1))

# Adding the plots to each subplot
if x_attributes:
for object in self.object_list:
for i in range(n_plots):
try:
ax[i].plot(
object.__getattribute__(x_attributes[i])[:, 1],
object.__getattribute__(y_attributes[i])[:, 1],
label=object.name,
)
except IndexError:
ax[i].plot(
object.__getattribute__(x_attributes[i]),
object.__getattribute__(y_attributes[i])[:, 1],
label=object.name,
)
except AttributeError:
raise AttributeError(
f"Invalid attribute {y_attributes[i]} or {x_attributes[i]}."
)
else:
# Adding the plots to each subplot
for object in self.object_list:
for i in range(n_plots):
try:
ax[i].plot(
object.__getattribute__(y_attributes[i])[:, 0],
object.__getattribute__(y_attributes[i])[:, 1],
label=object.name,
)
except AttributeError:
raise AttributeError(f"Invalid attribute {y_attributes[i]}.")

for i, subplot in enumerate(ax):

# Set the labels for the x and y axis
subplot.set_xlabel(x_labels[i])
subplot.set_ylabel(y_labels[i])

# Set the limits for the x axis
if x_lim:
subplot.set_xlim(*x_lim)
if y_lim:
subplot.set_ylim(*y_lim)
subplot.grid(True) # Add a grid to the plot

# Find the two closest integers to the square root of the number of object_list
# to be used as the number of columns and rows of the legend
n_cols_legend = int(round(len(self.object_list) ** 0.5))
n_rows_legend = int(round(len(self.object_list) / n_cols_legend))

# Set the legend
if legend: # Add a global legend to the figure
fig.legend(
*ax[0].get_legend_handles_labels(),
loc="lower center",
ncol=n_cols_legend,
numpoints=1,
frameon=True,
bbox_to_anchor=(0.5, 1.05),
)

fig.tight_layout()

return fig, ax
Loading