Computes: 1. :absolute-humidity 2. :actual-vapour-pressure 3. :dew-point-celsius 4. :pressure-millibars 5. :pressure-pascals 6. :relative-humidity 7. :saturation-vapour-pressure 8. :temperature-celsius 9. :temperature-kelvin 10. :volume 11. :wet-bulb-temperature |
||
|---|---|---|
| resources | ||
| src/humidity | ||
| test/humidity | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| project.clj | ||
| README.md | ||
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:
- The Everyone Dies Event Class
- The 'everyone dies' event comes home
- Extreme Heat
- 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:
:absolute-humiditygrammes per metre3.:actual-vapour-pressurePascals:dew-point-celsius:pressure-pascals:pressure-millibars:saturation-vapour-pressurePascals:relative-humiditypercentage, 0...100.:temperatureassumed to be ° Celsius:temperature-celsius:temperature-kelvin:volumein metres3, relative to 1 at standard temperature and pressure.:wet-bulb-temperaturein ° 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.