@@ -337,6 +337,94 @@ def gueymard94_pw(temp_air, relative_humidity):
337337 return pw
338338
339339
340+ def rh_from_tdew (temperature , dewpoint , coeff = (6.112 , 17.62 , 243.12 )):
341+ """
342+ Calculate relative humidity from dewpoint temperatureusing Magnus equation.
343+ This function was used by First Solar in creating their spectral model
344+ and is therefore relevant to the first solar spectral model in pvlib.
345+ Default magnus equation coefficients are from [2].
346+
347+ Parameters
348+ ----------
349+ temperature : numeric
350+ Air temperature in degrees Celsius
351+ dewpoint : numeric
352+ Dewpoint temperature in degrees Celsius
353+ coeff: tuple
354+ Magnus equation coefficient (A, B, C)
355+
356+ Returns
357+ -------
358+ pd.Series
359+ Relative humidity as percentage (0-100)
360+
361+ Notes
362+ -----
363+ Uses the AEKR coefficients which minimize errors between -40 and
364+ 50 degrees C according to reference [1].
365+
366+ References
367+ ----------
368+ .. [1] https://www.osti.gov/servlets/purl/548871-PjpxAP/webviewable/
369+ .. [2] https://www.schweizerbart.de//papers/metz/detail/3/89544/Advancements_in_the_field_of_hygrometry?af=crossref
370+ """
371+
372+ # Calculate vapor pressure (e) and saturation vapor pressure (es)
373+ e = coeff [0 ] * np .exp ((coeff [1 ] * temperature ) / (coeff [2 ] + temperature ))
374+ es = coeff [0 ] * np .exp ((coeff [1 ] * dewpoint ) / (coeff [2 ] + dewpoint ))
375+
376+ # Calculate relative humidity as percentage
377+ relative_humidity = 100 * (es / e )
378+
379+ return relative_humidity
380+
381+
382+ def tdew_from_rh (
383+ temperature , relative_humidity , coeff = (6.112 , 17.62 , 243.12 )
384+ ):
385+ """
386+ Calculate dewpoint temperature using Magnus equation with
387+ AEKR coefficients. This is just a reversal of the calculation
388+ in calculate_relative_humidity.
389+
390+ Parameters
391+ ----------
392+ temperature : numeric
393+ Air temperature in degrees Celsius
394+ relative_humidity : numeric
395+ Relative humidity as percentage (0-100)
396+
397+ Returns
398+ -------
399+ pd.Series
400+ Dewpoint temperature in degrees Celsius
401+
402+ Notes
403+ -----
404+ Derived by solving the Magnus equation for dewpoint given
405+ relative humidity.
406+ Valid for temperatures between -40 and 50 degrees C.
407+
408+ References
409+ ----------
410+ .. [1] https://www.osti.gov/servlets/purl/548871-PjpxAP/webviewable/
411+ """
412+ # Calculate the term inside the log
413+ # From RH = 100 * (es/e), we get es = (RH/100) * e
414+ # Substituting the Magnus equation and solving for dewpoint
415+
416+ # First calculate ln(es/A)
417+ ln_term = (
418+ (coeff [1 ] * temperature ) / (coeff [2 ] + temperature )
419+ + np .log (relative_humidity / 100 )
420+ )
421+
422+ # Then solve for dewpoint
423+ dewpoint = coeff [2 ] * ln_term / (coeff [1 ] - ln_term )
424+
425+ return dewpoint
426+
427+
340428first_solar_spectral_correction = deprecated (
341429 since = '0.10.0' ,
342430 alternative = 'pvlib.spectrum.spectral_factor_firstsolar'
0 commit comments