128 lines
5.6 KiB
Markdown
128 lines
5.6 KiB
Markdown
# Introduction
|
|
|
|
## Disclaimer
|
|
|
|
This library is supplied in the hope that it may be useful, but results computed with it should not be taken as authoritative but should be checked against other sources. I do not have enough expertise to guarantee its results are correct.
|
|
|
|
## 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 metre<sup>3</sup>.*
|
|
2. `:actual-vapour-pressure` *Pascals*
|
|
1. `:dew-point-celsius`
|
|
2. `:pressure-pascals`
|
|
3. `:pressure-millibars`
|
|
4. `:relative-humidity` *percentage, 0...100.*
|
|
5. `:saturation-vapour-pressure` *Pascals*
|
|
6. `:temperature` *assumed to be ° Celsius*
|
|
7. `:temperature-celsius`
|
|
8. `:temperature-kelvin`
|
|
9. `:volume` *in metres<sup>3</sup>, relative to 1 at standard temperature and pressure.*
|
|
10. `:wet-bulb-temperature-celsius` *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:
|
|
|
|
```clojure
|
|
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}
|
|
```
|
|
|
|
### Naming
|
|
|
|
Associated with each variable there is a namespace of the same name which contains a function, whose name is the name of the variable with `-fn` appended, that takes a packet, and, provided that packet contains enough information to compute that variable, returns a numeric value, else `nil`.
|
|
|
|
### Validation
|
|
|
|
A packet may be validated by calling the function `validate`. This recalculates all values in the packet, and, by default, tolerates discrepancies of up to 1%. This tolerance can be varied by binding the dynamic variable `*validation-limit*`. Validation merely checks that the values within the packet are consistent with one another, and does not properly account for pressure, so will not be valid at altitude.
|
|
|
|
```clojure
|
|
humidity.core=> (validate {:absolute-humidity 3953.618101887827,
|
|
#_=> :actual-vapour-pressure 4765.10094206357,
|
|
#_=> :dew-point-celsius 35.00000000000001,
|
|
#_=> :pressure-millibars 1013.25,
|
|
#_=> :pressure-pascals 101325,
|
|
#_=> :relative-humidity 100,
|
|
#_=> :saturation-vapour-pressure 5622.488734516426,
|
|
#_=> :temperature-celsius 35,
|
|
#_=> :temperature-kelvin 308.15,
|
|
#_=> :volume 1.1281347245103424,
|
|
#_=> :wet-bulb-temperature-celsius 35.11625928298915}
|
|
#_=> )
|
|
true
|
|
|
|
humidity.core=> (validate {:absolute-humidity 3953.618101887827,
|
|
#_=> :actual-vapour-pressure 4765.10094206357,
|
|
#_=> :dew-point-celsius 35.00000000000001,
|
|
#_=> :pressure-millibars 1013.25,
|
|
#_=> :pressure-pascals 101325,
|
|
#_=> :relative-humidity 95, ;; <-- intentionally wrong
|
|
#_=> :saturation-vapour-pressure 5622.488734516426,
|
|
#_=> :temperature-celsius 35,
|
|
#_=> :temperature-kelvin 308.15,
|
|
#_=> :volume 1.1281347245103424,
|
|
#_=> :wet-bulb-temperature-celsius 35.11625928298915}
|
|
#_=> )
|
|
ERROR: key: :dew-point-celsius; a: 35.00000000000001; b 34.07737599732603; errror: 2.857142925262451%.
|
|
false
|
|
|
|
humidity.core=> (binding [*validation-limit* 5]
|
|
#_=> (validate {:absolute-humidity 3953.618101887827,
|
|
#_=> :actual-vapour-pressure 4765.10094206357,
|
|
#_=> :dew-point-celsius 35.00000000000001,
|
|
#_=> :pressure-millibars 1013.25,
|
|
#_=> :pressure-pascals 101325,
|
|
#_=> :relative-humidity 95, ;; <-- intentionally wrong
|
|
#_=> :saturation-vapour-pressure 5622.488734516426,
|
|
#_=> :temperature-celsius 35,
|
|
#_=> :temperature-kelvin 308.15,
|
|
#_=> :volume 1.1281347245103424,
|
|
#_=> :wet-bulb-temperature-celsius 35.11625928298915}))
|
|
true
|
|
```
|
|
|
|
## Developing
|
|
|
|
This is a fairly standard [leiningen](https://leiningen.org/) 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.
|
|
|
|
Full documentation is available [here](https://www.journeyman.cc/humidity).
|
|
|
|
## 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.
|
|
|
|
Current test results are [here](cloverage/index.html), for comparison.
|
|
|
|
## 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.
|