Skip to content

Commit

Permalink
Merge pull request #412 from RocketPy-Team/maint/deprecate-methods-to-v1
Browse files Browse the repository at this point in the history
MAINT: deprecate some methods before v1
  • Loading branch information
Gui-FernandesBR authored Sep 23, 2023
2 parents 2856b91 + 316ee46 commit 3d7e4a4
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 411 deletions.
103 changes: 61 additions & 42 deletions rocketpy/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ def __init__(

# Store launch site coordinates referenced to UTM projection system
if self.latitude > -80 and self.latitude < 84:
convert = self.geodesic_to_utm(self.latitude, self.longitude)
convert = self.geodesic_to_utm(
lat=self.latitude,
lon=self.longitude,
flattening=self.ellipsoid.flattening,
semi_major_axis=self.ellipsoid.semi_major_axis,
)

self.initial_north = convert[1]
self.initial_east = convert[0]
Expand All @@ -375,8 +380,12 @@ def __init__(
self.elevation = elevation
self.set_elevation(elevation)

# Recalculate Earth Radius
self.earth_radius = self.calculate_earth_radius(self.latitude) # in m
# Recalculate Earth Radius (meters)
self.earth_radius = self.calculate_earth_radius(
lat=self.latitude,
semi_major_axis=self.ellipsoid.semi_major_axis,
flattening=self.ellipsoid.flattening,
)

# Initialize plots and prints object
self.plots = _EnvironmentPlots(self)
Expand Down Expand Up @@ -3309,7 +3318,11 @@ def set_earth_geometry(self, datum):
)

# Auxiliary functions - Geodesic Coordinates
def geodesic_to_utm(self, lat, lon):

@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°
Expand All @@ -3322,6 +3335,14 @@ def geodesic_to_utm(self, lat, lon):
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
-------
Expand Down Expand Up @@ -3360,10 +3381,6 @@ def geodesic_to_utm(self, lat, lon):
lon_mc = 3
EW = "W|E"

# Select the desired datum (i.e. the ellipsoid parameters)
flattening = self.ellipsoid.flattening
semi_major_axis = self.ellipsoid.semi_major_axis

# Evaluate the hemisphere and determine the N coordinate at the Equator
if lat < 0:
N0 = 10000000
Expand Down Expand Up @@ -3424,7 +3441,10 @@ def geodesic_to_utm(self, lat, lon):

return x, y, utm_zone, utm_letter, hemis, EW

def utm_to_geodesic(self, x, y, utm_zone, hemis):
@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). The latitude should be between -80°
and 84°
Expand All @@ -3441,6 +3461,14 @@ def utm_to_geodesic(self, x, y, utm_zone, hemis):
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
-------
Expand All @@ -3456,10 +3484,6 @@ def utm_to_geodesic(self, x, y, utm_zone, hemis):
# Calculate the Central Meridian from the UTM zone number
central_meridian = utm_zone * 6 - 183 # degrees

# Select the desired datum
flattening = self.ellipsoid.flattening
semi_major_axis = self.ellipsoid.semi_major_axis

# Calculate reference values
K0 = 1 - 1 / 2500
e2 = 2 * flattening - flattening**2
Expand Down Expand Up @@ -3513,7 +3537,10 @@ def utm_to_geodesic(self, x, y, utm_zone, hemis):

return lat, lon

def calculate_earth_radius(self, lat):
@staticmethod
def calculate_earth_radius(
lat, semi_major_axis=6378137.0, flattening=1 / 298.257223563
):
"""Simple function to calculate the Earth Radius at a specific latitude
based on ellipsoidal reference model (datum). The earth radius here is
assumed as the distance between the ellipsoid's center of gravity and a
Expand All @@ -3526,21 +3553,23 @@ def calculate_earth_radius(self, lat):
----------
lat : float
latitude in which the Earth radius will be calculated
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
-------
radius : float
Earth Radius at the desired latitude in meters
"""
# Select the desired datum (i.e. the ellipsoid parameters)
flattening = self.ellipsoid.flattening
semi_major_axis = self.ellipsoid.semi_major_axis

# Calculate the semi minor axis length
# semi_minor_axis = semi_major_axis - semi_major_axis*(flattening**(-1))
semi_minor_axis = semi_major_axis * (1 - flattening)

# Convert latitude to radians
# Numpy trigonometric functions work with radians, so convert to radians
lat = lat * np.pi / 180

# Calculate the Earth Radius in meters
Expand All @@ -3555,12 +3584,10 @@ def calculate_earth_radius(self, lat):
)
)

# Convert latitude to degrees
lat = lat * 180 / np.pi

return e_radius

