AIRMASS

Overview

The AIRMASS function calculates the optical air mass (mass of atmosphere per unit area) along a specified viewing angle, which is essential for solar irradiance calculations, atmospheric optics, and astronomical observations. Air mass quantifies how much atmosphere sunlight or other radiation must traverse—it is minimum when looking straight up (angle 90° above the horizon) and increases as the viewing angle approaches the horizon, with the air mass approaching 40x or greater near the horizon due to the oblique path length.

The function wraps the fluids library’s airmass function, which performs numerical integration of the density-weighted path integral over the atmosphere using SciPy’s quad integrator. It computes the total air mass using the formula accounting for atmospheric refraction:

m(\gamma) = \int_0^\infty \rho \left\{1 - \left[1 + 2(\text{RI}-1)\left(1-\frac{\rho}{\rho_0}\right)\right]\left[\frac{\cos \gamma}{1+h/R}\right]^2\right\}^{-1/2} dH

where \gamma is the angle above the horizon in degrees, \text{RI} is the refractive index of the atmosphere (approximately 1.000276 for air on Earth at 0.7 µm wavelength), h is elevation, and R is the planet’s radius. The algorithm is based on the work of Kasten and Young (1989), which provides revised optical air mass tables and approximation formulas.

A user-provided density profile (elevation vs. density) enables modeling different atmospheric conditions or planetary atmospheres. Applications include calculating solar panel irradiance (higher air mass reduces direct beam intensity), predicting astronomical observation quality, assessing atmospheric effects on satellite signals, and modeling radiation attenuation. Default parameters use Earth’s characteristics (radius 6,371,229 m, standard refractive index), but these can be customized for other planets or specific conditions.

This example function is provided as-is without any representation of accuracy.

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 column
  • angle (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.

Examples

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

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

import micropip
await micropip.install(["fluids"])
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

    # 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."
    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)
    except Exception:
        return "Error: angle must be a number."
    if not (0 <= gamma <= 90):
        return "Error: angle must be between 0 and 90 degrees."
    # 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]

    try:
        result = fluids_airmass(density_func, gamma, h_max, r_planet, ri)
    except Exception as e:
        return f"Error: {e}"

    return result

Online Calculator