Python: added Atmosphere function.

This commit is contained in:
Don Cross
2023-03-13 16:16:53 -04:00
parent 8c55fbad79
commit 6c59d14bd4
5 changed files with 283 additions and 0 deletions

View File

@@ -302,6 +302,19 @@ to iterate through consecutive alternating perigees and apogees.
---
<a name="AtmosphereInfo"></a>
### class AtmosphereInfo
**Information about idealized atmospheric variables at a given elevation.**
| Type | Attribute | Description |
| --- | --- | --- |
| `float` | `pressure` | Atmospheric pressure in pascals. |
| `float` | `temperature` | Atmospheric temperature in kelvins. |
| `float` | `density` | Atmospheric densitive relative to sea level. |
---
<a name="AxisInfo"></a>
### class AxisInfo
@@ -1317,6 +1330,28 @@ and the specified body as seen from the center of the Earth.
---
<a name="Atmosphere"></a>
### Atmosphere(elevationMeters: float) &#8594; [`AtmosphereInfo`](#AtmosphereInfo)
**Calculates U.S. Standard Atmosphere (1976) variables as a function of elevation.**
This function calculates idealized values of pressure, temperature, and density
using the U.S. Standard Atmosphere (1976) model.
1. COESA, U.S. Standard Atmosphere, 1976, U.S. Government Printing Office, Washington, DC, 1976.
2. Jursa, A. S., Ed., Handbook of Geophysics and the Space Environment, Air Force Geophysics Laboratory, 1985.
See:
https://hbcp.chemnetbase.com/faces/documents/14_12/14_12_0001.xhtml
https://ntrs.nasa.gov/api/citations/19770009539/downloads/19770009539.pdf
https://www.ngdc.noaa.gov/stp/space-weather/online-publications/miscellaneous/us-standard-atmosphere-1976/us-standard-atmosphere_st76-1562_noaa.pdf
| Type | Parameter | Description |
| --- | --- | --- |
| `float` | `elevationMeters` | The elevation above sea level at which to calculate atmospheric variables. Must be in the range -500 to +100000, or an exception will occur. |
**Returns**: [`AtmosphereInfo`](#AtmosphereInfo)
---
<a name="BackdatePosition"></a>
### BackdatePosition(time: [`Time`](#Time), observerBody: [`Body`](#Body), targetBody: [`Body`](#Body), aberration: bool) &#8594; [`Vector`](#Vector)

View File

@@ -5761,6 +5761,72 @@ def NextMoonQuarter(mq: MoonQuarter) -> MoonQuarter:
return next_mq
class AtmosphereInfo:
"""Information about idealized atmospheric variables at a given elevation.
Attributes
----------
pressure : float
Atmospheric pressure in pascals.
temperature : float
Atmospheric temperature in kelvins.
density : float
Atmospheric densitive relative to sea level.
"""
def __init__(self, pressure:float, temperature:float, density:float) -> None:
self.pressure = pressure
self.temperature = temperature
self.density = density
def __repr__(self) -> str:
return 'AtmosphereInfo({} Pa, {} K, {})'.format(self.pressure, self.temperature, self.density)
def Atmosphere(elevationMeters: float) -> AtmosphereInfo:
"""Calculates U.S. Standard Atmosphere (1976) variables as a function of elevation.
This function calculates idealized values of pressure, temperature, and density
using the U.S. Standard Atmosphere (1976) model.
1. COESA, U.S. Standard Atmosphere, 1976, U.S. Government Printing Office, Washington, DC, 1976.
2. Jursa, A. S., Ed., Handbook of Geophysics and the Space Environment, Air Force Geophysics Laboratory, 1985.
See:
https://hbcp.chemnetbase.com/faces/documents/14_12/14_12_0001.xhtml
https://ntrs.nasa.gov/api/citations/19770009539/downloads/19770009539.pdf
https://www.ngdc.noaa.gov/stp/space-weather/online-publications/miscellaneous/us-standard-atmosphere-1976/us-standard-atmosphere_st76-1562_noaa.pdf
Parameters
----------
elevationMeters : float
The elevation above sea level at which to calculate atmospheric variables.
Must be in the range -500 to +100000, or an exception will occur.
Returns
-------
AtmosphereInfo
"""
P0 = 101325.0 # pressure at sea level [pascals]
T0 = 288.15 # temperature at sea level [kelvins]
T1 = 216.65 # temperature between 20 km and 32 km [kelvins]
if elevationMeters < -500.0 or elevationMeters > 100000.0:
raise Error('Invalid elevationMeters value: {}'.format(elevationMeters))
if elevationMeters <= 11000.0:
temperature = T0 - 0.0065*elevationMeters
pressure = P0 * (T0 / temperature)**(-5.25577)
elif elevationMeters <= 20000.0:
temperature = T1
pressure = 22632.0 * math.exp(-0.00015768832 * (elevationMeters - 11000.0))
else:
temperature = T1 + 0.001*(elevationMeters - 20000.0)
pressure = 5474.87 * (T1 / temperature)**(34.16319)
# The density is calculated relative to the sea level value.
# Using the ideal gas law PV=nRT, we deduce that density is proportional to P/T.
density = (pressure / temperature) / (P0 / T0)
return AtmosphereInfo(pressure, temperature, density)
class IlluminationInfo:
"""Information about the brightness and illuminated shape of a celestial body.