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

MNT: Fix env plots max heights #433

Merged
merged 8 commits into from
Oct 9, 2023
45 changes: 24 additions & 21 deletions rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,18 @@ def __init__(
self.air_gas_constant = 287.05287 # in J/K/Kg
self.standard_g = 9.80665

# Initialize launch site details
self.elevation = elevation
self.set_elevation(elevation)
self._max_expected_height = 80000 # default value

# Initialize plots and prints objects
self.prints = _EnvironmentPrints(self)
self.plots = _EnvironmentPlots(self)

# Initialize atmosphere
self.set_atmospheric_model("standard_atmosphere")

# Save latitude and longitude
if latitude != None and longitude != None:
self.set_location(latitude, longitude)
else:
self.latitude, self.longitude = None, None

# Save date
if date != None:
self.set_date(date, timezone)
Expand All @@ -341,15 +344,6 @@ def __init__(
self.datum = datum
self.ellipsoid = self.set_earth_geometry(datum)

# Set gravity model
self.gravity = self.set_gravity_model(gravity)

# Initialize plots and prints objects
self.prints = _EnvironmentPrints(self)

# Initialize atmosphere
self.set_atmospheric_model("standard_atmosphere")

# Save latitude and longitude
self.latitude = latitude
self.longitude = longitude
Expand All @@ -374,9 +368,8 @@ def __init__(
self.initial_hemisphere = convert[4]
self.initial_ew = convert[5]

# Save elevation
self.elevation = elevation
self.set_elevation(elevation)
# Set gravity model
self.gravity = self.set_gravity_model(gravity)

# Recalculate Earth Radius (meters)
self.earth_radius = self.calculate_earth_radius(
Expand All @@ -385,9 +378,6 @@ def __init__(
flattening=self.ellipsoid.flattening,
)

# Initialize plots and prints object
self.plots = _EnvironmentPlots(self)

return None

def set_date(self, date, timezone="UTC"):
Expand Down Expand Up @@ -485,6 +475,19 @@ def set_gravity_model(self, gravity):
0, self.max_expected_height, 100
)

@property
def max_expected_height(self):
return self._max_expected_height

@max_expected_height.setter
def max_expected_height(self, value):
if value < self.elevation:
raise ValueError(
"Max expected height cannot be lower than the surface elevation"
)
self._max_expected_height = value
self.plots.grid = np.linspace(self.elevation, self.max_expected_height)

@funcify_method("height (m)", "gravity (m/s²)")
def somigliana_gravity(self, height):
"""Computes the gravity acceleration with the Somigliana formula.
Expand Down
12 changes: 6 additions & 6 deletions rocketpy/plots/environment_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def __init__(self, environment):
"""
# Create height grid
self.grid = np.linspace(environment.elevation, environment.max_expected_height)

self.environment = environment

return None

def __wind(self, ax):
Expand Down Expand Up @@ -179,14 +177,16 @@ def gravity_model(self):
None
"""
# Create figure
plt.figure(figsize=(9, 9))
plt.figure(figsize=(4.5, 4.5))

# Create gravity model subplot
ax = plt.subplot(111)
ax.plot(self.grid, [self.environment.gravity(i) for i in self.grid])
ax.set_ylabel("Gravity (m/s²)")
ax.set_xlabel("Height Above Sea Level (m)")
gravity = [self.environment.gravity(i) for i in self.grid]
ax.plot(gravity, self.grid)
ax.set_ylabel("Height Above Sea Level (m)")
ax.set_xlabel("Gravity Acceleration (m/s²)")
ax.grid(True)
plt.xticks(rotation=45)

plt.show()

Expand Down
39 changes: 18 additions & 21 deletions rocketpy/prints/environment_prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def gravity_details(self):
-------
None
"""
elevation = self.environment.elevation
max_expected_height = self.environment.max_expected_height
surface_gravity = self.environment.gravity([elevation])
ceiling_gravity = self.environment.gravity([max_expected_height])
print("\nGravity Details\n")
print(f"Acceleration of gravity at surface level: {surface_gravity:9.4f} m/s²")
print(
"Acceleration of Gravity at Lauch Site: "
+ str(self.environment.gravity(self.environment.elevation))
+ " m/s²"
f"Acceleration of gravity at {max_expected_height/1000:7.3f} km (ASL): {ceiling_gravity:.4f} m/s²"
)

return None

def launch_site_details(self):
Expand Down Expand Up @@ -176,27 +178,20 @@ def atmospheric_conditions(self):
return None

def print_earth_details(self):
"""[UNDER CONSTRUCTION]
"""
Function to print information about the Earth Model used in the
Environment Class

"""
# Print launch site details
# print("Launch Site Details")
# print("Launch Site Latitude: {:.5f}°".format(self.environment.latitude))
# print("Launch Site Longitude: {:.5f}°".format(self.environment.longitude))
# print("Reference Datum: " + self.environment.datum)
# print("Launch Site UTM coordinates: {:.2f} ".format(self.environment.initial_east)
# + self.environment.initial_ew + " {:.2f} ".format(self.environment.initial_north) + self.environment.initial_hemisphere
# )
# print("Launch Site UTM zone number:", self.environment.initial_utm_zone)
# print("Launch Site Surface Elevation: {:.1f} m".format(self.environment.elevation))
print(
"Earth Radius at Launch site: {:.1f} m".format(
self.environment.earth_radius
)
)
print("Gravity acceleration at launch site: Still not implemented :(")
print("\nEarth Model Details\n")
earth_radius = self.environment.earth_radius
semi_major_axis = self.environment.ellipsoid.semi_major_axis
flattening = self.environment.ellipsoid.flattening
semi_minor_axis = semi_major_axis * (1 - flattening)
print(f"Earth Radius at Launch site: {earth_radius/1000:.2f} km")
print(f"Semi-major Axis: {semi_major_axis/1000:.2f} km")
print(f"Semi-minor Axis: {semi_minor_axis/1000:.2f} km")
print(f"Flattening: {flattening:.4f}\n")

return None

Expand Down Expand Up @@ -224,4 +219,6 @@ def all(self):
self.atmospheric_conditions()
print()

self.print_earth_details()

return None