Skip to content

Added Altitude Pressure equation #8909

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

Merged
merged 19 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
113 changes: 0 additions & 113 deletions other/lru_cache_pythonic.py

This file was deleted.

40 changes: 40 additions & 0 deletions physics/altitude_pressure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Title : Calculate altitude using Pressure

Description :
The below algorithm approximates the altitude using Barometric formula


"""


def get_altitude_at_pressure(pressure: float) -> float:
"""
This method calculates the altitude from Pressure wrt to
Sea level pressure as reference .Pressure is in Pascals
https://en.wikipedia.org/wiki/Pressure_altitude
https://community.bosch-sensortec.com/t5/Question-and-answers/How-to-calculate-the-altitude-from-the-pressure-sensor-data/qaq-p/5702

H = 44330 * [1 - (P/p0)^(1/5.255) ]

Where :
H = altitude (m)
P = measured pressure
p0 = reference pressure at sea level 101325 Pa

Examples:

>>> get_altitude_at_pressure(pressure=100000)
105.47836610778828
Copy link
Member

@cclauss cclauss Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make tests for H ~= sea level, H ~= 100 meters (the current test), H ~= 1,750 (altitude of my house) also a zero pressure, a negative pressure, and a pressure greater than 101,325... The last few should prove that the code raises ValueErrors like...

>>> bisection(lambda x: x ** 3 - 1, 2, 1000)
Traceback (most recent call last):
...
ValueError: could not find root in given interval.

"""

if pressure > 101325:
raise ValueError("Value Higher than Pressure at Sea Level !")

return 44_330 * (1 - (pressure / 101_325) ** (1 / 5.5255))


if __name__ == "__main__":
import doctest

doctest.testmod()