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
| Name | Required | Description | Default |
|---|---|---|---|
| pressure_altitude_ft | Yes | ||
| temperature_c | Yes | ||
| dewpoint_c | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
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. """ - aerospace_mcp/fastmcp_server.py:230-230 (registration)Registration as an MCP tool via mcp.tool(density_altitude_calculator) in the FastMCP server.
mcp.tool(density_altitude_calculator) - aerospace_mcp/cli.py:149-149 (registration)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, }