Skip to content

Add referenceHumidity and observedHumidity parameters to altitudeFromPressureDifference - #44

Draft
oyve with Copilot wants to merge 3 commits into
mainfrom
copilot/improve-altitude-calculation
Draft

Add referenceHumidity and observedHumidity parameters to altitudeFromPressureDifference#44
oyve with Copilot wants to merge 3 commits into
mainfrom
copilot/improve-altitude-calculation

Conversation

Copilot AI commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Description

Enhances altitudeFromPressureDifference to accept separate humidity values at reference and observed altitudes. Since humidity varies with altitude, using distinct values for each level and averaging their virtual temperatures provides more accurate altitude calculations than a single uniform humidity.

Type of Change

  • New formula/feature (non-breaking change that adds functionality)

Related Issue

Addresses the question: "Could altitudeFromPressureDifference be improved even more having a referenceHumidity and a observedHumidity?"

Changes Made

  • Added referenceHumidity and observedHumidity optional parameters to altitudeFromPressureDifference
  • When both provided, calculates virtual temperature at each level using its respective pressure and humidity, then averages them
  • Maintains backward compatibility: existing relativeHumidity parameter still works unchanged
  • Priority order: separate humidities > single humidity > dry air
// Existing usage (unchanged)
const altitude = altitudeFromPressureDifference(101325, 89874, 0, 288.15, 60);

// New: separate humidity at each level (80% at reference, 40% at observed)
const altitude = altitudeFromPressureDifference(101325, 89874, 0, 288.15, undefined, 80, 40);

Formula Details (if applicable)

Formula Name

Hypsometric equation with humidity-varying virtual temperature

Scientific Source

Input Parameters

  • referencePressure: Pressure at reference altitude (Pa)
  • observedPressure: Pressure at observed altitude (Pa)
  • referenceAltitude: Known altitude (m), default 0
  • temperature: Average temperature (K), default 288.15
  • relativeHumidity: Single humidity for both levels (%), optional
  • referenceHumidity: Humidity at reference altitude (%), optional
  • observedHumidity: Humidity at observed altitude (%), optional

Output

  • Altitude in meters (m)

Validation

  • Tested against known reference values
  • Compared to scientific literature

Testing

Test Coverage

  • Added tests for new functionality
  • All tests pass locally (npm test)
  • Build succeeds (npm run build)

Test Results

Test Suites: 15 passed, 15 total
Tests:       229 passed, 229 total

Manual Testing

Added 8 new tests covering: separate humidity values, equal humidity matching single-humidity behavior, fallback to dry air when only one humidity provided, priority over single humidity, and extreme humidity differences.

Documentation

  • Added/updated JSDoc comments
  • Added usage examples (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have used the correct units (Kelvin for temperature, SI units for others)
  • I have verified backward compatibility (or documented breaking changes)

Breaking Changes

  • This PR introduces breaking changes

Performance Impact

  • No performance impact

Dependencies

  • No new dependencies

Reviewer Notes

  • Key files to review: src/formulas/altitude.ts, tests/formulas/altitude.test.ts
  • Areas needing special attention: Virtual temperature averaging approach for the layer
Original prompt

Could altitudeFromPressureDifference be improved even more having a referenceHumidity and a observedHumidity?


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 2, 2025 09:20
…PressureDifference

Co-authored-by: oyve <16225018+oyve@users.noreply.github.com>
…non-null assertions

Co-authored-by: oyve <16225018+oyve@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize altitude calculation using humidity input Add referenceHumidity and observedHumidity parameters to altitudeFromPressureDifference Dec 2, 2025
Copilot AI requested a review from oyve December 2, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants