Skip to content

Instantly share code, notes, and snippets.

@buzzerrookie
Created January 28, 2016 07:07
Show Gist options
  • Save buzzerrookie/5b6438c603eabf13d07e to your computer and use it in GitHub Desktop.
Save buzzerrookie/5b6438c603eabf13d07e to your computer and use it in GitHub Desktop.
Python program to compute International Standard Atmosphere
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)
@devonbattison
Copy link

I'm doing an assignment for my aerospace class, and I have to write a program to calculate components of standard atmosphere given an altitude. Is this code here what I should base my program off of? Here is the assignment:
Learning Objectives:
Due: 26 September
a. Understand the basic principles of the Standard Atmosphere.
b. Calculate various properties of the Standard Atmosphere.
c. Write a computer program to calculate state properties for a specified altitude.
Problems:

  1. Write a computer program to compute ICAO Standard Atmosphere characteristics for a given input altitude. The program must be written in Python. You must write it to accept a single user input from the keyboard, consisting of geometric altitude in units of feet. As outputs, your program is to compute temperature in units of degrees R, pressure in units of pounds per square feet, density in units of slugs per cubic feet, and the speed of sound in units of feet per second. It is to be assumed that the gas is air. Note that in the equations for temperature, pressure, and density given in the textbook, h is the geopotential altitude, but the input to your program is the geometric altitude.

@buzzerrookie
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment