8000 avoid and silence warnings (#698) · floresfdev/pvlib-python@f4bbac8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4bbac8

Browse files
authored
avoid and silence warnings (pvlib#698)
* test_modelchain warnings * silence more warnings * spa and solarposition test warnings * only tracker errors left (other pr) * fix has_numba function * update whatsnew * fix NDFD and HRRR_ESRL variables, silence warnings * update whats new * revert HRRR_ESRL changes, add comments * revert pvfactors change in ci
1 parent 4872296 commit f4bbac8

File tree

13 files changed

+309
-227
lines changed

13 files changed

+309
-227
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ Bug fixes
4747
near horizon. (:issue:`656`)
4848
* Fixed numpy warnings in :py:func:`~pvlib.tracking.singleaxis` when
4949
comparing NaN values to limits. (:issue:`622`)
50+
* Silenced divide by 0 irradiance warnings in
51+
:py:func:`~pvlib.irradiance.klucher` and
52+
:py:func:`~pvlib.pvsystem.calcparams_desoto`. (:issue:`698`)
53+
* Fix :py:class:`~pvlib.forecast.NDFD` model by updating variables.
5054

5155

5256
Testing
5357
~~~~~~~
58+
* Remove most expected warnings emitted by test suite. (:issue:`698`)
5459

5560

5661
Contributors

pvlib/forecast.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import warnings
1818

1919
warnings.warn(
20-
'The forecast module algorithms and features are highly experimental. ' +
21-
'The API may change, the functionality may be consolidated into an io ' +
20+
'The forecast module algorithms and features are highly experimental. '
21+
'The API may change, the functionality may be consolidated into an io '
2222
'module, or the module may be separated into its own package.')
2323

2424

@@ -97,7 +97,7 @@ class ForecastModel(object):
9797
"""
9898

9999
access_url_key = 'NetcdfSubset'
100-
catalog_url = 'http://thredds.ucar.edu/thredds/catalog.xml'
100+
catalog_url = 'https://thredds.ucar.edu/thredds/catalog.xml'
101101
base_tds_url = catalog_url.split('/thredds/')[0]
102102
data_format = 'netcdf'
103103

@@ -789,6 +789,9 @@ def __init__(self, set_type='best'):
789789
self.variables = {
790790
'temp_air': 'Temperature_surface',
791791
'wind_speed_gust': 'Wind_speed_gust_surface',
792+
# 'temp_air': 'Temperature_height_above_ground', # GH 702
793+
# 'wind_speed_u': 'u-component_of_wind_height_above_ground',
794+
# 'wind_speed_v': 'v-component_of_wind_height_above_ground',
792795
'total_clouds': 'Total_cloud_cover_entire_atmosphere',
793796
'low_clouds': 'Low_cloud_cover_UnknownLevelType-214',
794797
'mid_clouds': 'Medium_cloud_cover_UnknownLevelType-224',
@@ -830,6 +833,7 @@ def process_data(self, data, cloud_cover='total_clouds', **kwargs):
830833
data = super(HRRR_ESRL, self).process_data(data, **kwargs)
831834
data['temp_air'] = self.kelvin_to_celsius(data['temp_air'])
832835
data['wind_speed'] = self.gust_to_speed(data)
836+
# data['wind_speed'] = self.uv_to_speed(data) # GH 702
833837
irrads = self.cloud_cover_to_irradiance(data[cloud_cover], **kwargs)
834838
data = data.join(irrads, how='outer')
835839
return data[self.output_variables]
@@ -1036,9 +1040,8 @@ def __init__(self, set_type='best'):
10361040
model_type = 'Forecast Products and Analyses'
10371041
model = 'National Weather Service CONUS Forecast Grids (CONDUIT)'
10381042
self.variables = {
1039-
'temp_air': 'Temperature_surface',
1040-
'wind_speed': 'Wind_speed_surface',
1041-
'wind_speed_gust': 'Wind_speed_gust_surface',
1043+
'temp_air': 'Temperature_height_above_ground',
1044+
'wind_speed': 'Wind_speed_height_above_ground',
10421045
'total_clouds': 'Total_cloud_cover_surface', }
10431046
self.output_variables = [
10441047
'temp_air',

pvlib/irradiance.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,10 @@ def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith,
750750
solar_zenith, solar_azimuth)
751751
cos_tt = np.maximum(cos_tt, 0) # GH 526
752752

753-
F = 1 - ((dhi / ghi) ** 2)
753+
# silence warning from 0 / 0
754+
with np.errstate(invalid='ignore'):
755+
F = 1 - ((dhi / ghi) ** 2)
756+
754757
try:
755758
# fails with single point input
756759
F.fillna(0, inplace=True)

pvlib/pvsystem.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,9 @@ def calcparams_desoto(effective_irradiance, temp_cell,
12761276
# by applying reflection and soiling losses to broadband plane of array
12771277
# irradiance and not applying a spectral loss modifier, i.e.,
12781278
# spectral_modifier = 1.0.
1279-
Rsh = R_sh_ref * (irrad_ref / effective_irradiance)
1279+
# use errstate to silence divide by warning
1280+
with np.errstate(divide='ignore'):
1281+
Rsh = R_sh_ref * (irrad_ref / effective_irradiance)
12801282
Rs = R_s
12811283

12821284
return IL, I0, Rs, Rsh, nNsVth

pvlib/test/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def has_numba():
114114
try:
115115
import numba
116116
except ImportError:
117-
return True
117+
return False
118118
else:
119119
vers = numba.__version__.split('.')
120120
if int(vers[0] + vers[1]) < 17:

pvlib/test/test_clearsky.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytz
99

1010
import pytest
11-
from numpy.testing import assert_almost_equal, assert_allclose
11+
from numpy.testing import assert_allclose
1212
from pandas.util.testing import assert_frame_equal, assert_series_equal
1313

1414
from pvlib.location import Location
@@ -308,8 +308,9 @@ def test_simplified_solis_scalar_neg_elevation():
308308

309309

310310
def test_simplified_solis_series_elevation():
311-
expected = pd.DataFrame(np.array([[959.335463, 1064.653145, 129.125602]]),
312-
columns=['dni', 'ghi', 'dhi'])
311+
expected = pd.DataFrame(
312+
np.array([[959.335463, 1064.653145, 129.125602]]),
313+
columns=['dni', 'ghi', 'dhi'])
313314
expected = expected[['ghi', 'dni', 'dhi']]
314315

315316
out = clearsky.simplified_solis(pd.Series(80))

pvlib/test/test_forecast.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414

1515
if has_siphon:
16-
from pvlib.forecast import GFS, HRRR_ESRL, HRRR, NAM, NDFD, RAP
16+
with warnings.catch_warnings():
17+
# don't emit import warning
18+
warnings.simplefilter("ignore")
19+
from pvlib.forecast import GFS, HRRR_ESRL, HRRR, NAM, NDFD, RAP
1720

1821
# setup times and location to be tested. Tucson, AZ
1922
_latitude = 32.2
@@ -27,7 +30,8 @@
2730
HRRR_ESRL, marks=[
2831
skip_windows,
2932
pytest.mark.xfail(reason="HRRR_ESRL is unreliable"),
30-
pytest.mark.timeout(timeout=60)])]
33+
pytest.mark.timeout(timeout=60),
34+
pytest.mark.filterwarnings('ignore:.*experimental')])]
3135
_working_models = []
3236
_variables = ['temp_air', 'wind_speed', 'total_clouds', 'low_clouds',
3337
'mid_clouds', 'high_clouds', 'dni', 'dhi', 'ghi']
@@ -75,21 +79,21 @@ def test_process_data(model):
7579
def test_vert_level():
7680
amodel = NAM()
7781
vert_level = 5000
78-
data = amodel.get_processed_data(_latitude, _longitude, _start, _end,
79-
vert_level=vert_level)
82+
amodel.get_processed_data(_latitude, _longitude, _start, _end,
83+
vert_level=vert_level)
84+
8085

8186
@requires_siphon
8287
def test_datetime():
8388
amodel = NAM()
8489
start = datetime.now()
8590
end = start + timedelta(days=1)
86-
data = amodel.get_processed_data(_latitude, _longitude , start, end)
91+
amodel.get_processed_data(_latitude, _longitude, start, end)
8792

8893

8994
@requires_siphon
9095
def test_queryvariables():
9196
amodel = GFS()
92-
old_variables = amodel.variables
9397
new_variables = ['u-component_of_wind_height_above_ground']
9498
data = amodel.get_data(_latitude, _longitude, _start, _end,
9599
query_variables=new_variables)

pvlib/test/test_irradiance.py

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
from collections import OrderedDict
3+
import warnings
34

45
import numpy as np
56
from numpy import array, nan
@@ -107,18 +108,24 @@ def test_get_extra_radiation(input, expected, method):
107108
assert_allclose(out, expected, atol=1)
108109

109110

110-
@requires_numba
111-
def test_get_extra_radiation_nrel_numba(times):
112-
result = irradiance.get_extra_radiation(times, method='nrel', how='numba',
113-
numthreads=8)
114-
assert_allclose(result, [1322.332316, 1322.296282, 1322.261205, 1322.227091])
115-
116-
117111
def test_get_extra_radiation_epoch_year():
118112
out = irradiance.get_extra_radiation(doy, method='nrel', epoch_year=2012)
119113
assert_allclose(out, 1382.4926804890767, atol=0.1)
120114

121115

116+
@requires_numba
117+
def test_get_extra_radiation_nrel_numba(times):
118+
with warnings.catch_warnings():
119+
# don't warn on method reload or num threads
120+
warnings.simplefilter("ignore")
121+
result = irradiance.get_extra_radiation(
122+
times, method='nrel', how='numba', numthreads=4)
123+
# and reset to no-numba state
124+
irradiance.get_extra_radiation(times, method='nrel')
125+
assert_allclose(result,
126+
[1322.332316, 1322.296282, 1322.261205, 1322.227091])
127+
128+
122129
def test_get_extra_radiation_invalid():
123130
with pytest.raises(ValueError):
124131
irradiance.get_extra_radiation(300, method='invalid')
@@ -135,13 +142,15 @@ def test_grounddiffuse_simple_series(irrad_data):
135142

136143

137144
def test_grounddiffuse_albedo_0(irrad_data):
138-
ground_irrad = irradiance.get_ground_diffuse(40, irrad_data['ghi'], albedo=0)
145+
ground_irrad = irradiance.get_ground_diffuse(
146+
40, irrad_data['ghi'], albedo=0)
139147
assert 0 == ground_irrad.all()
140148

141149

142150
def test_grounddiffuse_albedo_invalid_surface(irrad_data):
143151
with pytest.raises(KeyError):
144-
irradiance.get_ground_diffuse(40, irrad_data['ghi'], surface_type='invalid')
152+
irradiance.get_ground_diffuse(
153+
40, irrad_data['ghi'], surface_type='invalid')
145154

146155

147156
def test_grounddiffuse_albedo_surface(irrad_data):
@@ -193,35 +202,33 @@ def test_klucher_series(irrad_data, ephem_data):
193202

194203

195204
def test_haydavies(irrad_data, ephem_data, dni_et):
196-
result = irradiance.haydavies(40, 180, irrad_data['dhi'], irrad_data['dni'],
197-
dni_et,
198-
ephem_data['apparent_zenith'],
199-
ephem_data['azimuth'])
205+
result = irradiance.haydavies(
206+
40, 180, irrad_data['dhi'], irrad_data['dni'], dni_et,
207+
ephem_data['apparent_zenith'], ephem_data['azimuth'])
200208
# values from matlab 1.4 code
201209
assert_allclose(result, [0, 27.1775, 102.9949, 33.1909], atol=1e-4)
202210

203211

204212
def test_reindl(irrad_data, ephem_data, dni_et):
205-
result = irradiance.reindl(40, 180, irrad_data['dhi'], irrad_data['dni'],
206-
irrad_data['ghi'], dni_et,
207-
ephem_data['apparent_zenith'],
208-
ephem_data['azimuth'])
213+
result = irradiance.reindl(
214+
40, 180, irrad_data['dhi'], irrad_data['dni'], irrad_data['ghi'],
215+
dni_et, ephem_data['apparent_zenith'], ephem_data['azimuth'])
209216
# values from matlab 1.4 code
210217
assert_allclose(result, [np.nan, 27.9412, 104.1317, 34.1663], atol=1e-4)
211218

212219

213220
def test_king(irrad_data, ephem_data):
214221
result = irradiance.king(40, irrad_data['dhi'], irrad_data['ghi'],
215-
ephem_data['apparent_zenith'])
222+
ephem_data['apparent_zenith'])
216223
assert_allclose(result, [0, 44.629352, 115.182626, 79.719855], atol=1e-4)
217224

218225

219226
def test_perez(irrad_data, ephem_data, dni_et, relative_airmass):
220227
dni = irrad_data['dni'].copy()
221228
dni.iloc[2] = np.nan
222229
out = irradiance.perez(40, 180, irrad_data['dhi'], dni,
223-
dni_et, ephem_data['apparent_zenith'],
224-
ephem_data['azimuth'], relative_airmass)
230+
dni_et, ephem_data['apparent_zenith'],
231+
ephem_data['azimuth'], relative_airmass)
225232
expected = pd.Series(np.array(
226233
[ 0. , 31.46046871, np.nan, 45.45539877]),
227234
index=irrad_data.index)
@@ -260,8 +267,9 @@ def test_perez_arrays(irrad_data, ephem_data, dni_et, relative_airmass):
260267
dni = irrad_data['dni'].copy()
261268
dni.iloc[2] = np.nan
262269
out = irradiance.perez(40, 180, irrad_data['dhi'].values, dni.values,
263-
dni_et, ephem_data['apparent_zenith'].values,
264-
ephem_data['azimuth'].values, relative_airmass.values)
270+
dni_et, ephem_data['apparent_zenith'].values,
271+
ephem_data['azimuth'].values,
272+
relative_airmass.values)
265273
expected = np.array(
266274
[ 0. , 31.46046871, np.nan, 45.45539877])
267275
assert_allclose(out, expected, atol=1e-2)
@@ -289,8 +297,8 @@ def test_sky_diffuse_zenith_close_to_90(model):
289297

290298

291299
def test_liujordan():
292-
expected = pd.DataFrame(np.
293-
array([[863.859736967, 653.123094076, 220.65905025]]),
300+
expected = pd.DataFrame(np.array(
301+
[[863.859736967, 653.123094076, 220.65905025]]),
294302
columns=['ghi', 'dni', 'dhi'],
295303
index=[0])
296304
out = irradiance.liujordan(
@@ -484,7 +492,7 @@ def test_dirint_nans():
484492

485493

486494
def test_dirint_tdew():
487-
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
495+
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
488496
ghi = pd.Series([1038.62, 254.53], index=times)
489497
zenith = pd.Series([10.567, 72.469], index=times)
490498
pressure = 93193.
@@ -495,7 +503,7 @@ def test_dirint_tdew():
495503

496504

497505
def test_dirint_no_delta_kt():
498-
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
506+
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
499507
ghi = pd.Series([1038.62, 254.53], index=times)
500508
zenith = pd.Series([10.567, 72.469], index=times)
501509
pressure = 93193.
@@ -507,16 +515,16 @@ def test_dirint_no_delta_kt():
507515

508516
def test_dirint_coeffs():
509517
coeffs = irradiance._get_dirint_coeffs()
510-
assert coeffs[0,0,0,0] == 0.385230
511-
assert coeffs[0,1,2,1] == 0.229970
512-
assert coeffs[3,2,6,3] == 1.032260
518+
assert coeffs[0, 0, 0, 0] == 0.385230
519+
assert coeffs[0, 1, 2, 1] == 0.229970
520+
assert coeffs[3, 2, 6, 3] == 1.032260
513521

514522

515523
def test_dirint_min_cos_zenith_max_zenith():
516524
# map out behavior under difficult conditions with various
517525
# limiting kwargs settings
518526
# times don't have any physical relevance
519-
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
527+
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
520528
ghi = pd.Series([0, 1], index=times)
521529
solar_zenith = pd.Series([90, 89.99], index=times)
522530

@@ -727,7 +735,7 @@ def test_dirindex_min_cos_zenith_max_zenith():
727735
# map out behavior under difficult conditions with various
728736
# limiting kwargs settings
729737
# times don't have any physical relevance
730-
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
738+
times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
731739
ghi = pd.Series([0, 1], index=times)
732740
ghi_clearsky = pd.Series([0, 1], index=times)
733741
dni_clearsky = pd.Series([0, 5], index=times)

pvlib/test/test_location.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
from pvlib.location import Location
2020
from pvlib.solarposition import declination_spencer71
2121
from pvlib.solarposition import equation_of_time_spencer71
22-
from test_solarposition import expected_solpos, golden_mst
23-
from test_solarposition import golden
24-
22+
from test_solarposition import expected_solpos, golden, golden_mst
2523
from conftest import requires_ephem, requires_scipy
2624

2725

2826
def test_location_required():
2927
Location(32.2, -111)
3028

29+
3130
def test_location_all():
3231
Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
3332

@@ -71,7 +70,7 @@ def test_location_print_pytz():
7170
' longitude: -111',
7271
' altitude: 700',
7372
' tz: US/Arizona'
74-
])
73+
])
7574
assert tus.__str__() == expected_str
7675

7776

@@ -212,7 +211,7 @@ def test_get_clearsky_simplified_solis_aod_pw(times):
212211
def test_get_clearsky_valueerror(times):
213212
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
214213
with pytest.raises(ValueError):
215-
clearsky = tus.get_clearsky(times, model='invalid_model')
214+
tus.get_clearsky(times, model='invalid_model')
216215

217216

218217
def test_from_tmy_3():
@@ -275,7 +274,7 @@ def test_get_airmass(times):
275274
def test_get_airmass_valueerror(times):
276275
tus = Location(32.2, -111, 'US/Arizona', 700, 'Tucson')
277276
with pytest.raises(ValueError):
278-
clearsky = tus.get_airmass(times, model='invalid_model')
277+
tus.get_airmass(times, model='invalid_model')
279278

280279

281280
def test_Location___repr__():
@@ -288,7 +287,7 @@ def test_Location___repr__():
288287
' longitude: -111',
289288
' altitude: 700',
290289
' tz: US/Arizona'
291-
])
290+
])
292291
assert tus.__repr__() == expected
293292

294293

@@ -315,4 +314,4 @@ def test_get_sun_rise_set_transit_valueerror(golden):
315314
times = pd.DatetimeIndex(['2015-01-01 07:00:00', '2015-01-01 23:00:00'],
316315
tz='MST')
317316
with pytest.raises(ValueError):
318-
result = golden.get_sun_rise_set_transit(times, method='eyeball')
317+
golden.get_sun_rise_set_transit(times, method='eyeball')

0 commit comments

Comments
 (0)
0