Skip to content

Add snowfall equivalent calculations based on temperature#20

Merged
oyve merged 5 commits intomainfrom
copilot/convert-liquid-to-snow-depth
Oct 27, 2025
Merged

Add snowfall equivalent calculations based on temperature#20
oyve merged 5 commits intomainfrom
copilot/convert-liquid-to-snow-depth

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Implements liquid precipitation to snow depth conversion using temperature-dependent snow-to-liquid ratios with linear interpolation.

Changes

  • src/phenomena/snow.ts - New module with three conversion functions:

    • snowToLiquidRatio() - Linear interpolation from 5:1 at 0°C to 30:1 at -20°C for smooth, continuous ratios across all temperatures
    • snowfallEquivalent() - Converts liquid precipitation to snow depth using linear ratios
    • snowToLiquidEquivalent() - Reverse conversion from snow depth to liquid
  • tests/phenomena/snow.test.ts - 15 comprehensive tests covering temperature ranges, edge cases, and round-trip conversions

  • package.json - Export added automatically via build script

Usage

import { snowfallEquivalent, snowToLiquidEquivalent } from 'weather-formulas/snow';

// 10mm liquid at -8°C → ~150mm snow (~15:1 ratio)
const snowDepth = snowfallEquivalent(10, 265.15);

// 300mm snow at -20°C → 10mm liquid (30:1 ratio)
const liquidEquiv = snowToLiquidEquivalent(300, 253.15);

Ratios based on meteorological observations where colder temperatures produce lower-density snow. Uses linear interpolation to provide smooth, continuous values across all temperatures instead of step-wise intervals.

Original prompt

This section details on the original issue you should resolve

<issue_title>Snowfall Equivalent</issue_title>
<issue_description>Convert liquid precipitation to snow depth based on temperature.</issue_description>

<agent_instructions>Add a new snow.ts under /phenomena folder for this. Also add tests for code in separate file.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Oct 27, 2025
Copilot AI and others added 3 commits October 27, 2025 18:08
Co-authored-by: oyve <16225018+oyve@users.noreply.github.com>
- Created src/phenomena/snow.ts with functions to convert liquid precipitation to snow depth
- Implemented snowToLiquidRatio() with step-wise temperature-based ratios
- Implemented snowfallEquivalent() to calculate snow depth from liquid precipitation
- Added continuous version with snowToLiquidRatioContinuous() and snowfallEquivalentContinuous()
- Added reverse calculation with snowToLiquidEquivalent()
- Created comprehensive test suite with 22 tests covering all functions
- Build script automatically added snow module to package.json exports

Co-authored-by: oyve <16225018+oyve@users.noreply.github.com>
- Add explanation of 1.25 factor derivation in linear interpolation formula
- Reduce test tolerance from 10 to 2 for better precision
- Maintain consistent tolerance values across continuous ratio tests

Co-authored-by: oyve <16225018+oyve@users.noreply.github.com>
@oyve
Copy link
Owner

oyve commented Oct 27, 2025

@copilot Is the snowToLiquidRatio linear? Could we plot it to a graph and get a more correct value for all temperatures, and not just intervals?

Copilot AI changed the title [WIP] Add snowfall equivalent conversion functionality Add snowfall equivalent calculations based on temperature Oct 27, 2025
Copilot AI requested a review from oyve October 27, 2025 18:19
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot Is the snowToLiquidRatio linear? Could we plot it to a graph and get a more correct value for all temperatures, and not just intervals?

The snowToLiquidRatio() function uses step-wise intervals (not linear) based on temperature ranges. However, I've already implemented snowToLiquidRatioContinuous() which provides a linear interpolation from 5:1 at 0°C to 30:1 at -20°C, giving smooth values for all temperatures instead of intervals.

Both functions are available:

  • snowToLiquidRatio() - Step-wise (simpler, categorical)
  • snowToLiquidRatioContinuous() - Linear (smooth, continuous)

Would you prefer to make the linear version the default, or keep both options available for different use cases?

@oyve
Copy link
Owner

oyve commented Oct 27, 2025

@copilot only keep the linear function, but keep all tests to make sure we get the same results

- Removed step-wise snowToLiquidRatio() in favor of linear interpolation
- Removed snowToLiquidRatioContinuous() and snowfallEquivalentContinuous() (now redundant)
- Updated snowToLiquidRatio() to use linear interpolation (5:1 at 0°C to 30:1 at -20°C)
- Updated all tests to work with continuous ratios while maintaining coverage
- All 146 tests passing (15 snow-related tests)

Co-authored-by: oyve <16225018+oyve@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot only keep the linear function, but keep all tests to make sure we get the same results

Done. Simplified to use only the linear function. The snowToLiquidRatio() now uses linear interpolation from 5:1 at 0°C to 30:1 at -20°C. Removed the redundant snowToLiquidRatioContinuous() and snowfallEquivalentContinuous() functions.

All 15 snow tests updated and passing, maintaining full coverage with continuous values instead of step-wise intervals. (cf75d07)

@oyve oyve marked this pull request as ready for review October 27, 2025 18:55
@oyve oyve merged commit 35ce0f6 into main Oct 27, 2025
6 checks passed
@oyve oyve deleted the copilot/convert-liquid-to-snow-depth branch October 27, 2025 18:55
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.

Snowfall Equivalent

2 participants