File tree 2 files changed +52
-113
lines changed
2 files changed +52
-113
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ """
2
+ Title : Calculate altitude using Pressure
3
+
4
+ Description :
5
+ The below algorithm approximates the altitude using Barometric formula
6
+
7
+
8
+ """
9
+
10
+
11
+ def get_altitude_at_pressure (pressure : float ) -> float :
12
+ """
13
+ This method calculates the altitude from Pressure wrt to
14
+ Sea level pressure as reference .Pressure is in Pascals
15
+ https://en.wikipedia.org/wiki/Pressure_altitude
16
+ https://community.bosch-sensortec.com/t5/Question-and-answers/How-to-calculate-the-altitude-from-the-pressure-sensor-data/qaq-p/5702
17
+
18
+ H = 44330 * [1 - (P/p0)^(1/5.255) ]
19
+
20
+ Where :
21
+ H = altitude (m)
22
+ P = measured pressure
23
+ p0 = reference pressure at sea level 101325 Pa
24
+
25
+ Examples:
26
+ >>> get_altitude_at_pressure(pressure=100_000)
27
+ 105.47836610778828
28
+ >>> get_altitude_at_pressure(pressure=101_325)
29
+ 0.0
30
+ >>> get_altitude_at_pressure(pressure=80_000)
31
+ 1855.873388064995
32
+ >>> get_altitude_at_pressure(pressure=201_325)
33
+ Traceback (most recent call last):
34
+ ...
35
+ ValueError: Value Higher than Pressure at Sea Level !
36
+ >>> get_altitude_at_pressure(pressure=-80_000)
37
+ Traceback (most recent call last):
38
+ ...
39
+ ValueError: Atmospheric Pressure can not be negative !
40
+ """
41
+
42
+ if pressure > 101325 :
43
+ raise ValueError ("Value Higher than Pressure at Sea Level !" )
44
+ if pressure < 0 :
45
+ raise ValueError ("Atmospheric Pressure can not be negative !" )
46
+ return 44_330 * (1 - (pressure / 101_325 ) ** (1 / 5.5255 ))
47
+
48
+
49
+ if __name__ == "__main__" :
50
+ import doctest
51
+
52
+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments