AIRMASS
This function computes atmospheric air mass, which is the integrated mass of air per unit surface area along a line of sight through the atmosphere. It is commonly used in atmospheric science, optics, and solar engineering to quantify how much atmosphere a path traverses at a given viewing angle.
The model integrates density with geometric and refractive corrections as a function of elevation:
m(\gamma)=\int_0^{H_{max}} \rho(H)\left\{1-\left[1+2(RI-1)\left(1-\frac{\rho(H)}{\rho_0}\right)\right]\left[\frac{\cos\gamma}{1+H/R}\right]^2\right\}^{-1/2} dH
The density profile is supplied as tabulated height-density points and linearly interpolated between points. The angle is measured above the horizon, where 90^\circ corresponds to a vertical path with minimum air mass.
Excel Usage
=AIRMASS(density_profile, angle, h_max, r_planet, ri)
density_profile(list[list], required): 2D array with elevation (m) in the first column and density (kg/m³) in the second columnangle(float, required): Angle above the horizon in degrees (0-90)h_max(float, optional, default: 86400): Maximum height to integrate to (m)r_planet(float, optional, default: 6371229): Radius of the planet (m)ri(float, optional, default: 1.000276): Refractive index of the atmosphere
Returns (float): Mass of air per square meter (float), or error message string.
Example 1: Zenith air mass (straight up)
Inputs:
| density_profile | angle | |
|---|---|---|
| 0 | 1.225 | 90 |
| 1000 | 1.112 |
Excel formula:
=AIRMASS({0,1.225;1000,1.112}, 90)
Expected output:
96133.3
Example 2: Air mass at 45 degree angle
Inputs:
| density_profile | angle | h_max | r_planet | |
|---|---|---|---|---|
| 0 | 1.225 | 45 | 86400 | 6371229 |
| 1000 | 1.112 |
Excel formula:
=AIRMASS({0,1.225;1000,1.112}, 45, 86400, 6371229)
Expected output:
135059
Example 3: All arguments specified explicitly
Inputs:
| density_profile | angle | h_max | r_planet | ri | |
|---|---|---|---|---|---|
| 0 | 1.225 | 90 | 86400 | 6371229 | 1.000276 |
| 1000 | 1.112 |
Excel formula:
=AIRMASS({0,1.225;1000,1.112}, 90, 86400, 6371229, 1.000276)
Expected output:
96133.3
Example 4: Custom planet radius
Inputs:
| density_profile | angle | h_max | r_planet | ri | |
|---|---|---|---|---|---|
| 0 | 1.225 | 90 | 86400 | 7000000 | 1.000276 |
| 1000 | 1.112 |
Excel formula:
=AIRMASS({0,1.225;1000,1.112}, 90, 86400, 7000000, 1.000276)
Expected output:
96133.3
Python Code
Show Code
from fluids.atmosphere import airmass as fluids_airmass
def airmass(density_profile, angle, h_max=86400, r_planet=6371229, ri=1.000276):
"""
Calculate the mass of air per square meter in the atmosphere along a given angle using a density profile.
See: https://fluids.readthedocs.io/fluids.atmosphere.html
This example function is provided as-is without any representation of accuracy.
Args:
density_profile (list[list]): 2D array with elevation (m) in the first column and density (kg/m³) in the second column
angle (float): Angle above the horizon in degrees (0-90)
h_max (float, optional): Maximum height to integrate to (m) Default is 86400.
r_planet (float, optional): Radius of the planet (m) Default is 6371229.
ri (float, optional): Refractive index of the atmosphere Default is 1.000276.
Returns:
float: Mass of air per square meter (float), or error message string.
"""
# Helper to normalize 2D list input
def to2d(x):
return [[x]] if not isinstance(x, list) else x
try:
# Normalize density_profile input
density_profile = to2d(density_profile)
# Validate density_profile
if not isinstance(density_profile, list) or len(density_profile) < 2:
return "Error: density_profile must be a 2D list with at least two rows."
if not all(isinstance(row, list) and len(row) >= 2 for row in density_profile):
return "Error: density_profile must contain rows with at least two columns."
try:
heights = [float(row[0]) for row in density_profile]
densities = [float(row[1]) for row in density_profile]
except Exception:
return "Error: density_profile must contain numeric values."
if any(h2 <= h1 for h1, h2 in zip(heights, heights[1:])):
return "Error: heights in density_profile must be strictly increasing."
try:
gamma = float(angle)
h_max_val = float(h_max)
r_planet_val = float(r_planet)
ri_val = float(ri)
except Exception:
return "Error: angle, h_max, r_planet, and ri must be numbers."
if not (0 <= gamma <= 90):
return "Error: angle must be between 0 and 90 degrees."
if h_max_val <= 0:
return "Error: h_max must be positive."
if r_planet_val <= 0:
return "Error: r_planet must be positive."
if ri_val <= 0:
return "Error: ri must be positive."
# Linear interpolation function for density
def density_func(H):
if H <= heights[0]:
return densities[0]
if H >= heights[-1]:
return densities[-1]
for i in range(1, len(heights)):
if H < heights[i]:
h0, h1 = heights[i-1], heights[i]
d0, d1 = densities[i-1], densities[i]
return d0 + (d1 - d0) * (H - h0) / (h1 - h0)
return densities[-1]
result = fluids_airmass(density_func, gamma, h_max_val, r_planet_val, ri_val)
return result
except Exception as e:
return f"Error: {str(e)}"