Skip to content

Commit

Permalink
ENH: add barometric_height to environment
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano authored and Gui-FernandesBR committed Jan 20, 2024
1 parent a14e7e8 commit 5c1267f
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class Environment:
Environment.pressure : Function
Air pressure in Pa as a function of altitude. Can be accessed as regular
array, or called as a Function. See Function for more information.
Environment.barometric_height : Function
Geometric height above sea level in m as a function of pressure. Can be
accessed as regular array, or called as a Function. See Function for
more information.
Environment.temperature : Function
Air temperature in K as a function of altitude. Can be accessed as
regular array, or called as a Function. See Function for more
Expand Down Expand Up @@ -1315,6 +1319,8 @@ def process_standard_atmosphere(self):

# Save temperature, pressure and wind profiles
self.pressure = self.pressure_ISA
self.barometric_height = self.barometric_height_ISA

self.temperature = self.temperature_ISA
self.wind_direction = Function(
0,
Expand Down Expand Up @@ -1433,6 +1439,7 @@ def process_custom_atmosphere(
if pressure is None:
# Use standard atmosphere
self.pressure = self.pressure_ISA
self.barometric_height = self.barometric_height_ISA
else:
# Use custom input
self.pressure = Function(
Expand All @@ -1441,6 +1448,11 @@ def process_custom_atmosphere(
outputs="Pressure (Pa)",
interpolation="linear",
)
self.barometric_height = self.pressure.inverse_function().set_discrete(
0, max_expected_height, 1000, extrapolation="constant"
)
self.barometric_height.set_inputs("Pressure (Pa)")
self.barometric_height.set_outputs("Height Above Sea Level (m)")
# Check maximum height of custom pressure input
if not callable(self.pressure.source):
max_expected_height = max(self.pressure[-1, 0], max_expected_height)
Expand Down Expand Up @@ -1605,6 +1617,12 @@ def process_windy_atmosphere(self, model="ECMWF"):
outputs="Pressure (Pa)",
interpolation="linear",
)
self.barometric_height = Function(
data_array[:, (0, 1)],
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
)
self.temperature = Function(
data_array[:, (1, 2)],
inputs="Height Above Sea Level (m)",
Expand Down Expand Up @@ -1732,6 +1750,12 @@ def process_wyoming_sounding(self, file):
outputs="Pressure (Pa)",
interpolation="linear",
)
self.barometric_height = Function(
data_array[:, (0, 1)],
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
)

# Retrieve temperature from data array
data_array[:, 2] = data_array[:, 2] + 273.15 # Converts C to K
Expand Down Expand Up @@ -1845,6 +1869,7 @@ def process_noaaruc_sounding(self, file):

# Extract pressure as a function of height
pressure_array = []
barometric_height_array = []
for line in lines:
# Split line into columns
columns = re.split(" +", line)[1:]
Expand All @@ -1858,7 +1883,9 @@ def process_noaaruc_sounding(self, file):
if max(columns) != 99999:
# Save value
pressure_array.append(columns)
barometric_height_array.append([columns[1], columns[0]])
pressure_array = np.array(pressure_array)
barometric_height_array = np.array(barometric_height_array)

# Extract temperature as a function of height
temperature_array = []
Expand Down Expand Up @@ -1905,6 +1932,14 @@ def process_noaaruc_sounding(self, file):
outputs="Pressure (Pa)",
interpolation="linear",
)
# construct barometric height array from pressure array
barometric_height_array[:, 0] = 10 * barometric_height_array[:, 0]
self.barometric_height = Function(
barometric_height_array,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
)

# Convert 10*C to K and save values
temperature_array[:, 1] = (
Expand Down Expand Up @@ -2274,6 +2309,12 @@ def process_forecast_reanalysis(self, file, dictionary):
outputs="Pressure (Pa)",
interpolation="linear",
)
self.barometric_height = Function(
data_array[:, (0, 1)],
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
)
self.temperature = Function(
data_array[:, (1, 2)],
inputs="Height Above Sea Level (m)",
Expand Down Expand Up @@ -2803,6 +2844,12 @@ def select_ensemble_member(self, member=0):
outputs="Pressure (Pa)",
interpolation="linear",
)
self.barometric_height = Function(
data_array[:, (0, 1)],
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
)
self.temperature = Function(
data_array[:, (1, 2)],
inputs="Height Above Sea Level (m)",
Expand Down Expand Up @@ -2965,7 +3012,14 @@ def pressure_function(h):
outputs="Pressure (Pa)",
)

return None
# Save international standard atmosphere height by pressure profile
# and discretize it. This is done to speed up the calculations in the
# trajectory simulation.
self.barometric_height_ISA = self.pressure_ISA.inverse_function().set_discrete(
pressure[-1], pressure[0], 1000, extrapolation="constant"
)
self.barometric_height_ISA.set_inputs("Pressure (Pa)")
self.barometric_height_ISA.set_outputs("Height Above Sea Level (m)")

def calculate_density_profile(self):
"""Compute the density of the atmosphere as a function of
Expand Down

0 comments on commit 5c1267f

Please sign in to comment.