Compare commits
2 commits
37689df3e2
...
507a365682
| Author | SHA1 | Date | |
|---|---|---|---|
| 507a365682 | |||
| 91343b9c10 |
15 changed files with 374 additions and 69 deletions
|
|
@ -11,12 +11,12 @@ partial data.
|
||||||
The 'packet', in the terminology of this library, is a map which has bindings
|
The 'packet', in the terminology of this library, is a map which has bindings
|
||||||
for some of the following keywords:
|
for some of the following keywords:
|
||||||
|
|
||||||
1. `:actual-humidity`
|
1. `:absolute-humidity`
|
||||||
2. `:actual-vapour-pressure
|
2. `:actual-vapour-pressure` *not yet implemented*
|
||||||
1. `:dew-point`
|
1. `:dew-point`
|
||||||
2. `:pressure-pascals`
|
2. `:pressure-pascals`
|
||||||
3. `:pressure-millibars`
|
3. `:pressure-millibars`
|
||||||
4. `:saturation-pressure`
|
4. `:saturation--vapour-pressure`
|
||||||
5. `:relative-humidity`
|
5. `:relative-humidity`
|
||||||
6. `:temperature`
|
6. `:temperature`
|
||||||
7. `:temperature-celsius`
|
7. `:temperature-celsius`
|
||||||
|
|
|
||||||
23
project.clj
23
project.clj
|
|
@ -1,7 +1,18 @@
|
||||||
(defproject humidity "0.1.0-SNAPSHOT"
|
(defproject humidity "0.1.0-SNAPSHOT"
|
||||||
:description "FIXME: write description"
|
:cloverage {:output "docs/cloverage"
|
||||||
:url "http://example.com/FIXME"
|
:ns-exclude-regex [#"beowulf\.gendoc" #"beowulf\.scratch"]}
|
||||||
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
|
:codox {:metadata {:doc "**TODO**: write docs"
|
||||||
:url "https://www.eclipse.org/legal/epl-2.0/"}
|
:doc/format :markdown}
|
||||||
:dependencies [[org.clojure/clojure "1.11.1"]]
|
:output-path "docs/codox"
|
||||||
:repl-options {:init-ns humidity.core})
|
:source-uri "https://github.com/simon-brooke/humidity/blob/master/{filepath}#L{line}"}
|
||||||
|
:dependencies [[org.clojure/clojure "1.12.5"]]
|
||||||
|
:description "Functions to compute relative humidity, absolute humidity, wet bulb
|
||||||
|
temperature, and other values related to humidity of air, given
|
||||||
|
partial data."
|
||||||
|
:license {:name "GPL-2.0-or-later"
|
||||||
|
:url "https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"}
|
||||||
|
:repl-options {:init-ns humidity.core}
|
||||||
|
:plugins [[lein-ancient "1.0.0"]
|
||||||
|
[lein-cloverage "1.2.2"]
|
||||||
|
[lein-codox "0.10.8"]]
|
||||||
|
:url "https://git.journeyman.cc/simon/humidity")
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,32 @@
|
||||||
(ns ^{:doc "Function to calculate wet bulb temperature (in ° C) given temperature in
|
(ns ^{:doc "Function to calculate absolute humidity in grammes per
|
||||||
° C and relative-humidity percentage (0...100).
|
metre<sup>3</sup> given temperature in ° K, saturation vapour pressure
|
||||||
|
in Pascals, and relative humidity as a percentage (0...100)."
|
||||||
See [authority](https://carnotcycle.wordpress.com/2012/08/04/how-to-convert-relative-humidity-to-absolute-humidity/)"}
|
:authority "https://carnotcycle.wordpress.com/2012/08/04/how-to-convert-relative-humidity-to-absolute-humidity/"
|
||||||
|
:author "simon"}
|
||||||
humidity.absolute
|
humidity.absolute
|
||||||
(:require
|
(:require
|
||||||
[humidity.constants :refer [Rw]]))
|
[humidity.constants :refer [Rw]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;; Absolute Humidity (grams/m3) = 6.112 × e^[(17.67 × T)/(T+243.5)] × rh × 2.1674
|
;; Absolute Humidity (grams/m3) = 6.112 × e^[(17.67 × T)/(T+243.5)] × rh × 2.1674
|
||||||
;; -----
|
;; -----
|
||||||
|
|
@ -18,20 +40,14 @@
|
||||||
|
|
||||||
(def C magic-numbers)
|
(def C magic-numbers)
|
||||||
|
|
||||||
;; (defn abs-humidity
|
(defn abs-humidity
|
||||||
;; "Returns absolute humidity in grammes per cubic metre given this
|
"calculate and return absolute humidity in grammes per metre<sup>3</sup>
|
||||||
;; `temperature` in ° C and `relative-hunidity` percentage (0...100).
|
given temperature in ° K, saturation vapour pressure in Pascals, and
|
||||||
;; "
|
relative humidity as a percentage (0...100)."
|
||||||
;; [temperature relative-humidity]
|
[& {:keys [relative-humidity saturation-vapour-pressure temperature-kelvin]}]
|
||||||
;; (when (empty? (filter false? (map number? [temperature relative-humidity])))
|
|
||||||
;; (let [T temperature
|
|
||||||
;; RHP relative-humidity]
|
|
||||||
;; (/ (* (C 1) (pow (* (/ (C 2) T) (+ T (C 3))) e) RHP (C 4))
|
|
||||||
;; (+ celsius-offset temperature)))))
|
|
||||||
|
|
||||||
;; AH=(RH × Ps)/(Rw × T × 100)
|
|
||||||
|
|
||||||
(defn abs-humidity [& {:keys [relative-humidity saturation-vapour-pressure temperature-kelvin]}]
|
|
||||||
(when (and relative-humidity saturation-vapour-pressure temperature-kelvin)
|
(when (and relative-humidity saturation-vapour-pressure temperature-kelvin)
|
||||||
;; I don't know why I'm having to multiply by a thousand here...
|
;; I don't know why I'm having to multiply by a thousand here...
|
||||||
(* (/ (* relative-humidity saturation-vapour-pressure) Rw temperature-kelvin) 1000)))
|
(*
|
||||||
|
(/
|
||||||
|
(* relative-humidity saturation-vapour-pressure) Rw temperature-kelvin)
|
||||||
|
1000)))
|
||||||
|
|
|
||||||
|
|
@ -1 +1,23 @@
|
||||||
(ns humidity.actual-vp)
|
(ns humidity.actual-vp)
|
||||||
|
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,26 @@
|
||||||
(ns humidity.constants)
|
(ns ^{:doc "Constants used in humidity calculations."
|
||||||
|
:author "simon"} humidity.constants)
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:const celsius-offset
|
(def ^:const celsius-offset
|
||||||
"Value of 0° Celsius in ° Kelvin"
|
"Value of 0° Celsius in ° Kelvin"
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,71 @@
|
||||||
(ns humidity.core
|
(ns ^{:doc "Central resolver function for humidity calculations"
|
||||||
|
:author "simon"}
|
||||||
|
humidity.core
|
||||||
(:require [humidity.absolute :refer [abs-humidity]]
|
(:require [humidity.absolute :refer [abs-humidity]]
|
||||||
[humidity.constants :refer [celsius-offset Pa]]
|
[humidity.constants :refer [celsius-offset Pa]]
|
||||||
[humidity.relative :refer [rel-humidity]]
|
[humidity.relative :refer [rel-humidity]]
|
||||||
[humidity.saturation-vp :as saturation-vp]
|
[humidity.saturation-vp :refer [saturation-vp]]
|
||||||
[humidity.utils :refer [?assoc]]
|
[humidity.utils :refer [?assoc]]
|
||||||
[humidity.wet-bulb :refer [wet-bulb-temperature]]))
|
[humidity.wet-bulb :as wb]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn resolve-humidity
|
(defn resolve-humidity
|
||||||
"Resolve humidity equations given the data in this packet."
|
"Resolve humidity equations given the data in this packet."
|
||||||
[& {:keys [temperature temperature-celsius temperature-kelvin relative-humidity
|
[& {:keys [absolute-humidity pressure-pascals pressure-millibars
|
||||||
pressure-pascals pressure-millibars saturation-vapour-pressure] :as packet}]
|
relative-humidity saturation-vapour-pressure temperature
|
||||||
|
temperature-celsius temperature-kelvin wet-bulb-temperature] :as packet}]
|
||||||
(println packet)
|
(println packet)
|
||||||
(if temperature (resolve-humidity (assoc (dissoc packet :temperature) :temperature-celsius temperature))
|
(if temperature (resolve-humidity
|
||||||
|
(assoc (dissoc packet :temperature)
|
||||||
|
:temperature-celsius temperature))
|
||||||
(?assoc packet
|
(?assoc packet
|
||||||
|
:absolute-humidity (when-not absolute-humidity
|
||||||
|
(abs-humidity packet))
|
||||||
|
:pressure-pascals (when-not pressure-pascals
|
||||||
|
(if pressure-millibars
|
||||||
|
(* pressure-millibars 100) Pa))
|
||||||
|
:pressure-millibars (when-not pressure-millibars
|
||||||
|
(if pressure-pascals
|
||||||
|
(/ pressure-pascals 100) (/ Pa 100)))
|
||||||
|
:relative-humidity (when-not relative-humidity
|
||||||
|
(rel-humidity packet))
|
||||||
|
:saturation-vapour-pressure (when-not saturation-vapour-pressure
|
||||||
|
(saturation-vp packet))
|
||||||
:temperature-celsius (when
|
:temperature-celsius (when
|
||||||
(and temperature-kelvin (not temperature-celsius))
|
(and temperature-kelvin
|
||||||
|
(not temperature-celsius))
|
||||||
(- temperature-kelvin celsius-offset))
|
(- temperature-kelvin celsius-offset))
|
||||||
:temperature-kelvin (when
|
:temperature-kelvin (when
|
||||||
(and temperature-celsius (not temperature-kelvin))
|
(and temperature-celsius
|
||||||
|
(not temperature-kelvin))
|
||||||
(+ temperature-celsius celsius-offset))
|
(+ temperature-celsius celsius-offset))
|
||||||
:wet-bulb-temperature (when
|
:wet-bulb-temperature (when-not wet-bulb-temperature
|
||||||
(and temperature-celsius relative-humidity)
|
(wb/wet-bulb-temperature packet)))))
|
||||||
(wet-bulb-temperature temperature-celsius relative-humidity))
|
|
||||||
:absolute-humidity (abs-humidity :relative-humidity relative-humidity
|
|
||||||
:saturation-vapour-pressure saturation-vapour-pressure
|
|
||||||
:temperature-kelvin temperature-kelvin)
|
|
||||||
:pressure-pascals (when-not pressure-pascals
|
|
||||||
(if pressure-millibars (* pressure-millibars 100) Pa))
|
|
||||||
:pressure-millibars (when-not pressure-millibars
|
|
||||||
(if pressure-pascals (/ pressure-pascals 100) (/ Pa 100)))
|
|
||||||
:relative-humidity (when-not relative-humidity (rel-humidity packet))
|
|
||||||
:saturation-vapour-pressure (saturation-vp/saturation-vp packet))))
|
|
||||||
|
|
||||||
|
|
||||||
(defn resolution
|
(defn resolution
|
||||||
"Repeatedly run `resolve-humidity`, q.v., until we can infer no further
|
"Repeatedly run `resolve-humidity`, q.v., until we can infer no further
|
||||||
information."
|
information."
|
||||||
[packet]
|
[& {:keys [] :as packet}]
|
||||||
(loop [p packet]
|
(loop [p packet]
|
||||||
(let [p' (resolve-humidity p)]
|
(let [p' (resolve-humidity p)]
|
||||||
(if (= (keys p) (keys p')) p
|
(if (= (keys p) (keys p')) p
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,27 @@
|
||||||
(:require [humidity.constants :refer [e Rw]]
|
(:require [humidity.constants :refer [e Rw]]
|
||||||
[humidity.utils :refer [expt]]))
|
[humidity.utils :refer [expt]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:const magic-numbers
|
(def ^:const magic-numbers
|
||||||
"The magic numbers (empirical constants) from the derived expression. It
|
"The magic numbers (empirical constants) from the derived expression. It
|
||||||
bothers me that all these formulae depend on 'empirical constants', *and*
|
bothers me that all these formulae depend on 'empirical constants', *and*
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,27 @@
|
||||||
(:require [clojure.math :refer [pow]]
|
(:require [clojure.math :refer [pow]]
|
||||||
[humidity.constants :refer [celsius-offset e]]))
|
[humidity.constants :refer [celsius-offset e]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn saturation-vp-tetens
|
(defn saturation-vp-tetens
|
||||||
"Calculate and return saturation vapour pressure in Pa using Tetens'
|
"Calculate and return saturation vapour pressure in Pa using Tetens'
|
||||||
formula, given temerature in ° Celsius."
|
formula, given temerature in ° Celsius."
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,27 @@
|
||||||
(ns ^{:doc "Utility functions for humidity calculation"} humidity.utils
|
(ns ^{:doc "Utility functions for humidity calculation"
|
||||||
|
:author "simon"} humidity.utils
|
||||||
(:require [clojure.math :refer [pow]]))
|
(:require [clojure.math :refer [pow]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defmacro expt
|
(defmacro expt
|
||||||
"Clojure.math `pow` function does not allow ratios as exponents;
|
"Clojure.math `pow` function does not allow ratios as exponents;
|
||||||
|
|
@ -16,4 +37,4 @@
|
||||||
(partition 2)
|
(partition 2)
|
||||||
(filter second)
|
(filter second)
|
||||||
(map vec)
|
(map vec)
|
||||||
(into m)))
|
(into m)))
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,27 @@
|
||||||
(:require [clojure.math :refer [atan]]
|
(:require [clojure.math :refer [atan]]
|
||||||
[humidity.utils :refer [expt]]))
|
[humidity.utils :refer [expt]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(def ^:const magic-numbers
|
(def ^:const magic-numbers
|
||||||
"The magic numbers (empirical constants) from the derived expression. It
|
"The magic numbers (empirical constants) from the derived expression. It
|
||||||
bothers me that all these formulae depend on 'empirical constants', *and*
|
bothers me that all these formulae depend on 'empirical constants', *and*
|
||||||
|
|
@ -17,11 +38,13 @@
|
||||||
(defn wet-bulb-temperature
|
(defn wet-bulb-temperature
|
||||||
"Returns wet bulb temperature (in ° C) given this `temperature` in
|
"Returns wet bulb temperature (in ° C) given this `temperature` in
|
||||||
° C and `relative-humidity` percentage (0...100)"
|
° C and `relative-humidity` percentage (0...100)"
|
||||||
[temperature relative-humidity]
|
[&{:keys [temperature relative-humidity]}]
|
||||||
(let [T temperature
|
(when
|
||||||
|
(and temperature relative-humidity)
|
||||||
|
(let [T temperature
|
||||||
RHP relative-humidity]
|
RHP relative-humidity]
|
||||||
(+ (* T (atan (* (C 1) (expt (+ RHP (C 2)) 1/2))))
|
(+ (* T (atan (* (C 1) (expt (+ RHP (C 2)) 1/2))))
|
||||||
(atan (+ T RHP))
|
(atan (+ T RHP))
|
||||||
(- 0 (atan (- RHP (C 3))))
|
(- 0 (atan (- RHP (C 3))))
|
||||||
(* (C 4) (expt RHP 3/2) (atan (* (C 5) RHP)))
|
(* (C 4) (expt RHP 3/2) (atan (* (C 5) RHP)))
|
||||||
(- 0 (C 6)))))
|
(- 0 (C 6))))))
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,26 @@
|
||||||
(:require [clojure.test :refer [deftest is testing]]
|
(:require [clojure.test :refer [deftest is testing]]
|
||||||
[humidity.constants :refer [celsius-offset]]
|
[humidity.constants :refer [celsius-offset]]
|
||||||
[humidity.absolute :refer [abs-humidity]]))
|
[humidity.absolute :refer [abs-humidity]]))
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(deftest absolute-humidity-test
|
(deftest absolute-humidity-test
|
||||||
(testing "definitional"
|
(testing "definitional"
|
||||||
|
|
|
||||||
38
test/humidity/core_test.clj
Normal file
38
test/humidity/core_test.clj
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
(ns humidity.core-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer [deftest is testing]]
|
||||||
|
[humidity.core :refer [resolution]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(deftest resolution-test
|
||||||
|
(testing "resolution")
|
||||||
|
(let [expected {: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}
|
||||||
|
packet {:relative-humidity 100 :temperature-celsius 35}
|
||||||
|
actual (resolution packet)]
|
||||||
|
(is (= actual expected))))
|
||||||
|
|
@ -3,6 +3,27 @@
|
||||||
[humidity.constants :refer [celsius-offset]]
|
[humidity.constants :refer [celsius-offset]]
|
||||||
[humidity.relative :refer [rel-humidity rel-humidity]]))
|
[humidity.relative :refer [rel-humidity rel-humidity]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(deftest relative-humidity-test
|
(deftest relative-humidity-test
|
||||||
(testing "definitional"
|
(testing "definitional"
|
||||||
(let [min-expected 99
|
(let [min-expected 99
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,31 @@
|
||||||
(ns humidity.saturation-vp-test(:require [clojure.test :refer [deftest is testing]]
|
(ns humidity.saturation-vp-test
|
||||||
[humidity.constants :refer [celsius-offset]]
|
(:require [clojure.test :refer [deftest is testing]]
|
||||||
[humidity.saturation-vp :refer [saturation-vp saturation-vp-tetens]]))
|
[humidity.saturation-vp :refer [saturation-vp]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(deftest saturation-vp-test
|
(deftest saturation-vp-test
|
||||||
(testing "from online sources"
|
(testing "from online sources"
|
||||||
(let [min-expected 5622
|
(let [min-expected 5622
|
||||||
max-expected 5629
|
max-expected 5629
|
||||||
actual (saturation-vp {:temperature-celsius 35})]
|
actual (saturation-vp {:temperature-celsius 35})]
|
||||||
(is (< min-expected actual max-expected)))))
|
(is (< min-expected actual max-expected)))))
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,33 @@
|
||||||
(:require [clojure.test :refer [deftest is testing]]
|
(:require [clojure.test :refer [deftest is testing]]
|
||||||
[humidity.wet-bulb :refer [wet-bulb-temperature]]))
|
[humidity.wet-bulb :refer [wet-bulb-temperature]]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Copyright (C) 2026 Simon Brooke
|
||||||
|
;;;
|
||||||
|
;;; This program is free software; you can redistribute it and/or
|
||||||
|
;;; modify it under the terms of the GNU General Public License
|
||||||
|
;;; as published by the Free Software Foundation; either version 2
|
||||||
|
;;; of the License, or (at your option) any later version.
|
||||||
|
;;;
|
||||||
|
;;; This program is distributed in the hope that it will be useful,
|
||||||
|
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
;;; GNU General Public License for more details.
|
||||||
|
;;;
|
||||||
|
;;; You should have received a copy of the GNU General Public License
|
||||||
|
;;; along with this program; if not, write to the Free Software
|
||||||
|
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
;;; USA.
|
||||||
|
;;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(deftest wet-bulb-test
|
(deftest wet-bulb-test
|
||||||
(testing "Example from paper"
|
(testing "Example from paper"
|
||||||
(let [expected 13.7
|
(let [expected 13.7
|
||||||
temperature 20
|
temperature 20
|
||||||
rel-humidity 50
|
rel-humidity 50
|
||||||
actual (wet-bulb-temperature temperature rel-humidity)]
|
actual (wet-bulb-temperature :temperature temperature :relative-humidity rel-humidity)]
|
||||||
(println (format "Expected: %s; actual: %s" expected actual))
|
(println (format "Expected: %s; actual: %s" expected actual))
|
||||||
(is (< (abs (- expected actual)) 0.001))))
|
(is (< (abs (- expected actual)) 0.001))))
|
||||||
|
|
||||||
|
|
@ -17,7 +37,7 @@
|
||||||
max-expected 33
|
max-expected 33
|
||||||
temperature 37
|
temperature 37
|
||||||
rel-humidity 70
|
rel-humidity 70
|
||||||
actual (wet-bulb-temperature temperature rel-humidity)]
|
actual (wet-bulb-temperature :temperature temperature :relative-humidity rel-humidity)]
|
||||||
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
||||||
(is (< min-expected actual max-expected)))
|
(is (< min-expected actual max-expected)))
|
||||||
|
|
||||||
|
|
@ -25,7 +45,7 @@
|
||||||
max-expected 36
|
max-expected 36
|
||||||
temperature 39.7
|
temperature 39.7
|
||||||
rel-humidity 70
|
rel-humidity 70
|
||||||
actual (wet-bulb-temperature temperature rel-humidity)]
|
actual (wet-bulb-temperature :temperature temperature :relative-humidity rel-humidity)]
|
||||||
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
||||||
(is (< min-expected actual max-expected)))
|
(is (< min-expected actual max-expected)))
|
||||||
|
|
||||||
|
|
@ -34,7 +54,7 @@
|
||||||
max-expected 34
|
max-expected 34
|
||||||
temperature 40
|
temperature 40
|
||||||
rel-humidity 60
|
rel-humidity 60
|
||||||
actual (wet-bulb-temperature temperature rel-humidity)]
|
actual (wet-bulb-temperature :temperature temperature :relative-humidity rel-humidity)]
|
||||||
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
||||||
(is (< min-expected actual max-expected)))
|
(is (< min-expected actual max-expected)))
|
||||||
|
|
||||||
|
|
@ -42,6 +62,6 @@
|
||||||
max-expected 35
|
max-expected 35
|
||||||
temperature 51
|
temperature 51
|
||||||
rel-humidity 30
|
rel-humidity 30
|
||||||
actual (wet-bulb-temperature temperature rel-humidity)]
|
actual (wet-bulb-temperature :temperature temperature :relative-humidity rel-humidity)]
|
||||||
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
(println (format "Expected: %s...%s; actual: %s" min-expected max-expected actual))
|
||||||
(is (< min-expected actual max-expected)))))
|
(is (< min-expected actual max-expected)))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue