Skip to content

Commit 320ac6b

Browse files
committed
* Fix for issue #782
- Validity checks with new kwargs min_pw and max_pw - Note added in docstring of epw.read_epw() concerning TMY3.epw files from energyplus.net - corresponding tests
1 parent a8ab9aa commit 320ac6b

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

docs/sphinx/source/whatsnew/v0.7.0.rst

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ API Changes
8383
- Methods `PVSystem.ashraeiam`, `PVSystem.physicaliam` and
8484
`PVSystem.sapm_aoi_loss` are deprecated and will be removed in v0.8.
8585

86+
* Changes related to spectral modifier (:issue:`782`):
87+
* Changes to functions
88+
- Added the argument `pw_min` and `pw_max`, default values 0.1 and 8 resp.,
89+
to `atmosphere.first_solar_spectral_correction`. This function now returns NaN
90+
if pw value higher than `pw_max`.
91+
8692
* Calling :py:func:`pvlib.pvsystem.retrieve_sam` with no parameters will raise
8793
an exception instead of displaying a dialog.
8894
* The `times` keyword argument has been deprecated in the
@@ -145,6 +151,8 @@ Documentation
145151
* Edited docstring for `pvsystem.sapm` to remove DataFrame option for input
146152
`module`. The DataFrame option was never tested and would cause an error if
147153
used. (:issue:`785`)
154+
* Note warning about _TMY3.epw files retrieved from energyplus.net in docstring
155+
of `epw.read_epw`
148156

149157
Removal of prior version deprecations
150158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pvlib/atmosphere.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,9 @@ def gueymard94_pw(temp_air, relative_humidity):
320320
return pw
321321

322322

323-
def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
324-
coefficients=None):
323+
def first_solar_spectral_correction(pw, airmass_absolute,
324+
module_type=None, coefficients=None,
325+
min_pw=0.1, max_pw=8):
325326
r"""
326327
Spectral mismatch modifier based on precipitable water and absolute
327328
(pressure corrected) airmass.
@@ -364,6 +365,14 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
364365
airmass_absolute : array-like
365366
absolute (pressure corrected) airmass.
366367
368+
min_pw : float, default 0.1
369+
minimum atmospheric precipitable water (cm). A lower pw value will be
370+
automatically set to this minimum value to avoid model divergence.
371+
372+
max_pw : float, default 8
373+
maximum atmospheric precipitable water (cm). If a higher value is
374+
encountered it will be set to np.nan to avoid model divergence.
375+
367376
module_type : None or string, default None
368377
a string specifying a cell type. Can be lower or upper case
369378
letters. Admits values of 'cdte', 'monosi', 'xsi', 'multisi',
@@ -422,16 +431,18 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
422431
# *** Pwat ***
423432
# Replace Pwat Values below 0.1 cm with 0.1 cm to prevent model from
424433
# diverging"
425-
426-
if np.min(pw) < 0.1:
427-
pw = np.maximum(pw, 0.1)
428-
warn('Exceptionally low Pwat values replaced with 0.1 cm to prevent' +
429-
' model divergence')
434+
pw = np.atleast_1d(pw)
435+
pw = pw.astype('float64')
436+
if np.min(pw) < min_pw:
437+
pw = np.maximum(pw, min_pw)
438+
warn('Exceptionally low pw values replaced with {0} cm to prevent '
439+
'model divergence'.format(min_pw))
430440

431441
# Warn user about Pwat data that is exceptionally high
432-
if np.max(pw) > 8:
433-
warn('Exceptionally high Pwat values. Check input data:' +
434-
' model may diverge in this range')
442+
if np.max(pw) > max_pw:
443+
pw[pw > max_pw] = np.nan
444+
warn('Exceptionally high pw values replaced by np.nan: '
445+
'check input data.')
435446

436447
# *** AMa ***
437448
# Replace Extremely High AM with AM 10 to prevent model divergence

pvlib/iotools/epw.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def read_epw(filename, coerce_year=None):
6767
=============== ====== =========================================
6868
6969
70-
============================= ==============================================================================================================================================================
70+
============================= ================================================================================================================================================================================================================== # noqa: E501
7171
EPWData field description
72-
============================= ==============================================================================================================================================================
72+
============================= ==================================================================================================================================================================================================================
7373
index A pandas datetime index. NOTE, times are set to local standard time (daylight savings is not included). Days run from 0-23h to comply with PVLIB's convention
7474
year Year, from original EPW file. Can be overwritten using coerce function.
7575
month Month, from original EPW file
@@ -99,14 +99,14 @@ def read_epw(filename, coerce_year=None):
9999
ceiling_height Height of cloud base above local terrain (7777=unlimited), meter
100100
present_weather_observation Indicator for remaining fields: If 0, then the observed weather codes are taken from the following field. If 9, then missing weather is assumed.
101101
present_weather_codes Present weather code, see [1], chapter 2.9.1.28
102-
precipitable_water Total precipitable water contained in a column of unit cross section from earth to top of atmosphere, cm
102+
precipitable_water Total precipitable water contained in a column of unit cross section from earth to top of atmosphere, cm. Note that some old *_TMY3.epw files may have incorrect unit if it was retrieved from www.energyplus.net.
103103
aerosol_optical_depth The broadband aerosol optical depth per unit of air mass due to extinction by aerosol component of atmosphere, unitless
104104
snow_depth Snow depth in centimeters on the day indicated, (999 = missing data)
105105
days_since_last_snowfall Number of days since last snowfall (maximum value of 88, where 88 = 88 or greater days; 99 = missing data)
106106
albedo The ratio of reflected solar irradiance to global horizontal irradiance, unitless
107107
liquid_precipitation_depth The amount of liquid precipitation observed at indicated time for the period indicated in the liquid precipitation quantity field, millimeter
108108
liquid_precipitation_quantity The period of accumulation for the liquid precipitation depth field, hour
109-
============================= ==============================================================================================================================================================
109+
============================= ==================================================================================================================================================================================================================
110110
111111
References
112112
----------

pvlib/test/test_atmosphere.py

+21
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ def test_first_solar_spectral_correction_ambiguous():
128128
atmosphere.first_solar_spectral_correction(1, 1)
129129

130130

131+
def test_first_solar_spectral_correction_range():
132+
with pytest.warns(UserWarning, match='Exceptionally high pw values'):
133+
out = atmosphere.first_solar_spectral_correction(np.array([.1, 3, 10]),
134+
np.array([1, 3, 5]),
135+
module_type='monosi')
136+
expected = np.array([0.96080878, 1.03055092, nan])
137+
assert_allclose(out, expected, atol=1e-3)
138+
with pytest.warns(UserWarning, match='Exceptionally high pw values'):
139+
out = atmosphere.first_solar_spectral_correction(6, 1.5, max_pw=5,
140+
module_type='monosi')
141+
with pytest.warns(UserWarning, match='Exceptionally low pw values'):
142+
out = atmosphere.first_solar_spectral_correction(np.array([0, 3, 8]),
143+
np.array([1, 3, 5]),
144+
module_type='monosi')
145+
expected = np.array([0.96080878, 1.03055092, 1.04932727])
146+
assert_allclose(out, expected, atol=1e-3)
147+
with pytest.warns(UserWarning, match='Exceptionally low pw values'):
148+
out = atmosphere.first_solar_spectral_correction(0.2, 1.5, min_pw=1,
149+
module_type='monosi')
150+
151+
131152
def test_kasten96_lt():
132153
"""Test Linke turbidity factor calculated from AOD, Pwat and AM"""
133154
amp = np.array([1, 3, 5])

0 commit comments

Comments
 (0)