Skip to content

Commit 5c75298

Browse files
Gui-FernandesBRaZira371
authored andcommitted
MNT: fix deprecations and warnings (RocketPy-Team#829)
* MNT: update code and remove deprecated functions * MNT: simplify geodesic_to_utm import and usage in Environment class * MNT: update CHANGELOG to fix deprecations and warnings * make lint * MNT: remove unused post_processed attribute from Flight class * MNT: update matplotlib version to 3.8.3 in requirements.txt * MNT: update matplotlib version to 3.10.0 in requirements.txt * MNT: downgrade matplotlib version to 3.9.0 in requirements.txt * MNT: change boxplot orientation to horizontal for compatibility with future Python versions * MNT: change boxplot orientation from horizontal to vertical for consistency
1 parent 981dda5 commit 5c75298

File tree

10 files changed

+20
-223
lines changed

10 files changed

+20
-223
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Attention: The newest changes should be on top -->
3737

3838
- ENH: _MotorPrints inheritance - issue #460 [#828](https://github.com/RocketPy-Team/RocketPy/pull/828)
3939

40+
- MNT: fix deprecations and warnings [#829](https://github.com/RocketPy-Team/RocketPy/pull/829)
41+
4042
### Fixed
4143

4244

@@ -45,7 +47,7 @@ Attention: The newest changes should be on top -->
4547
### Added
4648
- ENH: Support for ND arithmetic in Function class. [#810] (https://github.com/RocketPy-Team/RocketPy/pull/810)
4749
- ENH: allow users to provide custom samplers [#803](https://github.com/RocketPy-Team/RocketPy/pull/803)
48-
- ENH: Implement Multivariate Rejection Sampling (MRS) [#738] (https://github.com/RocketPy-Team/RocketPy/pull/738)
50+
- ENH: Implement Multivariate Rejection Sampling (MRS) [#738] (https://github.com/RocketPy-Team/RocketPy/pull/738)
4951
- ENH: Create a rocketpy file to store flight simulations [#800](https://github.com/RocketPy-Team/RocketPy/pull/800)
5052
- ENH: Support for the RSE file format has been added to the library [#798](https://github.com/RocketPy-Team/RocketPy/pull/798)
5153
- ENH: Introduce Net Thrust with pressure corrections [#789](https://github.com/RocketPy-Team/RocketPy/pull/789)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy>=1.13
22
scipy>=1.0
3-
matplotlib>=3.0
3+
matplotlib>=3.9.0 # Released May 15th 2024
44
netCDF4>=1.6.4
55
requests
66
pytz

rocketpy/environment/environment.py

Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
find_latitude_index,
2828
find_longitude_index,
2929
find_time_index,
30+
geodesic_to_utm,
3031
get_elevation_data_from_dataset,
3132
get_final_date_from_time_array,
3233
get_initial_date_from_time_array,
3334
get_interval_date_from_time_array,
3435
get_pressure_levels_from_file,
3536
mask_and_clean_dataset,
3637
)
37-
from rocketpy.environment.tools import geodesic_to_utm as geodesic_to_utm_tools
38-
from rocketpy.environment.tools import utm_to_geodesic as utm_to_geodesic_tools
3938
from rocketpy.environment.weather_model_mapping import WeatherModelMapping
4039
from rocketpy.mathutils.function import NUMERICAL_TYPES, Function, funcify_method
4140
from rocketpy.plots.environment_plots import _EnvironmentPlots
@@ -451,7 +450,7 @@ def __initialize_utm_coordinates(self):
451450
self.initial_utm_letter,
452451
self.initial_hemisphere,
453452
self.initial_ew,
454-
) = self.geodesic_to_utm(
453+
) = geodesic_to_utm(
455454
lat=self.latitude,
456455
lon=self.longitude,
457456
flattening=self.ellipsoid.flattening,
@@ -2523,98 +2522,7 @@ def set_earth_geometry(self, datum):
25232522
f"the following recognized datum: {available_datums}"
25242523
) from e
25252524

2526-
# Auxiliary functions - Geodesic Coordinates
2527-
2528-
@staticmethod
2529-
def geodesic_to_utm(
2530-
lat, lon, semi_major_axis=6378137.0, flattening=1 / 298.257223563
2531-
):
2532-
"""Function which converts geodetic coordinates, i.e. lat/lon, to UTM
2533-
projection coordinates. Can be used only for latitudes between -80.00°
2534-
and 84.00°
2535-
2536-
Parameters
2537-
----------
2538-
lat : float
2539-
The latitude coordinates of the point of analysis, must be contained
2540-
between -80.00° and 84.00°
2541-
lon : float
2542-
The longitude coordinates of the point of analysis, must be
2543-
contained between -180.00° and 180.00°
2544-
semi_major_axis : float
2545-
The semi-major axis of the ellipsoid used to represent the Earth,
2546-
must be given in meters (default is 6,378,137.0 m, which corresponds
2547-
to the WGS84 ellipsoid)
2548-
flattening : float
2549-
The flattening of the ellipsoid used to represent the Earth, usually
2550-
between 1/250 and 1/150 (default is 1/298.257223563, which
2551-
corresponds to the WGS84 ellipsoid)
2552-
2553-
Returns
2554-
-------
2555-
x : float
2556-
East coordinate, always positive
2557-
y : float
2558-
North coordinate, always positive
2559-
utm_zone : int
2560-
The number of the UTM zone of the point of analysis, can vary
2561-
between 1 and 60
2562-
utm_letter : string
2563-
The letter of the UTM zone of the point of analysis, can vary
2564-
between C and X, omitting the letters "I" and "O"
2565-
hemis : string
2566-
Returns "S" for southern hemisphere and "N" for Northern hemisphere
2567-
EW : string
2568-
Returns "W" for western hemisphere and "E" for eastern hemisphere
2569-
"""
2570-
warnings.warn(
2571-
"This function is deprecated and will be removed in v1.10.0. "
2572-
"Please use the new method `tools.geodesic_to_utm` instead.",
2573-
DeprecationWarning,
2574-
)
2575-
return geodesic_to_utm_tools(lat, lon, semi_major_axis, flattening)
2576-
2577-
@staticmethod
2578-
def utm_to_geodesic(
2579-
x, y, utm_zone, hemis, semi_major_axis=6378137.0, flattening=1 / 298.257223563
2580-
):
2581-
"""Function to convert UTM coordinates to geodesic coordinates
2582-
(i.e. latitude and longitude).
2583-
2584-
Parameters
2585-
----------
2586-
x : float
2587-
East UTM coordinate in meters
2588-
y : float
2589-
North UTM coordinate in meters
2590-
utm_zone : int
2591-
The number of the UTM zone of the point of analysis, can vary
2592-
between 1 and 60
2593-
hemis : string
2594-
Equals to "S" for southern hemisphere and "N" for Northern
2595-
hemisphere
2596-
semi_major_axis : float
2597-
The semi-major axis of the ellipsoid used to represent the Earth,
2598-
must be given in meters (default is 6,378,137.0 m, which corresponds
2599-
to the WGS84 ellipsoid)
2600-
flattening : float
2601-
The flattening of the ellipsoid used to represent the Earth, usually
2602-
between 1/250 and 1/150 (default is 1/298.257223563, which
2603-
corresponds to the WGS84 ellipsoid)
2604-
2605-
Returns
2606-
-------
2607-
lat : float
2608-
latitude of the analyzed point
2609-
lon : float
2610-
latitude of the analyzed point
2611-
"""
2612-
warnings.warn(
2613-
"This function is deprecated and will be removed in v1.10.0. "
2614-
"Please use the new method `tools.utm_to_geodesic` instead.",
2615-
DeprecationWarning,
2616-
)
2617-
return utm_to_geodesic_tools(x, y, utm_zone, hemis, semi_major_axis, flattening)
2525+
# Auxiliary functions
26182526

26192527
@staticmethod
26202528
def calculate_earth_radius(

rocketpy/motors/motor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ def vacuum_thrust(self):
11511151
Returns
11521152
-------
11531153
vacuum_thrust : Function
1154-
The rocket's thrust in a vaccum.
1154+
The rocket's thrust in a vacuum.
11551155
"""
11561156
if self.reference_pressure is None:
11571157
warnings.warn(

rocketpy/plots/monte_carlo_plots.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def all(self, keys=None):
183183
ax2 = fig.add_subplot(gs[1])
184184

185185
# Plot boxplot
186+
# TODO: changes vert to orientation="horizontal" when support for Py3.9 ends
186187
ax1.boxplot(self.monte_carlo.results[key], vert=False)
187188
ax1.set_title(f"Box Plot of {key}")
188189
ax1.set_yticks([])

rocketpy/rocket/aero_surface/air_brakes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def deployment_level(self, value):
131131
warnings.warn(
132132
f"Deployment level of {self.name} is smaller than 0 or "
133133
+ "larger than 1. Extrapolation for the drag coefficient "
134-
+ "curve will be used."
134+
+ "curve will be used.",
135+
UserWarning,
135136
)
136137
self._deployment_level = value
137138

rocketpy/simulation/flight.py

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ class Flight:
155155
Current integration time.
156156
Flight.y : list
157157
Current integration state vector u.
158-
Flight.post_processed : bool
159-
Defines if solution data has been post processed.
160158
Flight.initial_solution : list
161159
List defines initial condition - [tInit, x_init,
162160
y_init, z_init, vx_init, vy_init, vz_init, e0_init, e1_init,
@@ -1104,7 +1102,6 @@ def __init_solution_monitors(self):
11041102
self.impact_velocity = 0
11051103
self.impact_state = np.array([0])
11061104
self.parachute_events = []
1107-
self.post_processed = False
11081105
self.__post_processed_variables = []
11091106

11101107
def __init_flight_state(self):
@@ -3080,14 +3077,16 @@ def __calculate_rail_button_forces(self): # TODO: complex method.
30803077
null_force = Function(0)
30813078
if self.out_of_rail_time_index == 0: # No rail phase, no rail button forces
30823079
warnings.warn(
3083-
"Trying to calculate rail button forces without a rail phase defined."
3084-
+ "The rail button forces will be set to zero."
3080+
"Trying to calculate rail button forces without a rail phase defined. "
3081+
+ "The rail button forces will be set to zero.",
3082+
UserWarning,
30853083
)
30863084
return null_force, null_force, null_force, null_force
30873085
if len(self.rocket.rail_buttons) == 0:
30883086
warnings.warn(
3089-
"Trying to calculate rail button forces without rail buttons defined."
3090-
+ "The rail button forces will be set to zero."
3087+
"Trying to calculate rail button forces without rail buttons defined. "
3088+
+ "The rail button forces will be set to zero.",
3089+
UserWarning,
30913090
)
30923091
return null_force, null_force, null_force, null_force
30933092

@@ -3199,28 +3198,6 @@ def __evaluate_post_process(self):
31993198

32003199
return np.array(self.__post_processed_variables)
32013200

3202-
def post_process(self, interpolation="spline", extrapolation="natural"):
3203-
"""This method is **deprecated** and is only kept here for backwards
3204-
compatibility. All attributes that need to be post processed are
3205-
computed just in time.
3206-
3207-
Post-process all Flight information produced during
3208-
simulation. Includes the calculation of maximum values,
3209-
calculation of secondary values such as energy and conversion
3210-
of lists to Function objects to facilitate plotting.
3211-
3212-
Returns
3213-
-------
3214-
None
3215-
"""
3216-
# pylint: disable=unused-argument
3217-
warnings.warn(
3218-
"The method post_process is deprecated and will be removed in v1.10. "
3219-
"All attributes that need to be post processed are computed just in time.",
3220-
DeprecationWarning,
3221-
)
3222-
self.post_processed = True
3223-
32243201
def calculate_stall_wind_velocity(self, stall_angle): # TODO: move to utilities
32253202
"""Function to calculate the maximum wind velocity before the angle of
32263203
attack exceeds a desired angle, at the instant of departing rail launch.

rocketpy/utilities.py

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import ast
21
import inspect
32
import json
43
import os
5-
import traceback
64
import warnings
75
from datetime import date
86
from importlib.metadata import version
@@ -444,96 +442,6 @@ def _flutter_prints(
444442
print(f"Altitude of minimum Safety Factor: {altitude_min_sf:.3f} m (AGL)\n")
445443

446444

447-
def create_dispersion_dictionary(filename): # pragma: no cover
448-
"""Creates a dictionary with the rocket data provided by a .csv file.
449-
File should be organized in four columns: attribute_class, parameter_name,
450-
mean_value, standard_deviation. The first row should be the header.
451-
It is advised to use ";" as separator, but "," should work on most of cases.
452-
The "," separator might cause problems if the data set contains lists where
453-
the items are separated by commas.
454-
455-
Parameters
456-
----------
457-
filename : string
458-
String with the path to the .csv file. The file should follow the
459-
following structure:
460-
461-
.. code-block::
462-
463-
attribute_class; parameter_name; mean_value; standard_deviation;
464-
465-
environment; ensemble_member; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];;
466-
467-
motor; impulse; 1415.15; 35.3;
468-
469-
motor; burn_time; 5.274; 1;
470-
471-
motor; nozzle_radius; 0.021642; 0.0005;
472-
473-
motor; throat_radius; 0.008; 0.0005;
474-
475-
motor; grain_separation; 0.006; 0.001;
476-
477-
motor; grain_density; 1707; 50;
478-
479-
Returns
480-
-------
481-
dictionary
482-
Dictionary with all rocket data to be used in dispersion analysis. The
483-
dictionary will follow the following structure:
484-
485-
.. code-block:: python
486-
487-
analysis_parameters = {
488-
'environment': {
489-
'ensemble_member': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
490-
},
491-
'motor': {
492-
'impulse': (1415.15, 35.3),
493-
'burn_time': (5.274, 1),
494-
'nozzle_radius': (0.021642, 0.0005),
495-
'throat_radius': (0.008, 0.0005),
496-
'grain_separation': (0.006, 0.001),
497-
'grain_density': (1707, 50),
498-
}
499-
}
500-
"""
501-
warnings.warn(
502-
"This function is deprecated and will be removed in v1.10.0.",
503-
DeprecationWarning,
504-
)
505-
try:
506-
file = np.genfromtxt(
507-
filename, usecols=(1, 2, 3), skip_header=1, delimiter=";", dtype=str
508-
)
509-
except ValueError:
510-
warnings.warn(
511-
"Error caught: the recommended delimiter is ';'. If using ',' "
512-
"instead, be aware that some resources might not work as "
513-
"expected if your data set contains lists where the items are "
514-
"separated by commas. Please consider changing the delimiter to "
515-
"';' if that is the case."
516-
)
517-
warnings.warn(traceback.format_exc())
518-
file = np.genfromtxt(
519-
filename, usecols=(1, 2, 3), skip_header=1, delimiter=",", dtype=str
520-
)
521-
analysis_parameters = {}
522-
for row in file:
523-
if row[0] != "":
524-
if row[2] == "":
525-
try:
526-
analysis_parameters[row[0].strip()] = float(row[1])
527-
except ValueError:
528-
analysis_parameters[row[0].strip()] = ast.literal_eval(row[1])
529-
else:
530-
try:
531-
analysis_parameters[row[0].strip()] = (float(row[1]), float(row[2]))
532-
except ValueError:
533-
analysis_parameters[row[0].strip()] = ""
534-
return analysis_parameters
535-
536-
537445
def apogee_by_mass(flight, min_mass, max_mass, points=10, plot=True):
538446
"""Returns a Function object that estimates the apogee of a rocket given
539447
its mass (no motor). The function will use the rocket's mass as the

tests/acceptance/test_bella_lui_rocket.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def drogue_trigger(p, h, y):
182182
inclination=parameters.get("inclination")[0],
183183
heading=parameters.get("heading")[0],
184184
)
185-
test_flight.post_process()
186185

187186
# Comparison with Real Data
188187
flight_data = np.loadtxt(

tests/unit/test_environment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytz
77

88
from rocketpy import Environment
9+
from rocketpy.environment.tools import geodesic_to_utm, utm_to_geodesic
910

1011

1112
@pytest.mark.parametrize(
@@ -78,7 +79,7 @@ def test_geodesic_coordinate_geodesic_to_utm_converts_coordinate():
7879
utm_letter,
7980
north_south_hemis,
8081
east_west_hemis,
81-
) = Environment.geodesic_to_utm(
82+
) = geodesic_to_utm(
8283
lat=32.990254,
8384
lon=-106.974998,
8485
semi_major_axis=6378137.0, # WGS84
@@ -98,7 +99,7 @@ class and checks the conversion results from UTM to geodesic
9899
coordinates.
99100
"""
100101

101-
lat, lon = Environment.utm_to_geodesic(
102+
lat, lon = utm_to_geodesic(
102103
x=315468.64,
103104
y=3651938.65,
104105
utm_zone=13,

0 commit comments

Comments
 (0)