Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIT: Updates master to v1.7.0 #731

Merged
merged 38 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a25c2ee
Inital implementation of callback function with some quick fixes of e…
Oct 6, 2024
69aaece
ENH: Implement optional plot saving (#597)
nalquas Nov 10, 2024
6fea165
DOC: fixed documentation about spherical caps
alessio26gas Nov 9, 2024
c512c40
Merge pull request #728 from alessio26gas/doc/spherical-caps-typo
Gui-FernandesBR Nov 10, 2024
b137b43
Merge branch 'develop' into enh/monte-carlo-callback
Lucas-Prates Nov 11, 2024
5929656
bug: fix print error when summary contains None results
Lucas-Prates Nov 11, 2024
62b3edb
ENH: avoid computing mean and std when it might not make sense (e.g d…
Lucas-Prates Nov 11, 2024
b602949
ENH: raises an error when user 'export_function' contains errors from…
Lucas-Prates Nov 11, 2024
b0e0a08
TST: providing tests to monte carlo callbacks 'export_function' argument
Lucas-Prates Nov 11, 2024
ed85b3e
BUG: Corrected calculation of beta angle in aerodynamic computations
MateusStano Nov 13, 2024
9bf6db1
BUG: fix damping coefficients sign in linear model
MateusStano Nov 13, 2024
5d0f643
DEV: changelog
MateusStano Nov 13, 2024
d2232e0
DOC: add simple example on how to use the callback export function
Lucas-Prates Nov 13, 2024
afb4e3f
MNT: make black to notebook example
Lucas-Prates Nov 13, 2024
1574aea
DEV: changelog
MateusStano Nov 15, 2024
5856353
Merge pull request #729 from RocketPy-Team/bug/generic-surfaces-corre…
MateusStano Nov 15, 2024
e1a2061
Merge branch 'develop' into enh/monte-carlo-callback
Lucas-Prates Nov 16, 2024
f19cb81
MNT: refactoring 'export_list' to 'data_collectors' dict of callbacks
Lucas-Prates Nov 22, 2024
f10cad0
TST: refactoring tests to new 'data_collector' input format (dict of …
Lucas-Prates Nov 22, 2024
1a09345
MNT: removing float check on 'set_processed_results'
Lucas-Prates Nov 22, 2024
1a51082
DOC: updating notebook example and class documentation after callback…
Lucas-Prates Nov 22, 2024
e4aead7
MNT: make black for notebook
Lucas-Prates Nov 22, 2024
6c477e3
DOC: update CHANGELOG
Lucas-Prates Nov 22, 2024
ac4d3af
Merge pull request #702 from emtee14/enh/monte-carlo-callback
Lucas-Prates Nov 22, 2024
0414249
DOC: RED Flight Example (#733)
LUCKIN13 Nov 23, 2024
09507ec
DOC: Faraday 2023 flight sim (#734)
LUCKIN13 Nov 23, 2024
a4d886a
DOC: fix formatting issues in examples index
Gui-FernandesBR Nov 23, 2024
c861c01
DOC: fix syntax error in examples index
Gui-FernandesBR Nov 23, 2024
ddf71f9
BUG: forecast and reanalysis models - move wind_speed to correct posi…
WilliamArmst Nov 23, 2024
1f3eefc
BUG: forecast and reanalysis models - update ECMWF weather model vari…
WilliamArmst Nov 23, 2024
0fe3d8d
allow stochastic fins with multiple fin sets
WilliamArmst Nov 24, 2024
a1709f9
MNT: Place filename save parameter to the end. (#739)
phmbressan Nov 30, 2024
ab6e440
DOC: improvements to developers documentation (#732)
Gui-FernandesBR Nov 30, 2024
e66f79f
DEV: move the citation.cff file back to root
Gui-FernandesBR Nov 30, 2024
42ef34f
BUG: update draw method calls to use keyword argument for filename
Gui-FernandesBR Nov 30, 2024
14712fc
DOC: fix wrong directive
Gui-FernandesBR Nov 30, 2024
36ff707
DOC: comment slow code execution
Gui-FernandesBR Nov 30, 2024
9761e74
Merge branch 'master' into develop
Gui-FernandesBR Nov 30, 2024
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ Attention: The newest changes should be on top -->

### Added

-
- ENH: Implement optional plot saving [#597](https://github.com/RocketPy-Team/RocketPy/pull/597)

### Changed

-

### Fixed

-
- BUG: Sideslip Angle and Damping Coefficient Calculation [#729](https://github.com/RocketPy-Team/RocketPy/pull/729)

## [v1.6.2] - 2024-11-08

Expand Down
39 changes: 39 additions & 0 deletions docs/user/first_simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,45 @@ Finally, the :meth:`rocketpy.Flight.export_data` method also provides a convenie
os.remove("calisto_flight_data.csv")


Saving and Storing Plots
------------------------

Here we show how to save the plots and drawings generated by RocketPy.
For instance, we can save our rocket drawing as a ``.png`` file:

.. jupyter-execute::

calisto.draw(filename="calisto_drawing.png")

Also, if you want to save a specific rocketpy plot, every RocketPy
attribute of type :class:`rocketpy.Function` is capable of saving its plot
as an image file. For example, we can save our rocket's speed plot and the
trajectory plot as ``.jpg`` files:

.. jupyter-execute::

test_flight.speed.plot(filename="speed_plot.jpg")
test_flight.plots.trajectory_3d(filename="trajectory_plot.jpg")

The supported file formats are ``.eps``, ``.jpg``, ``.jpeg``, ``.pdf``,
``.pgf``, ``.png``, ``.ps``, ``.raw``, ``.rgba``, ``.svg``, ``.svgz``,
``.tif``, ``.tiff`` and ``.webp``. More details on manipulating data and
results can be found in the :ref:`Function Class Usage <functionusage>`.

.. note::

The ``filename`` argument is optional. If not provided, the plot will be
shown instead. If the provided filename is in a directory that does not
exist, the directory will be created.

.. jupyter-execute::
:hide-code:
:hide-output:

os.remove("calisto_drawing.png")
os.remove("speed_plot.jpg")
os.remove("trajectory_plot.jpg")

Further Analysis
----------------

Expand Down
5 changes: 3 additions & 2 deletions docs/user/motors/tanks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ The predefined ``CylindricalTank`` class is easy to use and is defined as such:

.. note::
The ``spherical_caps`` parameter is optional and defaults to ``False``. If set
to ``True``, the tank will be defined as a cylinder with flat caps.
If True, the tank will have spherical caps.
to ``True``, the tank will have spherical caps at the top and bottom with the
same radius as the cylindrical part. If set to ``False``, the tank will
be defined as a cylinder with flat caps.

The predefined ``SphericalTank`` is defined with:

Expand Down
40 changes: 34 additions & 6 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
RBFInterpolator,
)

from ..plots.plot_helpers import show_or_save_plot

# Numpy 1.x compatibility,
# TODO: remove these lines when all dependencies support numpy>=2.0.0
if np.lib.NumpyVersion(np.__version__) >= "2.0.0b1":
Expand Down Expand Up @@ -1378,7 +1380,7 @@
)

# Define all presentation methods
def __call__(self, *args):
def __call__(self, *args, filename=None):
"""Plot the Function if no argument is given. If an
argument is given, return the value of the function at the desired
point.
Expand All @@ -1392,13 +1394,18 @@
evaluated at all points in the list and a list of floats will be
returned. If the function is N-D, N arguments must be given, each
one being an scalar or list.
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
ans : None, scalar, list
"""
if len(args) == 0:
return self.plot()
return self.plot(filename=filename)
else:
return self.get_value(*args)

Expand Down Expand Up @@ -1459,8 +1466,11 @@
Function.plot_2d if Function is 2-Dimensional and forward arguments
and key-word arguments."""
if isinstance(self, list):
# Extract filename from kwargs
filename = kwargs.get("filename", None)

Check warning on line 1470 in rocketpy/mathutils/function.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/mathutils/function.py#L1470

Added line #L1470 was not covered by tests

# Compare multiple plots
Function.compare_plots(self)
Function.compare_plots(self, filename)

Check warning on line 1473 in rocketpy/mathutils/function.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/mathutils/function.py#L1473

Added line #L1473 was not covered by tests
else:
if self.__dom_dim__ == 1:
self.plot_1d(*args, **kwargs)
Expand Down Expand Up @@ -1488,6 +1498,7 @@
force_points=False,
return_object=False,
equal_axis=False,
filename=None,
):
"""Plot 1-Dimensional Function, from a lower limit to an upper limit,
by sampling the Function several times in the interval. The title of
Expand Down Expand Up @@ -1518,6 +1529,11 @@
Setting force_points to True will plot all points, as a scatter, in
which the Function was evaluated in the dataset. Default value is
False.
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
Expand Down Expand Up @@ -1558,7 +1574,7 @@
plt.title(self.title)
plt.xlabel(self.__inputs__[0].title())
plt.ylabel(self.__outputs__[0].title())
plt.show()
show_or_save_plot(filename)
if return_object:
return fig, ax

Expand All @@ -1581,6 +1597,7 @@
disp_type="surface",
alpha=0.6,
cmap="viridis",
filename=None,
):
"""Plot 2-Dimensional Function, from a lower limit to an upper limit,
by sampling the Function several times in the interval. The title of
Expand Down Expand Up @@ -1620,6 +1637,11 @@
cmap : string, optional
Colormap of plotted graph, which can be any of the color maps
available in matplotlib. Default value is viridis.
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
Expand Down Expand Up @@ -1692,7 +1714,7 @@
axes.set_xlabel(self.__inputs__[0].title())
axes.set_ylabel(self.__inputs__[1].title())
axes.set_zlabel(self.__outputs__[0].title())
plt.show()
show_or_save_plot(filename)

@staticmethod
def compare_plots( # pylint: disable=too-many-statements
Expand All @@ -1707,6 +1729,7 @@
force_points=False,
return_object=False,
show=True,
filename=None,
):
"""Plots N 1-Dimensional Functions in the same plot, from a lower
limit to an upper limit, by sampling the Functions several times in
Expand Down Expand Up @@ -1751,6 +1774,11 @@
False.
show : bool, optional
If True, shows the plot. Default value is True.
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
Expand Down Expand Up @@ -1826,7 +1854,7 @@
plt.ylabel(ylabel)

if show:
plt.show()
show_or_save_plot(filename)

if return_object:
return fig, ax
Expand Down
29 changes: 16 additions & 13 deletions rocketpy/motors/hybrid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,19 @@
)
reset_funcified_methods(self)

def draw(self):
"""Draws a representation of the HybridMotor."""
self.plots.draw()

def info(self):
"""Prints out basic data about the Motor."""
self.prints.all()
self.plots.thrust()

def all_info(self):
"""Prints out all data and graphs available about the Motor."""
self.prints.all()
self.plots.all()
def draw(self, filename=None):
"""Draws a representation of the HybridMotor.

Parameters
----------
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
None
"""
self.plots.draw(filename)

Check warning on line 619 in rocketpy/motors/hybrid_motor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/hybrid_motor.py#L619

Added line #L619 was not covered by tests
26 changes: 12 additions & 14 deletions rocketpy/motors/liquid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,19 @@
self.positioned_tanks.append({"tank": tank, "position": position})
reset_funcified_methods(self)

def draw(self):
"""Draw a representation of the LiquidMotor."""
self.plots.draw()
def draw(self, filename=None):
"""Draw a representation of the LiquidMotor.

def info(self):
"""Prints out basic data about the Motor."""
self.prints.all()
self.plots.thrust()

def all_info(self):
"""Prints out all data and graphs available about the Motor.
Parameters
----------
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Return
------
Returns
-------
None
"""
self.prints.all()
self.plots.all()
self.plots.draw(filename)

Check warning on line 481 in rocketpy/motors/liquid_motor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/liquid_motor.py#L481

Added line #L481 was not covered by tests
17 changes: 14 additions & 3 deletions rocketpy/motors/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,15 +1083,26 @@ def get_attr_value(obj, attr_name, multiplier=1):
# Write last line
file.write(f"{self.thrust.source[-1, 0]:.4f} {0:.3f}\n")

def info(self):
def info(self, filename=None):
"""Prints out a summary of the data and graphs available about the
Motor.

Parameters
----------
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
None
"""
# Print motor details
self.prints.all()
self.plots.thrust()
self.plots.thrust(filename=filename)

@abstractmethod
def all_info(self):
"""Prints out all data and graphs available about the Motor."""
self.prints.all()
Expand Down
29 changes: 16 additions & 13 deletions rocketpy/motors/solid_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,16 +727,19 @@
def propellant_I_23(self):
return 0

def draw(self):
"""Draw a representation of the SolidMotor."""
self.plots.draw()

def info(self):
"""Prints out basic data about the SolidMotor."""
self.prints.all()
self.plots.thrust()

def all_info(self):
"""Prints out all data and graphs available about the SolidMotor."""
self.prints.all()
self.plots.all()
def draw(self, filename=None):
"""Draw a representation of the SolidMotor.

Parameters
----------
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
None
"""
self.plots.draw(filename)

Check warning on line 745 in rocketpy/motors/solid_motor.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/solid_motor.py#L745

Added line #L745 was not covered by tests
19 changes: 16 additions & 3 deletions rocketpy/motors/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,22 @@
elif (height < bottom_tolerance).any():
underfill_height_exception(name, height)

def draw(self):
"""Draws the tank geometry."""
self.plots.draw()
def draw(self, filename=None):
"""Draws the tank geometry.

Parameters
----------
filename : str | None, optional
The path the plot should be saved to. By default None, in which case
the plot will be shown instead of saved. Supported file endings are:
eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff
and webp (these are the formats supported by matplotlib).

Returns
-------
None
"""
self.plots.draw(filename)

Check warning on line 494 in rocketpy/motors/tank.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/motors/tank.py#L494

Added line #L494 was not covered by tests


class MassFlowRateBasedTank(Tank):
Expand Down
Loading
Loading