Skip to content

Commit b88cbb5

Browse files
committed
* fix for issue #782
- Note added in docstring of epw.py - Validity check added in atmosphere.first_solar_spectral_correction - corresponding tests done
1 parent a8ab9aa commit b88cbb5

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 19 additions & 9 deletions
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 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',
@@ -423,15 +432,16 @@ def first_solar_spectral_correction(pw, airmass_absolute, module_type=None,
423432
# Replace Pwat Values below 0.1 cm with 0.1 cm to prevent model from
424433
# diverging"
425434

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')
435+
if np.min(pw) < min_pw:
436+
pw = np.maximum(pw, min_pw)
437+
warn('Exceptionally low Pwat values replaced with {0} cm to prevent '
438+
'model divergence'.format(min_pw))
430439

431440
# 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')
441+
if np.max(pw) > max_pw:
442+
pw[pw > max_pw] *= np.nan
443+
warn('Exceptionally high Pwat values: check input data. '
444+
'Concerned values are replaced by np.nan')
435445

436446
# *** AMa ***
437447
# Replace Extremely High AM with AM 10 to prevent model divergence

pvlib/iotools/epw.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def read_epw(filename, coerce_year=None):
6767
=============== ====== =========================================
6868
6969
70-
============================= ==============================================================================================================================================================
70+
============================= ==================================================================================================================================================================================================================
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ 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):
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):
139+
out = atmosphere.first_solar_spectral_correction(np.array([0, 3, 8]),
140+
np.array([1, 3, 5]),
141+
module_type='monosi')
142+
expected = np.array([0.96080878, 1.03055092, 1.04932727])
143+
assert_allclose(out, expected, atol=1e-3)
144+
145+
131146
def test_kasten96_lt():
132147
"""Test Linke turbidity factor calculated from AOD, Pwat and AM"""
133148
amp = np.array([1, 3, 5])

0 commit comments

Comments
 (0)