Skip to content

Commit

Permalink
Merge branch 'develop' into enh/air-brakes
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano authored Feb 5, 2024
2 parents 4ee4c7d + 435bd62 commit ce6d2ab
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function-naming-style=snake_case
# Good variable names which should always be accepted, separated by a comma.
good-names=FlightPhases,
WindroseAxes,
barometric_height_ISA,


# Good variable names regexes, separated by a comma. If names match any regex,
Expand Down Expand Up @@ -436,6 +437,7 @@ disable=raw-checker-failed,
no-else-return,
inconsistent-return-statements,
unspecified-encoding,
no-member, # because we use funcify_method decorator

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ straightforward as possible.

### Added

- ENH: Shepard Optimized Interpolation - Multiple Inputs Support [#515](https://github.com/RocketPy-Team/RocketPy/pull/515)
- ENH: adds new Function.savetxt method [#514](https://github.com/RocketPy-Team/RocketPy/pull/514)
- ENH: Argument for Optional Mutation on Function Discretize [#519](https://github.com/RocketPy-Team/RocketPy/pull/519)

Expand All @@ -40,8 +41,11 @@ straightforward as possible.
- MNT: Add repr method to Parachute class [#490](https://github.com/RocketPy-Team/RocketPy/pull/490)
- ENH: Function Reverse Arithmetic Priority [#488](https://github.com/RocketPy-Team/RocketPy/pull/488)
- DOC: Update Header Related Docs
- ENH Precalculate Barometric Height [#511](https://github.com/RocketPy-Team/RocketPy/pull/511)
- MNT: Encapsulate quaternion conversions [#537](https://github.com/RocketPy-Team/RocketPy/pull/537)
- MNT: improve the low pass filter and document an example [#538](https://github.com/RocketPy-Team/RocketPy/pull/538)


### Fixed

- ENH: Parachute trigger doesn't work if "Apogee" is used instead of "apogee" [#489](https://github.com/RocketPy-Team/RocketPy/pull/489)
Expand Down
30 changes: 11 additions & 19 deletions docs/notebooks/deployable_payload_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"\n",
"* RocketPy\n",
"* netCDF4 (to get weather forecasts)\n",
"* Data files (we will clone RocketPy's repository for these)\n",
"* Data files (we will download RocketPy's data from github)\n",
"\n",
"Therefore, let's run the following lines of code:"
]
Expand All @@ -45,18 +45,10 @@
"outputs": [],
"source": [
"!pip install rocketpy netCDF4\n",
"!git clone https://github.com/RocketPy-Team/RocketPy.git"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.chdir(\"RocketPy/docs/notebooks\")"
"!curl -o NACA0012-radians.csv https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/calisto/NACA0012-radians.csv\n",
"!curl -o Cesaroni_M1670.eng https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/motors/Cesaroni_M1670.eng\n",
"!curl -o powerOffDragCurve.csv https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/calisto/powerOffDragCurve.csv\n",
"!curl -o powerOnDragCurve.csv https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/calisto/powerOnDragCurve.csv"
]
},
{
Expand Down Expand Up @@ -237,7 +229,7 @@
"outputs": [],
"source": [
"Pro75M1670 = SolidMotor(\n",
" thrust_source=\"../../data/motors/Cesaroni_M1670.eng\",\n",
" thrust_source=\"Cesaroni_M1670.eng\",\n",
" dry_mass=1.815,\n",
" dry_inertia=(0.125, 0.125, 0.002),\n",
" nozzle_radius=33 / 1000,\n",
Expand Down Expand Up @@ -392,8 +384,8 @@
" radius=127 / 2000,\n",
" mass=rocket_mass + rocket_mass,\n",
" inertia=(6.321, 6.321, 0.034),\n",
" power_off_drag=\"../../data/calisto/powerOffDragCurve.csv\",\n",
" power_on_drag=\"../../data/calisto/powerOnDragCurve.csv\",\n",
" power_off_drag=\"powerOffDragCurve.csv\",\n",
" power_on_drag=\"powerOnDragCurve.csv\",\n",
" center_of_mass_without_motor=0,\n",
" coordinate_system_orientation=\"tail_to_nose\",\n",
")\n",
Expand All @@ -417,7 +409,7 @@
" span=0.110,\n",
" position=-1.04956,\n",
" cant_angle=0.5,\n",
" airfoil=(\"../../data/calisto/NACA0012-radians.csv\",\"radians\"),\n",
" airfoil=(\"NACA0012-radians.csv\",\"radians\"),\n",
")\n",
"\n",
"rocket_with_payload.add_tail(\n",
Expand Down Expand Up @@ -536,8 +528,8 @@
" radius=127 / 2000,\n",
" mass=rocket_mass,\n",
" inertia=(6.321, 6.321, 0.034),\n",
" power_off_drag=\"../../data/calisto/powerOffDragCurve.csv\",\n",
" power_on_drag=\"../../data/calisto/powerOnDragCurve.csv\",\n",
" power_off_drag=\"powerOffDragCurve.csv\",\n",
" power_on_drag=\"powerOnDragCurve.csv\",\n",
" center_of_mass_without_motor=0,\n",
" coordinate_system_orientation=\"tail_to_nose\",\n",
")\n",
Expand Down
16 changes: 9 additions & 7 deletions docs/notebooks/dispersion_analysis/dispersion_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clone repository if using Google Colab\n",
"## Download data files if using Google Colab\n",
"\n",
"If you are running this using Binder, or you are running locally with the necessary files, you do not need to run this.\n",
"On the other hand, if you are running on Google Colab, make sure to run the cell below to clone the repository and download the necessary files."
"On the other hand, if you are running on Google Colab, make sure to run the cell below to download the necessary files."
]
},
{
Expand All @@ -37,10 +37,12 @@
"metadata": {},
"outputs": [],
"source": [
"!git clone https://github.com/RocketPy-Team/RocketPy.git\n",
"import os\n",
"\n",
"os.chdir(\"RocketPy/docs/notebooks/dispersion_analysis\")"
"!curl -o dispersion_analysis_inputs/Cd_PowerOff.csv --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/Cd_PowerOff.csv\n",
"!curl -o dispersion_analysis_inputs/Cd_PowerOn.csv --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/Cd_PowerOn.csv\n",
"!curl -o dispersion_analysis_inputs/LASC2019_reanalysis.nc --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/LASC2019_reanalysis.nc\n",
"!curl -o dispersion_analysis_inputs/thrustCurve.csv --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/thrustCurve.csv\n",
"!curl -o dispersion_analysis_inputs/Valetudo_basemap_final.jpg --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/Valetudo_basemap_final.jpg\n",
"!mkdir -p dispersion_analysis_outputs"
]
},
{
Expand All @@ -66,7 +68,7 @@
},
"outputs": [],
"source": [
"!pip install rocketpy"
"!pip install rocketpy imageio"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clone repository if using Google Colab\n",
"## Clone data files if using Google Colab\n",
"\n",
"If you are running this using Binder, or you are running locally with the necessary files, you do not need to run this.\n",
"On the other hand, if you are running on Google Colab, make sure to run the cell below to clone the repository and download the necessary files."
"On the other hand, if you are running on Google Colab, make sure to run the cell below to download the necessary files."
]
},
{
Expand All @@ -31,10 +31,12 @@
"metadata": {},
"outputs": [],
"source": [
"!git clone https://github.com/giovaniceotto/RocketPy.git\n",
"import os\n",
"\n",
"os.chdir(\"RocketPy/docs/notebooks/dispersion_analysis\")"
"!curl -o dispersion_analysis_inputs/Cd_PowerOff.csv --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/Cd_PowerOff.csv\n",
"!curl -o dispersion_analysis_inputs/Cd_PowerOn.csv --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/Cd_PowerOn.csv\n",
"!curl -o dispersion_analysis_inputs/LASC2019_reanalysis.nc --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/LASC2019_reanalysis.nc\n",
"!curl -o dispersion_analysis_inputs/thrustCurve.csv --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/thrustCurve.csv\n",
"!curl -o dispersion_analysis_inputs/Valetudo_basemap_final.jpg --create-dirs https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/docs/notebooks/dispersion_analysis/dispersion_analysis_inputs/Valetudo_basemap_final.jpg\n",
"!mkdir -p dispersion_analysis_outputs"
]
},
{
Expand Down
30 changes: 9 additions & 21 deletions docs/notebooks/getting_started_colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"We start by setting up our environment. To run this notebook, we will need:\n",
"\n",
"- RocketPy\n",
"- Data files (we will clone RocketPy's repository for these)\n",
"- Data files (we will download RocketPy's data from github)\n",
"\n",
"Therefore, let's run the following lines of code:"
]
Expand All @@ -38,22 +38,10 @@
"outputs": [],
"source": [
"!pip install rocketpy\n",
"!git clone https://github.com/giovaniceotto/RocketPy.git"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "pY5XGge5OoGJ"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.chdir(\"RocketPy/docs/notebooks\")"
"!curl -o NACA0012-radians.csv https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/calisto/NACA0012-radians.csv\n",
"!curl -o Cesaroni_M1670.eng https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/motors/Cesaroni_M1670.eng\n",
"!curl -o powerOffDragCurve.csv https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/calisto/powerOffDragCurve.csv\n",
"!curl -o powerOnDragCurve.csv https://raw.githubusercontent.com/RocketPy-Team/RocketPy/master/data/calisto/powerOnDragCurve.csv"
]
},
{
Expand Down Expand Up @@ -2485,7 +2473,7 @@
"outputs": [],
"source": [
"Pro75M1670 = SolidMotor(\n",
" thrust_source=\"../../data/motors/Cesaroni_M1670.eng\",\n",
" thrust_source=\"Cesaroni_M1670.eng\",\n",
" dry_mass=1.815,\n",
" dry_inertia=(0.125, 0.125, 0.002),\n",
" nozzle_radius=33 / 1000,\n",
Expand Down Expand Up @@ -3499,8 +3487,8 @@
" radius=127 / 2000,\n",
" mass=14.426,\n",
" inertia=(6.321, 6.321, 0.034),\n",
" power_off_drag=\"../../data/calisto/powerOffDragCurve.csv\",\n",
" power_on_drag=\"../../data/calisto/powerOnDragCurve.csv\",\n",
" power_off_drag=\"powerOffDragCurve.csv\",\n",
" power_on_drag=\"powerOnDragCurve.csv\",\n",
" center_of_mass_without_motor=0,\n",
" coordinate_system_orientation=\"tail_to_nose\",\n",
")\n",
Expand Down Expand Up @@ -3579,7 +3567,7 @@
" span=0.110,\n",
" position=-1.04956,\n",
" cant_angle=0.5,\n",
" airfoil=(\"../../data/calisto/NACA0012-radians.csv\",\"radians\"),\n",
" airfoil=(\"NACA0012-radians.csv\",\"radians\"),\n",
")\n",
"\n",
"tail = calisto.add_tail(\n",
Expand Down
67 changes: 66 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, 100, 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,15 @@ def process_windy_atmosphere(self, model="ECMWF"):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
bar_height = data_array[:, (0, 1)]
self.barometric_height = Function(
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
extrapolation="natural",
)
self.temperature = Function(
data_array[:, (1, 2)],
inputs="Height Above Sea Level (m)",
Expand Down Expand Up @@ -1732,6 +1753,15 @@ def process_wyoming_sounding(self, file):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
bar_height = data_array[:, (0, 1)]
self.barometric_height = Function(
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
extrapolation="natural",
)

# Retrieve temperature from data array
data_array[:, 2] = data_array[:, 2] + 273.15 # Converts C to K
Expand Down Expand Up @@ -1845,6 +1875,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 +1889,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 +1938,15 @@ def process_noaaruc_sounding(self, file):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Converts 10*hPa to Pa and save values
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",
extrapolation="natural",
)

# Convert 10*C to K and save values
temperature_array[:, 1] = (
Expand Down Expand Up @@ -2274,6 +2316,15 @@ def process_forecast_reanalysis(self, file, dictionary):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
bar_height = data_array[:, (0, 1)]
self.barometric_height = Function(
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
extrapolation="natural",
)
self.temperature = Function(
data_array[:, (1, 2)],
inputs="Height Above Sea Level (m)",
Expand Down Expand Up @@ -2803,6 +2854,15 @@ def select_ensemble_member(self, member=0):
outputs="Pressure (Pa)",
interpolation="linear",
)
# Linearly extrapolate pressure to ground level
bar_height = data_array[:, (0, 1)]
self.barometric_height = Function(
bar_height,
inputs="Pressure (Pa)",
outputs="Height Above Sea Level (m)",
interpolation="linear",
extrapolation="natural",
)
self.temperature = Function(
data_array[:, (1, 2)],
inputs="Height Above Sea Level (m)",
Expand Down Expand Up @@ -2965,7 +3025,12 @@ def pressure_function(h):
outputs="Pressure (Pa)",
)

return None
# Discretize Function to speed up the trajectory simulation.
self.barometric_height_ISA = self.pressure_ISA.inverse_function().set_discrete(
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)")

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

0 comments on commit ce6d2ab

Please sign in to comment.