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

ENH: Moved Environment prints to environment_prints.py #294

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
167 changes: 10 additions & 157 deletions rocketpy/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import pytz
import requests

from .prints.environment_prints import _EnvironmentPrints

try:
import netCDF4
except ImportError:
Expand Down Expand Up @@ -369,6 +371,9 @@ def __init__(
self.earthRadius = 6.3781 * (10**6)
self.airGasConstant = 287.05287 # in J/K/Kg

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

# Initialize atmosphere
self.setAtmosphericModel("StandardAtmosphere")

Expand Down Expand Up @@ -2852,76 +2857,9 @@ def info(self):
------
None
"""
# Print launch site details
print("Launch Site Details")
print("\nLaunch Rail Length:", self.rL, " m")
time_format = "%Y-%m-%d %H:%M:%S"
if self.date != None and "UTC" not in self.timeZone:
print(
"Launch Date:",
self.date.strftime(time_format),
"UTC |",
self.localDate.strftime(time_format),
self.timeZone,
)
elif self.date != None:
print("Launch Date:", self.date.strftime(time_format), "UTC")
if self.lat != None and self.lon != None:
print("Launch Site Latitude: {:.5f}°".format(self.lat))
print("Launch Site Longitude: {:.5f}°".format(self.lon))
print("Reference Datum: " + self.datum)
print(
"Launch Site UTM coordinates: {:.2f} ".format(self.initialEast)
+ self.initialEW
+ " {:.2f} ".format(self.initialNorth)
+ self.initialHemisphere
)
print("Launch Site UTM zone:", str(self.initialUtmZone) + self.initialUtmLetter)
print("Launch Site Surface Elevation: {:.1f} m".format(self.elevation))

# Print atmospheric model details
print("\n\nAtmospheric Model Details")
modelType = self.atmosphericModelType
print("\nAtmospheric Model Type:", modelType)
print(
modelType
+ " Maximum Height: {:.3f} km".format(self.maxExpectedHeight / 1000)
)
if modelType in ["Forecast", "Reanalysis", "Ensemble"]:
# Determine time period
initDate = self.atmosphericModelInitDate
endDate = self.atmosphericModelEndDate
interval = self.atmosphericModelInterval
print(modelType + " Time Period: From ", initDate, " to ", endDate, " UTC")
print(modelType + " Hour Interval:", interval, " hrs")
# Determine latitude and longitude range
initLat = self.atmosphericModelInitLat
endLat = self.atmosphericModelEndLat
initLon = self.atmosphericModelInitLon
endLon = self.atmosphericModelEndLon
print(modelType + " Latitude Range: From ", initLat, "° To ", endLat, "°")
print(modelType + " Longitude Range: From ", initLon, "° To ", endLon, "°")
if modelType == "Ensemble":
print("Number of Ensemble Members:", self.numEnsembleMembers)
print("Selected Ensemble Member:", self.ensembleMember, " (Starts from 0)")

# Print atmospheric conditions
print("\n\nSurface Atmospheric Conditions")
print("\nSurface Wind Speed: {:.2f} m/s".format(self.windSpeed(self.elevation)))
print(
"Surface Wind Direction: {:.2f}°".format(self.windDirection(self.elevation))
)
print("Surface Wind Heading: {:.2f}°".format(self.windHeading(self.elevation)))
print(
"Surface Pressure: {:.2f} hPa".format(self.pressure(self.elevation) / 100)
)
print("Surface Temperature: {:.2f} K".format(self.temperature(self.elevation)))
print("Surface Air Density: {:.3f} kg/m³".format(self.density(self.elevation)))
print(
"Surface Speed of Sound: {:.2f} m/s".format(
self.speedOfSound(self.elevation)
)
)

# All prints
self.prints.all()

# Plot graphs
print("\n\nAtmospheric Model Plots")
Expand Down Expand Up @@ -2984,72 +2922,8 @@ def allInfo(self):
------
None
"""
# Print gravity details
print("Gravity Details")
print("\nAcceleration of Gravity: " + str(self.g) + " m/s²")

# Print launch site details
print("\n\nLaunch Site Details")
print("\nLaunch Rail Length:", self.rL, " m")
time_format = "%Y-%m-%d %H:%M:%S"
if self.date != None and "UTC" not in self.timeZone:
print(
"Launch Date:",
self.date.strftime(time_format),
"UTC |",
self.localDate.strftime(time_format),
self.timeZone,
)
elif self.date != None:
print("Launch Date:", self.date.strftime(time_format), "UTC")
if self.lat != None and self.lon != None:
print("Launch Site Latitude: {:.5f}°".format(self.lat))
print("Launch Site Longitude: {:.5f}°".format(self.lon))
print("Launch Site Surface Elevation: {:.1f} m".format(self.elevation))

# Print atmospheric model details
print("\n\nAtmospheric Model Details")
modelType = self.atmosphericModelType
print("\nAtmospheric Model Type:", modelType)
print(
modelType
+ " Maximum Height: {:.3f} km".format(self.maxExpectedHeight / 1000)
)
if modelType in ["Forecast", "Reanalysis", "Ensemble"]:
# Determine time period
initDate = self.atmosphericModelInitDate
endDate = self.atmosphericModelEndDate
interval = self.atmosphericModelInterval
print(modelType + " Time Period: From ", initDate, " to ", endDate, " UTC")
print(modelType + " Hour Interval:", interval, " hrs")
# Determine latitude and longitude range
initLat = self.atmosphericModelInitLat
endLat = self.atmosphericModelEndLat
initLon = self.atmosphericModelInitLon
endLon = self.atmosphericModelEndLon
print(modelType + " Latitude Range: From ", initLat, "° To ", endLat, "°")
print(modelType + " Longitude Range: From ", initLon, "° To ", endLon, "°")
if modelType == "Ensemble":
print("Number of Ensemble Members:", self.numEnsembleMembers)
print("Selected Ensemble Member:", self.ensembleMember, " (Starts from 0)")

# Print atmospheric conditions
print("\n\nSurface Atmospheric Conditions")
print("\nSurface Wind Speed: {:.2f} m/s".format(self.windSpeed(self.elevation)))
print(
"Surface Wind Direction: {:.2f}°".format(self.windDirection(self.elevation))
)
print("Surface Wind Heading: {:.2f}°".format(self.windHeading(self.elevation)))
print(
"Surface Pressure: {:.2f} hPa".format(self.pressure(self.elevation) / 100)
)
print("Surface Temperature: {:.2f} K".format(self.temperature(self.elevation)))
print("Surface Air Density: {:.3f} kg/m³".format(self.density(self.elevation)))
print(
"Surface Speed of Sound: {:.2f} m/s".format(
self.speedOfSound(self.elevation)
)
)

self.prints.all()

# Plot graphs
print("\n\nAtmospheric Model Plots")
Expand Down Expand Up @@ -3654,24 +3528,3 @@ def decimalDegressToArcSeconds(self, angle):
# ))

return deg, min, sec

def printEarthDetails(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.lat))
# print("Launch Site Longitude: {:.5f}°".format(self.lon))
# print("Reference Datum: " + self.datum)
# print("Launch Site UTM coordinates: {:.2f} ".format(self.initialEast)
# + self.initialEW + " {:.2f} ".format(self.initialNorth) + self.initialHemisphere
# )
# print("Launch Site UTM zone number:", self.initialUtmZone)
# print("Launch Site Surface Elevation: {:.1f} m".format(self.elevation))
print("Earth Radius at Launch site: {:.1f} m".format(self.earthRadius))
print("Gravity acceleration at launch site: Still not implemented :(")

return None
Loading