001 (ns ^{:doc "Function to calculate wet bulb temperature (in ° C) given temperature in
002 ° C and relative-humidity percentage (0...100)"
003 :author "simon"}
004 humidity.wet-bulb-temperature-celsius
005 (:require [clojure.math :refer [atan]]
006 [humidity.utils :refer [expt]]))
007
008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
009 ;;;
010 ;;; Copyright (C) 2026 Simon Brooke
011 ;;;
012 ;;; This program is free software; you can redistribute it and/or
013 ;;; modify it under the terms of the GNU General Public License
014 ;;; as published by the Free Software Foundation; either version 2
015 ;;; of the License, or (at your option) any later version.
016 ;;;
017 ;;; This program is distributed in the hope that it will be useful,
018 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
019 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020 ;;; GNU General Public License for more details.
021 ;;;
022 ;;; You should have received a copy of the GNU General Public License
023 ;;; along with this program; if not, write to the Free Software
024 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
025 ;;; USA.
026 ;;;
027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
028 (def ^:const magic-numbers
029 "The magic numbers (empirical constants) from the derived expression. It
030 bothers me that all these formulae depend on 'empirical constants', *and*
031 that there is no commonality between the empirical constants of different
032 formulae."
033 [0 0.151977 8.313659 1.676331 0.00391838 0.023101 4.686035])
034
035 (def C magic-numbers)
036
037 (defn wet-bulb-temperature-celsius-fn
038 "Returns wet bulb temperature (in ° C) given this `temperature` in
039 ° C and `relative-humidity` percentage (0...100)"
040 [& {:keys [temperature-celsius relative-humidity]}]
041 (when
042 (and temperature-celsius relative-humidity)
043 (let [T temperature-celsius
044 RHP relative-humidity]
045 (+ (* T (atan (* (C 1) (expt (+ RHP (C 2)) 1/2))))
046 (atan (+ T RHP))
047 (- 0 (atan (- RHP (C 3))))
048 (* (C 4) (expt RHP 3/2) (atan (* (C 5) RHP)))
049 (- 0 (C 6))))))