Created
January 28, 2016 07:07
-
-
Save buzzerrookie/5b6438c603eabf13d07e to your computer and use it in GitHub Desktop.
Python program to compute International Standard Atmosphere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
g = 9.80665 | |
R = 287.00 | |
def cal(p0, t0, a, h0, h1): | |
if a != 0: | |
t1 = t0 + a * (h1 - h0) | |
p1 = p0 * (t1 / t0) ** (-g / a / R) | |
else: | |
t1 = t0 | |
p1 = p0 * math.exp(-g / R / t0 * (h1 - h0)) | |
return t1, p1 | |
def isa(altitude): | |
a = [-0.0065, 0, 0.001, 0.0028] | |
h = [11000, 20000, 32000, 47000] | |
p0 = 101325 | |
t0 = 288.15 | |
prevh = 0 | |
if altitude < 0 or altitude > 47000: | |
print("altitude must be in [0, 47000]") | |
return | |
for i in range(0, 4): | |
if altitude <= h[i]: | |
temperature, pressure = cal(p0, t0, a[i], prevh, altitude) | |
break; | |
else: | |
# sth like dynamic programming | |
t0, p0 = cal(p0, t0, a[i], prevh, h[i]) | |
prevh = h[i] | |
density = pressure / (R * temperature) | |
strformat = 'Temperature: {0:.2f} \nPressure: {1:.2f} \nDensity: {2:.4f}' | |
print(strformat.format(temperature, pressure, density)) | |
if __name__ == '__main__': | |
# command line option | |
if len(sys.argv) != 2: | |
print("Usage: ./isa.py <altitude>") | |
sys.exit(-1) | |
try: | |
altitude = float(sys.argv[1]) | |
except: | |
print("Wrong altitude format!") | |
sys.exit(-2) | |
isa(altitude) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@devonbattison in my program, the input altitude is geopotential altitude in units of meter, and the output temperature, pressure, density are in units of Celsius, Pa and kg/m3 respectively. Of course you can refer to my program, but pay attention to the units.