/// <summary> /// Calculates the relative humidity (RH) for the given ambient temperature and dew/frost point. /// </summary> /// <param name="temperature">The ambient temperature.</param> /// <param name="dewPoint">The dewpoint or frostpoint temperature.</param> /// <param name="formula">The folmula to use for calculation.</param> /// <returns>The relative humidity in range from 0% to 100%.</returns> public static double CalculateRelativeHumidity(double temperature, double dewPoint, RelativeHumidityFormula formula = RelativeHumidityFormula.WMO) { switch (formula) { case RelativeHumidityFormula.Rough: return(CalculateRelativeHumidityRough(temperature, dewPoint)); case RelativeHumidityFormula.Nasa: return(dewPoint >= 0 ? CalculateRelativeHumidityNasaOverWater(temperature, dewPoint) : CalculateRelativeHumidityNasaOverIce(temperature, dewPoint)); case RelativeHumidityFormula.NasaOverWater: return(CalculateRelativeHumidityNasaOverWater(temperature, dewPoint)); case RelativeHumidityFormula.NasaOverIce: return(CalculateRelativeHumidityNasaOverIce(temperature, dewPoint)); case RelativeHumidityFormula.WMO: return(dewPoint >= -60 ? CalculateRelativeHumidityWMOOverWater(temperature, dewPoint) : CalculateRelativeHumidityWMOOverIce(temperature, dewPoint)); case RelativeHumidityFormula.WMOOverWater: return(CalculateRelativeHumidityWMOOverWater(temperature, dewPoint)); case RelativeHumidityFormula.WMOOverIce: return(CalculateRelativeHumidityWMOOverIce(temperature, dewPoint)); default: throw new ArgumentOutOfRangeException(nameof(formula), formula, null); } }
public void Mixed(double t, double d, double expectedRh, double accuracy, RelativeHumidityFormula formula) { var rh = HumidityCalculator.CalculateRelativeHumidity(t, d, formula); var min = Math.Max(expectedRh * (1 - accuracy), 0); var max = Math.Min(expectedRh * (1 + accuracy), 100); Assert.InRange(rh, min, max); }
/// <summary> /// Calculates the relative humidity (RH) from the METAR report. /// </summary> /// <param name="metar">The metar report.</param> /// <param name="formula">The folmula to use for calculation.</param> /// <returns>The relative humidity in range from 0% to 100%.</returns> public static double CalculateRelativeHumidity(this Metar metar, RelativeHumidityFormula formula = RelativeHumidityFormula.WMO) { return(CalculateRelativeHumidity(metar.Temperature, metar.DewPoint, formula)); }