def decimal_degrees_to_arc_seconds(self, angle):
@staticmethod
def decimal_degrees_to_arc_seconds(angle):
"""Function to convert an angle in decimal degrees to deg/min/sec.
Converts (°) to (° ' ")
Expand All @@ -3572,24 +3599,16 @@ def decimal_degrees_to_arc_seconds(self, angle):
Returns
-------
deg : float
degrees : float
The degrees.
min : float
arc_minutes : float
The arc minutes. 1 arc-minute = (1/60)*degree
sec : float
arc_seconds : float
The arc Seconds. 1 arc-second = (1/3600)*degree
"""

if angle < 0:
signal = -1
else:
signal = 1

deg = (signal * angle) // 1
min = abs(signal * angle - deg) * 60 // 1
sec = abs((signal * angle - deg) * 60 - min) * 60
# print("The angle {:f} is equals to {:.0f}º {:.0f}' {:.3f}'' ".format(
# angle, signal*deg, min, sec
# ))

return deg, min, sec
sign = -1 if angle < 0 else 1
degrees = int(abs(angle)) * sign
remainder = abs(angle) - abs(degrees)
arc_minutes = int(remainder * 60)
arc_seconds = (remainder * 60 - arc_minutes) * 60
return degrees, arc_minutes, arc_seconds
63 changes: 0 additions & 63 deletions rocketpy/Flight.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import math
import time
import warnings
from copy import deepcopy
from functools import cached_property

import matplotlib.pyplot as plt
import numpy as np
import simplekml
from scipy import integrate
Expand Down Expand Up @@ -3313,67 +3311,6 @@ def all_info(self):

return None

def animate(self, start=0, stop=None, fps=12, speed=4, elev=None, azim=None):
"""Plays an animation of the flight. Not implemented yet. Only
kinda works outside notebook.
"""
# Set up stopping time
stop = self.t_final if stop is None else stop
# Speed = 4 makes it almost real time - matplotlib is way to slow
# Set up graph
fig = plt.figure(figsize=(18, 15))
axes = fig.gca(projection="3d")
# Initialize time
time_range = np.linspace(start, stop, fps * (stop - start))
# Initialize first frame
axes.set_title("Trajectory and Velocity Animation")
axes.set_xlabel("X (m)")
axes.set_ylabel("Y (m)")
axes.set_zlabel("Z (m)")
axes.view_init(elev, azim)
R = axes.quiver(0, 0, 0, 0, 0, 0, color="r", label="Rocket")
V = axes.quiver(0, 0, 0, 0, 0, 0, color="g", label="Velocity")
W = axes.quiver(0, 0, 0, 0, 0, 0, color="b", label="Wind")
S = axes.quiver(0, 0, 0, 0, 0, 0, color="black", label="Freestream")
axes.legend()
# Animate
for t in time_range:
R.remove()
V.remove()
W.remove()
S.remove()
# Calculate rocket position
Rx, Ry, Rz = self.x(t), self.y(t), self.z(t)
Ru = 1 * (2 * (self.e1(t) * self.e3(t) + self.e0(t) * self.e2(t)))
Rv = 1 * (2 * (self.e2(t) * self.e3(t) - self.e0(t) * self.e1(t)))
Rw = 1 * (1 - 2 * (self.e1(t) ** 2 + self.e2(t) ** 2))
# Calculate rocket Mach number
Vx = self.vx(t) / 340.40
Vy = self.vy(t) / 340.40
Vz = self.vz(t) / 340.40
# Calculate wind Mach Number
z = self.z(t)
Wx = self.env.wind_velocity_x(z) / 20
Wy = self.env.wind_velocity_y(z) / 20
# Calculate freestream Mach Number
Sx = self.stream_velocity_x(t) / 340.40
Sy = self.stream_velocity_y(t) / 340.40
Sz = self.stream_velocity_z(t) / 340.40
# Plot Quivers
R = axes.quiver(Rx, Ry, Rz, Ru, Rv, Rw, color="r")
V = axes.quiver(Rx, Ry, Rz, -Vx, -Vy, -Vz, color="g")
W = axes.quiver(Rx - Vx, Ry - Vy, Rz - Vz, Wx, Wy, 0, color="b")
S = axes.quiver(Rx, Ry, Rz, Sx, Sy, Sz, color="black")
# Adjust axis
axes.set_xlim(Rx - 1, Rx + 1)
axes.set_ylim(Ry - 1, Ry + 1)
axes.set_zlim(Rz - 1, Rz + 1)
# plt.pause(1/(fps*speed))
try:
plt.pause(1 / (fps * speed))
except:
time.sleep(1 / (fps * speed))

def time_iterator(self, node_list):
i = 0
while i < len(node_list) - 1:
Expand Down
Loading

0 comments on commit 3d7e4a4

Please sign in to comment.