Skip to content

Instantly share code, notes, and snippets.

@dfrommi
Last active October 18, 2020 12:48
Show Gist options
  • Select an option

  • Save dfrommi/7c7cc366d602612f6fa361f1251c48c5 to your computer and use it in GitHub Desktop.

Select an option

Save dfrommi/7c7cc366d602612f6fa361f1251c48c5 to your computer and use it in GitHub Desktop.
Calculation of Dew-point and Absolute Humidity #util

Calculation of Dew-point and Absolute Humidity

Dew-Point and absolute humidity can be calculated from temperature in celsius and relative humidity.

The Barometer class expects both values as inputs and calculates absolute humidity af and dew-point td.

import kotlin.math.log10
import kotlin.math.pow
data class Barometer(val r: Double, val t: Double) {
// Konstanten
private val mw = 18.016 // Molekulargewicht des Wasserdampfes (kg/kmol)
private val gk = 8214.3 // universelle Gaskonstante (J/(kmol*K))
private val t0 = 273.15 // Absolute Temperatur von 0 °C (Kelvin)
private val a = if (t >= 0.0) 7.5 else 7.6
private val b = if (t >= 0.0) 237.3 else 240.7
// Temperatur in Kelvin
private val tk = t + t0
// Sättigungsdampfdruck (hPa)
private val sdd = 6.1078 * 10.0.pow((a * t) / (b + t))
// Dampfdruck (hPa)
private val dd = sdd * (r / 100.0)
// Absolute Feuchte (g/m3)
val af = 10.0.pow(5) * mw / gk * dd / tk
// Taupunkttemperatur (°C)
val td = log10(dd / 6.1078).let { v -> (b * v) / (a - v) }
override fun toString() = "[r = $r, t = $t, af = $af, td = $td]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment