Skip to content

Commit

Permalink
ENH: add extrapolation to barometric_height
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 07d4c33 commit 2b06a7e
Showing 1 changed file with 79 additions and 9 deletions.
88 changes: 79 additions & 9 deletions rocketpy/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ def process_custom_atmosphere(
interpolation="linear",
)
self.barometric_height = self.pressure.inverse_function().set_discrete(
0, max_expected_height, 1000, extrapolation="constant"
0, max_expected_height, 100, extrapolation="constant"
)
self.barometric_height.set_inputs("Pressure (Pa)")
self.barometric_height.set_outputs("Height Above Sea Level (m)")
Expand Down Expand Up @@ -1617,8 +1617,21 @@ def process_windy_atmosphere(self, model="ECMWF"):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
columns = data_array[:, (0, 1)]
pressure_ground = np.array(
[
[
columns[1][0]
+ (-columns[1][1] / (columns[0][1] - columns[1][1]))
* (columns[0][0] - columns[1][0]),
0,
]
]
)
bar_height = np.concatenate((pressure_ground, columns))
self.barometric_height = Function(
data_array[:, (0, 1)],
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
Expand Down Expand Up @@ -1750,8 +1763,21 @@ def process_wyoming_sounding(self, file):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
columns = data_array[:, (0, 1)]
pressure_ground = np.array(
[
[
columns[1][0]
+ (-columns[1][1] / (columns[0][1] - columns[1][1]))
* (columns[0][0] - columns[1][0]),
0,
]
]
)
bar_height = np.concatenate((pressure_ground, columns))
self.barometric_height = Function(
data_array[:, (0, 1)],
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
Expand Down Expand Up @@ -1932,10 +1958,28 @@ def process_noaaruc_sounding(self, file):
outputs="Pressure (Pa)",
interpolation="linear",
)
# construct barometric height array from pressure array
# Converts 10*hPa to Pa and save values
barometric_height_array[:, 0] = 10 * barometric_height_array[:, 0]
# Linearly extrapolate pressure to ground level
pressure_ground = np.array(
[
[
barometric_height_array[1][0]
+ (
-barometric_height_array[1][1]
/ (
barometric_height_array[0][1]
- barometric_height_array[1][1]
)
)
* (barometric_height_array[0][0] - barometric_height_array[1][0]),
0,
]
]
)
bar_height = np.concatenate((pressure_ground, barometric_height_array))
self.barometric_height = Function(
barometric_height_array,
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
Expand Down Expand Up @@ -2309,8 +2353,21 @@ def process_forecast_reanalysis(self, file, dictionary):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
columns = data_array[:, (0, 1)]
pressure_ground = np.array(
[
[
columns[1][0]
+ (-columns[1][1] / (columns[0][1] - columns[1][1]))
* (columns[0][0] - columns[1][0]),
0,
]
]
)
bar_height = np.concatenate((pressure_ground, columns))
self.barometric_height = Function(
data_array[:, (0, 1)],
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
Expand Down Expand Up @@ -2844,11 +2901,24 @@ def select_ensemble_member(self, member=0):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
columns = data_array[:, (0, 1)]
pressure_ground = np.array(
[
[
columns[1][0]
+ (-columns[1][1] / (columns[0][1] - columns[1][1]))
* (columns[0][0] - columns[1][0]),
0,
]
]
)
bar_height = np.concatenate((pressure_ground, columns))
self.barometric_height = Function(
data_array[:, (0, 1)],
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
interpolation="linearS",
)
self.temperature = Function(
data_array[:, (1, 2)],
Expand Down Expand Up @@ -3016,7 +3086,7 @@ def pressure_function(h):
# 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"
pressure[-1], pressure[0], 100, extrapolation="constant"
)
self.barometric_height_ISA.set_inputs("Pressure (Pa)")
self.barometric_height_ISA.set_outputs("Height Above Sea Level (m)")
Expand Down

0 comments on commit 2b06a7e

Please sign in to comment.