Skip to content

Commit 77025c7

Browse files
Kurt RheeKurt Rhee
authored andcommitted
set default magnus coefficients per conversation in #1744
1 parent f62bd8e commit 77025c7

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

pvlib/spectrum/magnus_tetens.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import numpy as np
22

33

4-
def magnus_tetens_aekr(temperature, dewpoint):
4+
def magnus_tetens_aekr(temperature, dewpoint, A=6.112, B=17.62, C=243.12):
55
"""
66
Calculate relative humidity using Magnus equation with AEKR coefficients.
77
This function was used by First Solar in creating their spectral model
88
and is therefore relevant to the first solar spectral model in pvlib.
9+
Default magnus equation coefficients are from [2].
910
1011
Parameters
1112
----------
1213
temperature : pd.Series
1314
Air temperature in degrees Celsius
1415
dewpoint : pd.Series
1516
Dewpoint temperature in degrees Celsius
17+
A: float
18+
Magnus equation coefficient A
19+
B: float
20+
Magnus equation coefficient B
21+
C: float
22+
Magnus equation coefficient C
1623
1724
Returns
1825
-------
@@ -27,23 +34,22 @@ def magnus_tetens_aekr(temperature, dewpoint):
2734
References
2835
----------
2936
.. [1] https://www.osti.gov/servlets/purl/548871-PjpxAP/webviewable/
37+
.. [2] https://www.schweizerbart.de//papers/metz/detail/3/89544/Advancements_in_the_field_of_hygrometry?af=crossref
3038
"""
31-
# Magnus equation coefficients (AEKR)
32-
MAGNUS_A = 6.1094
33-
MAGNUS_B = 17.625
34-
MAGNUS_C = 243.04
3539

3640
# Calculate vapor pressure (e) and saturation vapor pressure (es)
37-
e = MAGNUS_A * np.exp((MAGNUS_B * temperature) / (MAGNUS_C + temperature))
38-
es = MAGNUS_A * np.exp((MAGNUS_B * dewpoint) / (MAGNUS_C + dewpoint))
41+
e = A * np.exp((B * temperature) / (C + temperature))
42+
es = A * np.exp((B * dewpoint) / (C + dewpoint))
3943

4044
# Calculate relative humidity as percentage
4145
relative_humidity = 100 * (es / e)
4246

4347
return relative_humidity
4448

4549

46-
def reverse_magnus_tetens_aekr(temperature, relative_humidity):
50+
def reverse_magnus_tetens_aekr(
51+
temperature, relative_humidity, B=17.62, C=243.12
52+
):
4753
"""
4854
Calculate dewpoint temperature using Magnus equation with
4955
AEKR coefficients. This is just a reversal of the calculation
@@ -71,22 +77,18 @@ def reverse_magnus_tetens_aekr(temperature, relative_humidity):
7177
----------
7278
.. [1] https://www.osti.gov/servlets/purl/548871-PjpxAP/webviewable/
7379
"""
74-
# Magnus equation coefficients (AEKR)
75-
MAGNUS_B = 17.625
76-
MAGNUS_C = 243.04
77-
7880
# Calculate the term inside the log
7981
# From RH = 100 * (es/e), we get es = (RH/100) * e
8082
# Substituting the Magnus equation and solving for dewpoint
8183

82-
# First calculate ln(es/MAGNUS_A)
84+
# First calculate ln(es/A)
8385
ln_term = (
84-
(MAGNUS_B * temperature) / (MAGNUS_C + temperature)
86+
(B * temperature) / (C + temperature)
8587
+ np.log(relative_humidity/100)
8688
)
8789

8890
# Then solve for dewpoint
89-
dewpoint = MAGNUS_C * ln_term / (MAGNUS_B - ln_term)
91+
dewpoint = C * ln_term / (B - ln_term)
9092

9193
return dewpoint
9294

0 commit comments

Comments
 (0)