From cde68f9fb252ad217d0413db4ca286ab7636b191 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Mon, 16 Jun 2025 23:16:00 -0300 Subject: [PATCH 01/10] MNT: update code and remove deprecated functions --- rocketpy/environment/environment.py | 95 +--------------------- rocketpy/motors/motor.py | 2 +- rocketpy/plots/monte_carlo_plots.py | 4 +- rocketpy/rocket/aero_surface/air_brakes.py | 3 +- rocketpy/simulation/flight.py | 32 ++------ rocketpy/utilities.py | 90 -------------------- tests/acceptance/test_bella_lui_rocket.py | 1 - tests/unit/test_environment.py | 5 +- 8 files changed, 16 insertions(+), 216 deletions(-) diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index a0a8c4238..97d79d988 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -451,7 +451,7 @@ def __initialize_utm_coordinates(self): self.initial_utm_letter, self.initial_hemisphere, self.initial_ew, - ) = self.geodesic_to_utm( + ) = geodesic_to_utm_tools( lat=self.latitude, lon=self.longitude, flattening=self.ellipsoid.flattening, @@ -2523,98 +2523,7 @@ def set_earth_geometry(self, datum): f"the following recognized datum: {available_datums}" ) from e - # Auxiliary functions - Geodesic Coordinates - - @staticmethod - def geodesic_to_utm( - lat, lon, semi_major_axis=6378137.0, flattening=1 / 298.257223563 - ): - """Function which converts geodetic coordinates, i.e. lat/lon, to UTM - projection coordinates. Can be used only for latitudes between -80.00° - and 84.00° - - Parameters - ---------- - lat : float - The latitude coordinates of the point of analysis, must be contained - between -80.00° and 84.00° - lon : float - The longitude coordinates of the point of analysis, must be - contained between -180.00° and 180.00° - semi_major_axis : float - The semi-major axis of the ellipsoid used to represent the Earth, - must be given in meters (default is 6,378,137.0 m, which corresponds - to the WGS84 ellipsoid) - flattening : float - The flattening of the ellipsoid used to represent the Earth, usually - between 1/250 and 1/150 (default is 1/298.257223563, which - corresponds to the WGS84 ellipsoid) - - Returns - ------- - x : float - East coordinate, always positive - y : float - North coordinate, always positive - utm_zone : int - The number of the UTM zone of the point of analysis, can vary - between 1 and 60 - utm_letter : string - The letter of the UTM zone of the point of analysis, can vary - between C and X, omitting the letters "I" and "O" - hemis : string - Returns "S" for southern hemisphere and "N" for Northern hemisphere - EW : string - Returns "W" for western hemisphere and "E" for eastern hemisphere - """ - warnings.warn( - "This function is deprecated and will be removed in v1.10.0. " - "Please use the new method `tools.geodesic_to_utm` instead.", - DeprecationWarning, - ) - return geodesic_to_utm_tools(lat, lon, semi_major_axis, flattening) - - @staticmethod - def utm_to_geodesic( - x, y, utm_zone, hemis, semi_major_axis=6378137.0, flattening=1 / 298.257223563 - ): - """Function to convert UTM coordinates to geodesic coordinates - (i.e. latitude and longitude). - - Parameters - ---------- - x : float - East UTM coordinate in meters - y : float - North UTM coordinate in meters - utm_zone : int - The number of the UTM zone of the point of analysis, can vary - between 1 and 60 - hemis : string - Equals to "S" for southern hemisphere and "N" for Northern - hemisphere - semi_major_axis : float - The semi-major axis of the ellipsoid used to represent the Earth, - must be given in meters (default is 6,378,137.0 m, which corresponds - to the WGS84 ellipsoid) - flattening : float - The flattening of the ellipsoid used to represent the Earth, usually - between 1/250 and 1/150 (default is 1/298.257223563, which - corresponds to the WGS84 ellipsoid) - - Returns - ------- - lat : float - latitude of the analyzed point - lon : float - latitude of the analyzed point - """ - warnings.warn( - "This function is deprecated and will be removed in v1.10.0. " - "Please use the new method `tools.utm_to_geodesic` instead.", - DeprecationWarning, - ) - return utm_to_geodesic_tools(x, y, utm_zone, hemis, semi_major_axis, flattening) + # Auxiliary functions @staticmethod def calculate_earth_radius( diff --git a/rocketpy/motors/motor.py b/rocketpy/motors/motor.py index 7178cdcf5..1cb659d4f 100644 --- a/rocketpy/motors/motor.py +++ b/rocketpy/motors/motor.py @@ -1151,7 +1151,7 @@ def vacuum_thrust(self): Returns ------- vacuum_thrust : Function - The rocket's thrust in a vaccum. + The rocket's thrust in a vacuum. """ if self.reference_pressure is None: warnings.warn( diff --git a/rocketpy/plots/monte_carlo_plots.py b/rocketpy/plots/monte_carlo_plots.py index cfb865c5f..a2af1f5db 100644 --- a/rocketpy/plots/monte_carlo_plots.py +++ b/rocketpy/plots/monte_carlo_plots.py @@ -183,7 +183,7 @@ def all(self, keys=None): ax2 = fig.add_subplot(gs[1]) # Plot boxplot - ax1.boxplot(self.monte_carlo.results[key], vert=False) + ax1.boxplot(self.monte_carlo.results[key], orientation="horizontal") ax1.set_title(f"Box Plot of {key}") ax1.set_yticks([]) @@ -226,7 +226,7 @@ def plot_comparison(self, other_monte_carlo): # Plot boxplot bp = ax1.boxplot( [other_monte_carlo.results[key], self.monte_carlo.results[key]], - vert=False, + orientation="horizontal", tick_labels=["Other", "Original"], patch_artist=True, ) diff --git a/rocketpy/rocket/aero_surface/air_brakes.py b/rocketpy/rocket/aero_surface/air_brakes.py index ee4830808..d0eb733d5 100644 --- a/rocketpy/rocket/aero_surface/air_brakes.py +++ b/rocketpy/rocket/aero_surface/air_brakes.py @@ -131,7 +131,8 @@ def deployment_level(self, value): warnings.warn( f"Deployment level of {self.name} is smaller than 0 or " + "larger than 1. Extrapolation for the drag coefficient " - + "curve will be used." + + "curve will be used.", + UserWarning, ) self._deployment_level = value diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index ce728dafe..914300a1d 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -3055,14 +3055,16 @@ def __calculate_rail_button_forces(self): # TODO: complex method. null_force = Function(0) if self.out_of_rail_time_index == 0: # No rail phase, no rail button forces warnings.warn( - "Trying to calculate rail button forces without a rail phase defined." - + "The rail button forces will be set to zero." + "Trying to calculate rail button forces without a rail phase defined. " + + "The rail button forces will be set to zero.", + UserWarning, ) return null_force, null_force, null_force, null_force if len(self.rocket.rail_buttons) == 0: warnings.warn( - "Trying to calculate rail button forces without rail buttons defined." - + "The rail button forces will be set to zero." + "Trying to calculate rail button forces without rail buttons defined. " + + "The rail button forces will be set to zero.", + UserWarning, ) return null_force, null_force, null_force, null_force @@ -3174,28 +3176,6 @@ def __evaluate_post_process(self): return np.array(self.__post_processed_variables) - def post_process(self, interpolation="spline", extrapolation="natural"): - """This method is **deprecated** and is only kept here for backwards - compatibility. All attributes that need to be post processed are - computed just in time. - - Post-process all Flight information produced during - simulation. Includes the calculation of maximum values, - calculation of secondary values such as energy and conversion - of lists to Function objects to facilitate plotting. - - Returns - ------- - None - """ - # pylint: disable=unused-argument - warnings.warn( - "The method post_process is deprecated and will be removed in v1.10. " - "All attributes that need to be post processed are computed just in time.", - DeprecationWarning, - ) - self.post_processed = True - def calculate_stall_wind_velocity(self, stall_angle): # TODO: move to utilities """Function to calculate the maximum wind velocity before the angle of attack exceeds a desired angle, at the instant of departing rail launch. diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index 3ed81df41..c8d32e6af 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -444,96 +444,6 @@ def _flutter_prints( print(f"Altitude of minimum Safety Factor: {altitude_min_sf:.3f} m (AGL)\n") -def create_dispersion_dictionary(filename): # pragma: no cover - """Creates a dictionary with the rocket data provided by a .csv file. - File should be organized in four columns: attribute_class, parameter_name, - mean_value, standard_deviation. The first row should be the header. - It is advised to use ";" as separator, but "," should work on most of cases. - The "," separator might cause problems if the data set contains lists where - the items are separated by commas. - - Parameters - ---------- - filename : string - String with the path to the .csv file. The file should follow the - following structure: - - .. code-block:: - - attribute_class; parameter_name; mean_value; standard_deviation; - - environment; ensemble_member; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];; - - motor; impulse; 1415.15; 35.3; - - motor; burn_time; 5.274; 1; - - motor; nozzle_radius; 0.021642; 0.0005; - - motor; throat_radius; 0.008; 0.0005; - - motor; grain_separation; 0.006; 0.001; - - motor; grain_density; 1707; 50; - - Returns - ------- - dictionary - Dictionary with all rocket data to be used in dispersion analysis. The - dictionary will follow the following structure: - - .. code-block:: python - - analysis_parameters = { - 'environment': { - 'ensemble_member': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - }, - 'motor': { - 'impulse': (1415.15, 35.3), - 'burn_time': (5.274, 1), - 'nozzle_radius': (0.021642, 0.0005), - 'throat_radius': (0.008, 0.0005), - 'grain_separation': (0.006, 0.001), - 'grain_density': (1707, 50), - } - } - """ - warnings.warn( - "This function is deprecated and will be removed in v1.10.0.", - DeprecationWarning, - ) - try: - file = np.genfromtxt( - filename, usecols=(1, 2, 3), skip_header=1, delimiter=";", dtype=str - ) - except ValueError: - warnings.warn( - "Error caught: the recommended delimiter is ';'. If using ',' " - "instead, be aware that some resources might not work as " - "expected if your data set contains lists where the items are " - "separated by commas. Please consider changing the delimiter to " - "';' if that is the case." - ) - warnings.warn(traceback.format_exc()) - file = np.genfromtxt( - filename, usecols=(1, 2, 3), skip_header=1, delimiter=",", dtype=str - ) - analysis_parameters = {} - for row in file: - if row[0] != "": - if row[2] == "": - try: - analysis_parameters[row[0].strip()] = float(row[1]) - except ValueError: - analysis_parameters[row[0].strip()] = ast.literal_eval(row[1]) - else: - try: - analysis_parameters[row[0].strip()] = (float(row[1]), float(row[2])) - except ValueError: - analysis_parameters[row[0].strip()] = "" - return analysis_parameters - - def apogee_by_mass(flight, min_mass, max_mass, points=10, plot=True): """Returns a Function object that estimates the apogee of a rocket given its mass (no motor). The function will use the rocket's mass as the diff --git a/tests/acceptance/test_bella_lui_rocket.py b/tests/acceptance/test_bella_lui_rocket.py index 76f2b4fde..a67547780 100644 --- a/tests/acceptance/test_bella_lui_rocket.py +++ b/tests/acceptance/test_bella_lui_rocket.py @@ -182,7 +182,6 @@ def drogue_trigger(p, h, y): inclination=parameters.get("inclination")[0], heading=parameters.get("heading")[0], ) - test_flight.post_process() # Comparison with Real Data flight_data = np.loadtxt( diff --git a/tests/unit/test_environment.py b/tests/unit/test_environment.py index 714470a40..6ad3e51db 100644 --- a/tests/unit/test_environment.py +++ b/tests/unit/test_environment.py @@ -6,6 +6,7 @@ import pytz from rocketpy import Environment +from rocketpy.environment.tools import geodesic_to_utm, utm_to_geodesic @pytest.mark.parametrize( @@ -78,7 +79,7 @@ def test_geodesic_coordinate_geodesic_to_utm_converts_coordinate(): utm_letter, north_south_hemis, east_west_hemis, - ) = Environment.geodesic_to_utm( + ) = geodesic_to_utm( lat=32.990254, lon=-106.974998, semi_major_axis=6378137.0, # WGS84 @@ -98,7 +99,7 @@ class and checks the conversion results from UTM to geodesic coordinates. """ - lat, lon = Environment.utm_to_geodesic( + lat, lon = utm_to_geodesic( x=315468.64, y=3651938.65, utm_zone=13, From 4c96ce86fd0bbe24dd5ca759ce1a14da3552c845 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 19 Jun 2025 20:49:06 -0300 Subject: [PATCH 02/10] MNT: simplify geodesic_to_utm import and usage in Environment class --- rocketpy/environment/environment.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rocketpy/environment/environment.py b/rocketpy/environment/environment.py index 97d79d988..06171d600 100644 --- a/rocketpy/environment/environment.py +++ b/rocketpy/environment/environment.py @@ -27,6 +27,7 @@ find_latitude_index, find_longitude_index, find_time_index, + geodesic_to_utm, get_elevation_data_from_dataset, get_final_date_from_time_array, get_initial_date_from_time_array, @@ -34,8 +35,6 @@ get_pressure_levels_from_file, mask_and_clean_dataset, ) -from rocketpy.environment.tools import geodesic_to_utm as geodesic_to_utm_tools -from rocketpy.environment.tools import utm_to_geodesic as utm_to_geodesic_tools from rocketpy.environment.weather_model_mapping import WeatherModelMapping from rocketpy.mathutils.function import NUMERICAL_TYPES, Function, funcify_method from rocketpy.plots.environment_plots import _EnvironmentPlots @@ -451,7 +450,7 @@ def __initialize_utm_coordinates(self): self.initial_utm_letter, self.initial_hemisphere, self.initial_ew, - ) = geodesic_to_utm_tools( + ) = geodesic_to_utm( lat=self.latitude, lon=self.longitude, flattening=self.ellipsoid.flattening, From cb62905796a41347835f43ce0b99495b80c3d1cd Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 19 Jun 2025 20:49:13 -0300 Subject: [PATCH 03/10] MNT: update CHANGELOG to fix deprecations and warnings --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3f1217db..dce368bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ Attention: The newest changes should be on top --> - ENH: _MotorPrints inheritance - issue #460 [#828](https://github.com/RocketPy-Team/RocketPy/pull/828) +- MNT: fix deprecations and warnings [#829](https://github.com/RocketPy-Team/RocketPy/pull/829) + ### Fixed @@ -45,7 +47,7 @@ Attention: The newest changes should be on top --> ### Added - ENH: Support for ND arithmetic in Function class. [#810] (https://github.com/RocketPy-Team/RocketPy/pull/810) - ENH: allow users to provide custom samplers [#803](https://github.com/RocketPy-Team/RocketPy/pull/803) -- ENH: Implement Multivariate Rejection Sampling (MRS) [#738] (https://github.com/RocketPy-Team/RocketPy/pull/738) +- ENH: Implement Multivariate Rejection Sampling (MRS) [#738] (https://github.com/RocketPy-Team/RocketPy/pull/738) - ENH: Create a rocketpy file to store flight simulations [#800](https://github.com/RocketPy-Team/RocketPy/pull/800) - ENH: Support for the RSE file format has been added to the library [#798](https://github.com/RocketPy-Team/RocketPy/pull/798) - ENH: Introduce Net Thrust with pressure corrections [#789](https://github.com/RocketPy-Team/RocketPy/pull/789) From 007b5ed62223ca11cbdbf4c977f1624a25da5208 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 19 Jun 2025 21:01:18 -0300 Subject: [PATCH 04/10] make lint --- rocketpy/utilities.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rocketpy/utilities.py b/rocketpy/utilities.py index c8d32e6af..9ec707ffe 100644 --- a/rocketpy/utilities.py +++ b/rocketpy/utilities.py @@ -1,8 +1,6 @@ -import ast import inspect import json import os -import traceback import warnings from datetime import date from importlib.metadata import version From 733ec1d92b27b9e214e26737e98e08791c9679b5 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 19 Jun 2025 21:06:01 -0300 Subject: [PATCH 05/10] MNT: remove unused post_processed attribute from Flight class --- rocketpy/simulation/flight.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 914300a1d..7d2693a0a 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -155,8 +155,6 @@ class Flight: Current integration time. Flight.y : list Current integration state vector u. - Flight.post_processed : bool - Defines if solution data has been post processed. Flight.initial_solution : list List defines initial condition - [tInit, x_init, y_init, z_init, vx_init, vy_init, vz_init, e0_init, e1_init, @@ -1102,7 +1100,6 @@ def __init_solution_monitors(self): self.impact_velocity = 0 self.impact_state = np.array([0]) self.parachute_events = [] - self.post_processed = False self.__post_processed_variables = [] def __init_flight_state(self): From 67e0deb00ad3556f1757d38244cfd71738bc4a70 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 19 Jun 2025 21:15:56 -0300 Subject: [PATCH 06/10] MNT: update matplotlib version to 3.8.3 in requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 68aebe503..5d60fdad1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy>=1.13 scipy>=1.0 -matplotlib>=3.0 +matplotlib>=3.8.3 # Released Feb 14th 2024 netCDF4>=1.6.4 requests pytz From f0d2170b07137e2836636cc2e73df91f711f52be Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 20 Jun 2025 06:32:18 -0300 Subject: [PATCH 07/10] MNT: update matplotlib version to 3.10.0 in requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5d60fdad1..da2905bac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy>=1.13 scipy>=1.0 -matplotlib>=3.8.3 # Released Feb 14th 2024 +matplotlib>=3.10.0 # Released Dec 14th 2024 netCDF4>=1.6.4 requests pytz From 3ac9492f0e209d19e5c1ce6b0377908ed45e852f Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 20 Jun 2025 06:39:49 -0300 Subject: [PATCH 08/10] MNT: downgrade matplotlib version to 3.9.0 in requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index da2905bac..61a594320 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy>=1.13 scipy>=1.0 -matplotlib>=3.10.0 # Released Dec 14th 2024 +matplotlib>=3.9.0 # Released May 15th 2024 netCDF4>=1.6.4 requests pytz From d421db18693ddced88ad37639e7fc3cacfba9fd1 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 20 Jun 2025 06:39:56 -0300 Subject: [PATCH 09/10] MNT: change boxplot orientation to horizontal for compatibility with future Python versions --- rocketpy/plots/monte_carlo_plots.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rocketpy/plots/monte_carlo_plots.py b/rocketpy/plots/monte_carlo_plots.py index a2af1f5db..556ffe6f1 100644 --- a/rocketpy/plots/monte_carlo_plots.py +++ b/rocketpy/plots/monte_carlo_plots.py @@ -183,7 +183,8 @@ def all(self, keys=None): ax2 = fig.add_subplot(gs[1]) # Plot boxplot - ax1.boxplot(self.monte_carlo.results[key], orientation="horizontal") + # TODO: changes vert to orientation="horizontal" when support for Py3.9 ends + ax1.boxplot(self.monte_carlo.results[key], vert=False) ax1.set_title(f"Box Plot of {key}") ax1.set_yticks([]) From b54c87fccbb0e8c81cd6bd253eaff495fd173712 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Fri, 20 Jun 2025 06:41:17 -0300 Subject: [PATCH 10/10] MNT: change boxplot orientation from horizontal to vertical for consistency --- rocketpy/plots/monte_carlo_plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/plots/monte_carlo_plots.py b/rocketpy/plots/monte_carlo_plots.py index 556ffe6f1..114858252 100644 --- a/rocketpy/plots/monte_carlo_plots.py +++ b/rocketpy/plots/monte_carlo_plots.py @@ -227,7 +227,7 @@ def plot_comparison(self, other_monte_carlo): # Plot boxplot bp = ax1.boxplot( [other_monte_carlo.results[key], self.monte_carlo.results[key]], - orientation="horizontal", + vert=False, tick_labels=["Other", "Original"], patch_artist=True, )