JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 69
  • Score
    100M100P100Q82190F
  • License GPL-3.0-or-later

A collection of atmospheric, meteorological weather calculations

Package Exports

  • weather-formulas
  • weather-formulas/airDensity
  • weather-formulas/beaufort
  • weather-formulas/diurnalRythm
  • weather-formulas/humidity
  • weather-formulas/pressure
  • weather-formulas/saffirSimpson
  • weather-formulas/temperature
  • weather-formulas/wind

Readme

License: GPL v3 Node.js CI

weather-formulas

A library of atmospheric and weather-related calculations.

  • Includes test code for all formulas.
  • Supports custom valuation sets where applicable.
  • Supports both ES Module (ESM) and CommonJS (CJS).

Table of Contents

Features

Temperature

  • Dew Point: Calculate the dew point using the Magnus formula or Arden Buck equation.
  • Wind Chill: Estimate the perceived temperature based on wind speed and air temperature.
  • (Australian) Apparent Temperature: Calculate the apparent temperature considering humidity and wind.
  • Heat Index: Measure the perceived temperature based on air temperature and humidity.
  • Humidex: Calculate the humidex, a Canadian measure of perceived temperature.
  • Potential Temperature: Calculate the temperature an air parcel would have if brought to a standard pressure.
  • Virtual Temperature: Calculate the temperature accounting for water vapor in the air.
  • Lapse Rate: Calculate the rate of temperature change with altitude.
  • Dynamic lapse rate: Calculate the lapse rate dynamically based on readings.
  • Weighted Average Temperature: Calculate the weighted average temperature based on altitude differences.
  • Adjust Temperature by Lapse Rate: Adjust temperature based on a fixed lapse rate.

Humidity

Pressure

  • Pressure Altitude: Calculate the altitude based on observed pressure.
  • Density Altitude: Calculate the altitude adjusted for temperature and air density.
  • Barometric Formula: Calculate pressure at a given altitude using the barometric formula.
  • Adjust Pressure To Sea Level:
    • Simple formula: A quick approximation for standard conditions.
    • Advanced formula: A more accurate calculation using the barometric formula.
    • By dynamic lapse rate: Adjust pressure using a dynamically calculated lapse rate.
    • By historical data: Adjust pressure using historical readings.

Wind

  • Wind Direction: Convert wind direction in degrees to compass direction.
  • Wind Power Density: Calculate wind power density in watts per square meter.
  • Wind Force: Calculate wind force in kilograms per square meter.
  • Adjust Wind Speed for Altitude: Adjust wind speed between different altitudes based on air density.
  • Apparent Wind: Calculate the wind speed and direction experienced by a moving observer (e.g., vessel or vehicle).

Air Density

Scales

Install

Install the library using npm:

$ npm install weather-formulas

How to Use

ES Modules (ESM)

If your project is configured to use ES Modules (e.g., "type": "module" in package.json), you can use the import syntax to load the package:

import { temperature, humidity, pressure, wind, airDensity } from 'weather-formulas';

// Example usage
const RH = humidity.relativeHumidity(298.15, 293.15); // 25°C and 20°C in Kelvin
console.log(`Relative Humidity: ${RH}%`);

CommonJS (CJS)

If your project uses CommonJS (e.g., no "type": "module" in package.json), you can use the require syntax to load the package:

const { temperature, humidity, pressure, wind, airDensity } = require('weather-formulas');

// Example usage
const RH = humidity.relativeHumidity(298.15, 293.15); // 25°C and 20°C in Kelvin
console.log(`Relative Humidity: ${RH}%`);

Advanced Examples

Use a provided valuation set:

const valuationSet = temperature.DEW_POINT_VALUATIONS.DAVID_BOLTON;
const actual = temperature.dewPointMagnusFormula(298.15, 60, valuationSet); // 25°C and 60% humidity
console.log(`Dew Point: ${actual} K`);

Use a custom valuation set:

const valuationSet = { a: 6, b: 17, c: 250, d: 234.5 };
const actual = temperature.dewPointArdenBuckEquation(298.15, 60, valuationSet); // 25°C and 60% humidity
console.log(`Dew Point: ${actual} K`);

Inspect code/tests for all possibilities.

Testing

All formulas are covered by automated tests.
Run tests with:

npm test

Compatibility

  • Requires Node.js 18+.
  • Fully typed with TypeScript (v5+).
  • Supports both ES Modules (ESM) and CommonJS (CJS).

Contribute

Please feel free to contribute by creating a Pull Request including test code, or by suggesting other formulas.

License

This project is licensed under the GPL v3 License.

Support

For support, please open an issue in the GitHub repository.

Disclaimer

Always verify calculations before using in production as edge cases due to floating point errors may exist for large numbers, and which may not be covered by tests today. Please report any issues.