Functions to compute relative humidity, absolute humidity, wet bulb temperature, given pressure and absolute temperature.
Find a file
2026-08-12 13:02:43 +01:00
resources I have not yet got the overall architecture right, but the functions are 2026-08-09 13:32:32 +01:00
src/humidity Added dew point; implemented actual vapour pressure, but don't have test data. 2026-08-12 13:02:43 +01:00
test/humidity Added dew point; implemented actual vapour pressure, but don't have test data. 2026-08-12 13:02:43 +01:00
.gitignore Initial commit 2026-08-08 14:33:32 +00:00
LICENSE Initial commit 2026-08-08 14:33:32 +00:00
project.clj Tidied up documentation. This is more or less ready for others to play with. 2026-08-11 19:21:08 +01:00
README.md Added dew point; implemented actual vapour pressure, but don't have test data. 2026-08-12 13:02:43 +01:00

humidity

Functions to compute relative humidity, absolute humidity, wet bulb temperature, and other values related to humidity of air, given partial data.

Purpose

I'm using this code to explore human survivability given global warming. The following essays of mine are relevant:

  1. The Everyone Dies Event Class
  2. The 'everyone dies' event comes home
  3. Extreme Heat
  4. Analysis of 2026 heatwaves UK

Status

Alpha-quality code. It more or less works but it isn't at all polished.

General architecture

The packet

The 'packet', in the terminology of this library, is a map which has bindings for some of the following keywords:

  1. :absolute-humidity grammes per metre3.
  2. :actual-vapour-pressure Pascals
  3. :dew-point-celsius
  4. :pressure-pascals
  5. :pressure-millibars
  6. :saturation-vapour-pressure Pascals
  7. :relative-humidity percentage, 0...100.
  8. :temperature assumed to be ° Celsius
  9. :temperature-celsius
  10. :temperature-kelvin
  11. :volume in metres3, relative to 1 at standard temperature and pressure.
  12. :wet-bulb-temperature in ° Celsius.

These keywords represent variables in the pressure equations, and they are all to a degree inter-related; so if you have (or can assume) some of them, you can compute others.

Rather than having a tangle of functions all of which call one another, which seemed likely to result in horrible messes and potential infinite recursion, there is one central function, humidity.core/resolution, which takes a partial packet and repeatedly tries to compute the values for more variables until it can compute no more, and then returns the enhanced packet.

Thus:

humidity.core=> (use 'humidity.core :reload)
nil
humidity.core=> (resolution :relative-humidity 100 :temperature-celsius 35)
{:relative-humidity 100, :temperature-celsius 35, :pressure-pascals 101325, :pressure-millibars 4053/4, :saturation-vapour-pressure 5622.488734516426, :temperature-kelvin 308.15, :absolute-humidity 3953.618101887827}

At present there are no checks to ensure that the packet makes sense.

Associated with each variable there is a namespace which contains a function that takes a packet, and, provided that packet contains enough information to compute that variable, returns a numeric value, else nil.

Developing

This is a fairly standard leiningen project. I anticipate that most Clojure developers will have leininen installed, even if they no longer use it much. Start a repl with

lein repl

and hook in your preferred editor as appropriate for that editor.

Testing

Tests are reasonably complets but all could do with more examples, especially around the crucial 35° C wet bulb area and towards the extremities of normal weather range. If you are contributing additional code, I would appreciate it being accompanied by tests.

I suggest running tests using

lein cloverage

As this gives not only pass/fail output, but also test coverage output.

Contributing

Pull requests are welcomed, provided they do not contain AI generated code. I'm not going to waste time debugging Claude's mess, my own is bad enough.

License

Copyright © 2026 Simon Brooke. Licensed under the GNU General Public License, version 2.0 or (at your option) any later version.