Skip to content

Commit

Permalink
Merge pull request #23 from oyve/v2.1.5
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
oyve authored May 18, 2021
2 parents 8f36312 + b72ecc4 commit 7940659
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 327 deletions.
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
![Node.js CI](https://github.com/oyve/barometer-trend/workflows/Node.js%20CI/badge.svg)
# barometer-trend
Calculate the trend of a barometer over a three hour period.
Calculate the tendency and trend of a barometer for a one to three hour period with barometric weather predictions.

## Features
Gets the suggested:
- Tendency and trend of the barometer for the *last hour* or *three hours* (`FALLNG|SLOWLY`)
- Front system tendency, passage and wind analyze based on the latest three hours. (`Falling before a lesser rise` | `Cold front passage` | `Strong and gusty, then veers`)
- Force wind expectation in Beaufort scale based on the ratio of pressure increase/decrease (`F8-9`)
- Prediction of weather by ratio of increase/decrease trend (`Expect gale force weather'`)
- Prediction of weather by pressure tendency, threshold and wind direction (`Increasing rain, clearing within 12 hours.`)
- Prediction of weather by pressure threshold for winter|summer (`Cloudy and humid, thunderstorms`)
- Tendency and trend of the barometer for the *last hour* or *three hours* (`FALLNG|SLOWLY`)-
- Prediction of weather and systems:
- By pressure tendency only (`Expect gale force weather'`)
- By pressure tendency, thresholds and wind direction (`Increasing rain, clearing within 12 hours.`)
- By seasonal pressure thresholds for winter and summer (`Cloudy and humid, thunderstorms`)
- Front system tendency for the last three hours (`Falling before a lesser rise` | `Cold front passage` | `Strong and gusty, then veers`)
- Force wind expectation in Beaufort scale based on the pressure tendency (`F8-9`)
- Detects current pressure system `Low`, `Normal`, `High`

Note
- All calculations corrected to sea level pressure by optional `altitude` and `temperature`
- 48 hour history

## Install & Use
```
Expand All @@ -22,27 +26,28 @@ const barometer = require('barometer-trend');
barometer.addPressure(datetime1, 101500);
barometer.addPressure(datetime2, 101505);
barometer.addPressure(datetime3, 101512, 100, 20, 225); //100 = altitude, 20 = C degrees, 225 = wind direction - enables more calculations (or give NULL for each seperately)
barometer.addPressure(datetime3, 101512, 100, 20, 225); //100 = altitude, 20 = C degrees, 225 = wind direction
let forecast = barometer.getPredictions();
//barometer.addPressure(...) is more presice when pressure is corrected by altitude and temperature.
let forecast = barometer.getPredictions(); //returns JSON
```

## Note
- Pressure must be in Pascals, 1015 mBar/hPa = 101500 Pascal.
- Pressure readings older than *three hours* are automatically removed.
- Pressure must be input in Pascals, 1015 mBar/hPa = 101500 Pascal.
- `getPredictions()` investigate the trend for the latest *one hour* and *three hours*
- If run less than *one hour* or *three hours*, the latest timing up until now is picked.
- The most recent trend with the highest severity is chosen.
- The most recent trend with the highest severity is chosen (*One hour* or *Three hour* reading)

## Contribute
Feel free to create a Pull Request including test code.
Feel free to contribute; create an Issue, and Pull Request including test code.

## Disclaimer
- All calculations is done by online research; the author of this library does not have a background in metereology. All sources listed below.
- A barometer is only *one source of weather information* and may give a general trend and indication, but not "see" the overall picture. (There's a reason satelittes exists and being a metereologist is a paid job.)
- All calculations presumes being located at sea with no disturbances.
- Near land, winds may be one-two Beaufort scale numbers lower and the wind might be coming from "the wrong direction".
- In subtropic and tropical regions some of the calculations may not be valid at all; i.e. the tradewind system is different from northern hemishpere west->east low pressure systems.
- In subtropic and tropical regions some of the calculations may not be valid at all; i.e. the trade winds (easterlies) is different from northern hemishpere west->east (westerlies) low pressure systems.
- In trade wind zones observe the daily variations; any change to this pattern could possibly indicate gale weather.

## Sources / References
Expand Down
39 changes: 26 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const byPressureTrendAndSeason = require('./predictions/byPressureTrendAndSeason
const beaufort = require('./predictions/beaufort')
const trend = require('./trend');
const utils = require('./utils');
const history = require('./predictions/history');
const system = require('./predictions/system');

let pressures = [];

Expand All @@ -29,24 +31,26 @@ function hasPressures() {
* @param {number} trueWindDirection True wind direction in degrees
*/
function addPressure(datetime, pressure, altitude = null, temperature = null, trueWindDirection = null) {
if (trueWindDirection !== null && trueWindDirection === 360) trueWindDirection = 0;
if (altitude === null) altitude = 0;
if (temperature === null) temperature = 15 + utils.KELVIN;
if (temperature === null) temperature = utils.toKelvinFromCelcius(15);
if (trueWindDirection !== null && trueWindDirection === 360) trueWindDirection = 0;

if (altitude > 0) {
pressure = utils.adjustPressureToSeaLevel(pressure, altitude, temperature);
}
let pressureASL = utils.adjustPressureToSeaLevel(pressure, altitude, temperature);

pressures.push({
datetime: datetime,
value: pressure,
twd: trueWindDirection
value: pressureASL,
meta: {
value: pressure,
altitude: altitude,
temperature: temperature,
twd: trueWindDirection
}
});

removeOldPressures();
}


/**
* Get the count of pressure entries. (Mainly for testing purposes)
* @returns {number} Number of pressure entries
Expand All @@ -55,15 +59,20 @@ function getPressureCount() {
return pressures.length;
}

function removeOldPressures(threshold) {
var threshold = utils.minutesFromNow(-utils.MINUTES.THREE_HOURS);
function removeOldPressures(threshold = null) {
if (threshold === null) {
threshold = utils.minutesFromNow(-utils.MINUTES.FORTYEIGHT_HOURS);
}

pressures = pressures.filter((p) => p.datetime.getTime() >= threshold.getTime());
}

function getLastPressure() {
return pressures[pressures.length - 1];
}



/**
* Get the trend of the barometer
* @param {boolean} isNorthernHemisphere Located north of equator? Default true.
Expand All @@ -74,16 +83,20 @@ function getPredictions(isNorthernHemisphere = true) {

let lastPressure = getLastPressure();

var pressureTrend = trend.getTrend(pressures);
let pressureTrend = trend.getTrend(pressures);
let pressureSystem = system.getSystemByPressure(lastPressure.value);
let pressureHistory = history.getHistoricPressures(pressures);
let predictionPressureOnly = byPressureTrend.getPrediction(pressureTrend.tendency, pressureTrend.trend);
let predictionFront = front.getFront(pressures);
let predictionBeaufort = beaufort.getByPressureVariationRatio(pressureTrend.ratio);
let predictionSeason = byPressureTrendAndSeason.getPrediction(lastPressure.value, pressureTrend.tendency, pressureTrend.trend, utils.isSummer(isNorthernHemisphere))
let predictionPressureTendencyThresholdAndQuadrant = byPressureTendencyAndWind.getPrediction(lastPressure.value, lastPressure.twd, pressureTrend.tendency, pressureTrend.trend, isNorthernHemisphere);
let predictionPressureTendencyThresholdAndQuadrant = byPressureTendencyAndWind.getPrediction(lastPressure.value, lastPressure.meta.twd, pressureTrend.tendency, pressureTrend.trend, isNorthernHemisphere);

let forecast = {
lastPressure: lastPressure,
history: pressureHistory,
trend: pressureTrend,
indicator: "Please update JSON, see latest documentation",
system: pressureSystem,
predictions: {
pressureOnly: predictionPressureOnly,
quadrant: predictionPressureTendencyThresholdAndQuadrant,
Expand Down
Loading

0 comments on commit 7940659

Please sign in to comment.