Skip to main content
Glama

density_altitude_calculator

Calculate density altitude from pressure altitude and temperature for accurate aircraft performance assessment.

Instructions

Calculate density altitude from pressure altitude and temperature.

Density altitude is the altitude in the standard atmosphere at which the air density equals the actual air density at the given conditions. Essential for aircraft performance calculations.

Args: pressure_altitude_ft: Pressure altitude in feet temperature_c: Outside air temperature in Celsius dewpoint_c: Optional dewpoint for humidity correction

Returns: Formatted string with density altitude calculation results including air density, density ratio (sigma), pressure ratio (delta), and ISA deviation.

Raises: No exceptions are raised directly; errors are returned as formatted strings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pressure_altitude_ftYes
temperature_cYes
dewpoint_cNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The actual tool handler function. Takes pressure_altitude_ft, temperature_c, and optional dewpoint_c, computes density altitude using ISA barometric formulas with humidity correction, returns a formatted string with results.
    def density_altitude_calculator(
        pressure_altitude_ft: float,
        temperature_c: float,
        dewpoint_c: float | None = None,
    ) -> str:
        """Calculate density altitude from pressure altitude and temperature.
    
        Density altitude is the altitude in the standard atmosphere at which
        the air density equals the actual air density at the given conditions.
        Essential for aircraft performance calculations.
    
        Args:
            pressure_altitude_ft: Pressure altitude in feet
            temperature_c: Outside air temperature in Celsius
            dewpoint_c: Optional dewpoint for humidity correction
    
        Returns:
            Formatted string with density altitude calculation results including
            air density, density ratio (sigma), pressure ratio (delta), and ISA
            deviation.
    
        Raises:
            No exceptions are raised directly; errors are returned as formatted strings.
        """
        try:
            # Convert to SI
            pressure_alt_m = pressure_altitude_ft * 0.3048
            temp_k = temperature_c + 273.15
    
            # ISA temperature at pressure altitude
            if pressure_alt_m <= 11000:
                isa_temp_k = T0 - LAPSE_RATE * pressure_alt_m
            else:
                isa_temp_k = 216.65  # Tropopause temperature
    
            # Temperature deviation from ISA
            delta_isa = temp_k - isa_temp_k
    
            # Calculate actual pressure from pressure altitude using the ISA
            # barometric formula. Pressure altitude is defined as the altitude in
            # the ISA that corresponds to the observed station pressure.
            if pressure_alt_m <= 11000:
                # Troposphere barometric formula: P = P0 * (1 - L*h/T0)^(g/(R*L))
                p = P0 * (1 - LAPSE_RATE * pressure_alt_m / T0) ** (
                    G0 / (R_AIR * LAPSE_RATE)
                )
            else:
                # Isothermal layer above tropopause
                p_trop = P0 * (1 - LAPSE_RATE * 11000 / T0) ** (G0 / (R_AIR * LAPSE_RATE))
                p = p_trop * math.exp(-G0 * (pressure_alt_m - 11000) / (R_AIR * 216.65))
    
            # Calculate actual density
            rho = p / (R_AIR * temp_k)
    
            # Humidity correction (optional)
            humidity_correction_ft = 0
            if dewpoint_c is not None:
                # Approximate humidity correction using dewpoint spread
                spread = temperature_c - dewpoint_c
                # Higher humidity (smaller spread) increases density altitude
                humidity_correction_ft = max(0, (30 - spread) * 3)  # Rough approximation
    
            # Find density altitude by solving for the altitude in the ISA where
            # the standard density equals the actual density computed above.
            # Simplified approximation: each 1 deg C above ISA increases density
            # altitude by approximately 118.8 ft (derived from the ISA lapse rate
            # and the barometric formula linearization).
            density_alt_ft = (
                pressure_altitude_ft + (delta_isa * 118.8) + humidity_correction_ft
            )
    
            # Calculate density altitude in meters
            density_alt_m = density_alt_ft * 0.3048
    
            # Recalculate ISA conditions at density altitude for verification
            _isa_at_da = _get_isa_conditions(density_alt_m)
    
            result = {
                "input": {
                    "pressure_altitude_ft": pressure_altitude_ft,
                    "pressure_altitude_m": round(pressure_alt_m, 1),
                    "temperature_c": temperature_c,
                    "dewpoint_c": dewpoint_c,
                },
                "density_altitude_ft": round(density_alt_ft, 0),
                "density_altitude_m": round(density_alt_m, 0),
                "air_density_kg_m3": round(rho, 5),
                "density_ratio_sigma": round(rho / RHO0, 5),
                "pressure_ratio_delta": round(p / P0, 5),
                "isa_deviation_c": round(delta_isa, 1),
                "isa_temp_at_pressure_alt_c": round(isa_temp_k - 273.15, 1),
                "humidity_correction_ft": round(humidity_correction_ft, 0),
            }
    
            output = f"""
    DENSITY ALTITUDE CALCULATION
    ============================
    Input Conditions:
      Pressure Altitude: {pressure_altitude_ft:,.0f} ft ({pressure_alt_m:,.0f} m)
      Temperature: {temperature_c:.1f}°C
      ISA Temperature at PA: {isa_temp_k - 273.15:.1f}°C
      ISA Deviation: {delta_isa:+.1f}°C
      Dewpoint: {dewpoint_c if dewpoint_c else "Not specified"}°C
    
    Results:
      Density Altitude: {density_alt_ft:,.0f} ft ({density_alt_m:,.0f} m)
      Air Density: {rho:.5f} kg/m³
      Density Ratio (σ): {rho / RHO0:.5f}
      Pressure Ratio (δ): {p / P0:.5f}
    
    Performance Impact:
      {"⚠️ HIGH DENSITY ALTITUDE - Reduced engine and aerodynamic performance" if density_alt_ft > 5000 else "✓ Normal performance expected"}
    
    {json.dumps(result, indent=2)}
    """
            return output.strip()
    
        except Exception as e:
            logger.error(f"Density altitude calculation error: {str(e)}", exc_info=True)
            return f"Error calculating density altitude: {str(e)}"
  • Function signature and docstring define input parameters (pressure_altitude_ft: float, temperature_c: float, dewpoint_c: float | None = None) and return type (str).
    def density_altitude_calculator(
        pressure_altitude_ft: float,
        temperature_c: float,
        dewpoint_c: float | None = None,
    ) -> str:
        """Calculate density altitude from pressure altitude and temperature.
    
        Density altitude is the altitude in the standard atmosphere at which
        the air density equals the actual air density at the given conditions.
        Essential for aircraft performance calculations.
    
        Args:
            pressure_altitude_ft: Pressure altitude in feet
            temperature_c: Outside air temperature in Celsius
            dewpoint_c: Optional dewpoint for humidity correction
    
        Returns:
            Formatted string with density altitude calculation results including
            air density, density ratio (sigma), pressure ratio (delta), and ISA
            deviation.
    
        Raises:
            No exceptions are raised directly; errors are returned as formatted strings.
        """
  • Registration as an MCP tool via mcp.tool(density_altitude_calculator) in the FastMCP server.
    mcp.tool(density_altitude_calculator)
  • Registration in CLI tool map under 'density_altitude_calculator' key.
    "density_altitude_calculator": density_altitude_calculator,
  • ISA helper function _get_isa_conditions() used by the handler to compute standard atmospheric conditions at a given altitude.
    def _get_isa_conditions(altitude_m: float) -> dict:
        """Get ISA atmospheric conditions at a given geopotential altitude.
    
        Uses the barometric formula to compute pressure, temperature, density,
        and speed of sound. The troposphere (0-11 km) has a linear temperature
        lapse; the tropopause/lower stratosphere (11-20 km) is isothermal.
    
        Args:
            altitude_m: Geopotential altitude in meters. Negative values are
                clamped to 0.
    
        Returns:
            Dict with pressure_pa, temperature_k, temperature_c, density_kg_m3,
            speed_of_sound_ms, and dimensionless ratios (pressure, density,
            temperature) relative to sea-level ISA values.
        """
        if altitude_m < 0:
            altitude_m = 0
    
        if altitude_m <= 11000:
            # Troposphere (0 to 11 km): linear temperature decrease.
            # T = T0 - L * h  where L = LAPSE_RATE = 0.0065 K/m
            T = T0 - LAPSE_RATE * altitude_m
            # Barometric formula for troposphere (with lapse rate):
            # P = P0 * (T / T0) ^ (g0 / (R * L))
            # Exponent g0/(R*L) = 9.80665 / (287.05 * 0.0065) = 5.2559
            P = P0 * (T / T0) ** (G0 / (R_AIR * LAPSE_RATE))
        else:
            # Tropopause / lower stratosphere (11 km+): isothermal at 216.65 K.
            # First compute conditions at the tropopause boundary (11 km).
            T_trop = T0 - LAPSE_RATE * 11000  # 216.65 K
            P_trop = P0 * (T_trop / T0) ** (G0 / (R_AIR * LAPSE_RATE))
            T = T_trop
            # Barometric formula for isothermal layer:
            # P = P_trop * exp(-g0 * (h - h_trop) / (R * T_trop))
            P = P_trop * math.exp(-G0 * (altitude_m - 11000) / (R_AIR * T_trop))
    
        # Ideal gas law: rho = P / (R * T)
        rho = P / (R_AIR * T)
        # Speed of sound in an ideal gas: a = sqrt(gamma * R * T)
        a = math.sqrt(GAMMA * R_AIR * T)
    
        return {
            "pressure_pa": P,
            "temperature_k": T,
            "temperature_c": T - 273.15,
            "density_kg_m3": rho,
            "speed_of_sound_ms": a,
            "pressure_ratio": P / P0,
            "density_ratio": rho / RHO0,
            "temperature_ratio": T / T0,
        }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description bears full burden. Describes inputs, output format (formatted string), and error handling (errors returned as strings). Missing side effects or computational limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with a brief opening, definition, and docstring-style Args/Returns/Raises. Front-loaded with core purpose, though Returns section is slightly verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers purpose, parameters, output (formatted string with specific values), and error handling. Output schema exists, so return values are partly defined. Lacks output units and validity ranges.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but description adds units and meaning for all three parameters: pressure_altitude_ft in feet, temperature_c in Celsius, dewpoint_c optional for humidity correction. Goes well beyond schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the tool calculates density altitude from pressure altitude and temperature, with a definition and significance. Distinct from siblings like stall_speed_calculator.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Mentions essential for aircraft performance calculations but does not specify when to use vs alternatives or exclusion conditions. No guidance on when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cheesejaguar/aerospace-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server