This package primarily provides some weather/atmospheric-related calculations. It also provides types for these calculations to traffic, helping to reduce the chance of mixing up units.
For example, these types prevent accidentally using a Celsius temperature as a Fahrenheit temperature:
Documentation: pkg.go.dev/github.com/cdzombak/libwx
go get github.com/cdzombak/libwx
DewPointF()
and DewPointC()
calculate the dew point, given a temperature and relative humidity.
IndoorHumidityRecommendationF()
and IndoorHumidityRecommendationC()
provide a recommended maximum indoor humidity percentage for the given outdoor temperature.
WindChillF()
and WindChillC()
calculate the wind chill, given the outdoor temperature and wind speed.
The wind chill formula works given temperatures less than 50ºF and wind speeds greater than 3 mph. To calculate wind chill but return an error if the input is outside this range, use WindChillFWithValidation()
and WindChillCWithValidation()
. These functions return ErrInputRange
if the input is out of the formula's input range.
WetBulbF()
and WetBulbC()
calculate the wet bulb temperature, given the dry bulb temperature and relative humidity.
This formula is taken from "Wet-Bulb Temperature from Relative Humidity and Air Temperature" (Roland Stull, Journal of Applied Meteorology and Climatology, 2011) and assumes standard sea level pressure.
These functions return ErrInputRange
if the input is out of the formula's input range.
HeatIndexFWithValidation()
and HeatIndexCWithValidation()
calculate the heat index, given a temperature and relative humidity.
HeatIndexWarningF()
and HeatIndexWarningC()
provide a warning level based on the heat index. These warning levels are based on the NOAA's heat index table:
HeatIndexWarningNone
indicates the heat index does not warrant elevated caution.HeatIndexWarningCaution
indicates fatigue is possible with prolonged exposure and activity. Continuing activity could result in heat cramps.HeatIndexWarningExtremeCaution
indicates heat cramps and heat exhaustion are possible. Continuing activity could result in heat stroke.HeatIndexWarningDanger
indicates heat cramps and heat exhaustion are likely; heat stroke is probable with continued activity.HeatIndexWarningExtremeDanger
indicates heat stroke is imminent.
The following distance types are provided:
Mile
Meter
Km
(kilometer)NauticalMile
Each type provides methods to convert to the other types (e.g. NauticalMile.Meters()
). An Unwrap()
method also exists to get the raw value as a float64
.
The RelHumidity
type is an integer type representing a relative humidity percentage from 0-100
, inclusive. A clamping method and function for this range are provided.
An Unwrap()
method also exists to get the raw value as an int
; UnwrapFloat64()
returns the value as a float64
.
The following pressure types are provided:
PressureInHg
(inches of mercury)PressureMb
(millibars)
Each type provides methods to convert to the other type (e.g. PressureInHg.Mb()
). An Unwrap()
method also exists to get the raw value as a float64
.
The following speed types are provided:
SpeedMph
(miles per hour)SpeedKmh
(kilometers per hour)SpeedKnots
(knots)
Each type provides methods to convert to the other types (e.g. SpeedKnots.Mph()
). An Unwrap()
method also exists to get the raw value as a float64
.
The following temperature types are provided:
Each type provides methods to convert to the other type (e.g. TempF.C()
). An Unwrap()
method also exists to get the raw value as a float64
.
Finally, libwx
provides some utility functions for comparing float64
and int
values:
IntCompare(a, b int) int
Float64Compare(a, b, tolerance float64) int
Float64Equal(a, b, tolerance float64) bool
The *Compare(…)
functions return:
-1
ifa < b
0
ifa == b
1
ifa > b
For float64
comparisons functions that accept a tolerance
, convenience tolerance constants are provided:
ToleranceExact = float64(0.0)
Tolerance0 = float64(1.0)
Tolerance1 = float64(0.1)
Tolerance01 = float64(0.01)
Tolerance001 = float64(0.001)
When making repeated comparisons with the same tolerance, having to pass the tolerance each time is tedious and increases room for human error. To help with this, curried versions of Float64Compare()
and Float64Equal()
are provided. These return a comparison function with the specified tolerance baked-in:
CurriedFloat64Compare(tolerance float64) func(float64, float64) int
CurriedFloat64Equal(tolerance float64) func(float64, float64) bool
For example:
package main
import (
wx "github.com/cdzombak/libwx"
)
function main() {
equalityChecker := wx.CurriedFloat64Equal(Tolerance1)
equalityChecker(1.0, 1.11) // => false
equalityChecker(1.0, 1.01) // => true
}
MIT; see LICENSE in this repo.
Chris Dzombak