Skip to content

Commit 23236b2

Browse files
authored
replace logging.warning with warnings.warn, remove logging.debug (#448)
1 parent b026c57 commit 23236b2

File tree

7 files changed

+10
-73
lines changed

7 files changed

+10
-73
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ v0.5.2 (__, 2017)
66
API Changes
77
~~~~~~~~~~~
88
* removed unused 'pressure' arg from irradiance.liujordan function (:issue:`386`)
9+
* replaced logging.warning calls with warnings.warn calls, and removed
10+
logging.debug calls. We encourage users to explore tools such as pdb and
11+
trackback in place of the logging.debug calls. Fixes (:issue:`447`).
912

1013
Enhancements
1114
~~~~~~~~~~~~

pvlib/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
logging.basicConfig()
31
from pvlib.version import __version__
42
from pvlib import tools
53
from pvlib import atmosphere

pvlib/irradiance.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from __future__ import division
88

9-
import logging
10-
119
import datetime
1210
from collections import OrderedDict
1311
from functools import partial
@@ -19,7 +17,6 @@
1917
from pvlib import solarposition
2018
from pvlib import atmosphere
2119

22-
pvl_logger = logging.getLogger('pvlib')
2320

2421
SURFACE_ALBEDOS = {'urban': 0.18,
2522
'grass': 0.20,
@@ -345,8 +342,6 @@ def total_irrad(surface_tilt, surface_azimuth,
345342
'poa_sky_diffuse', 'poa_ground_diffuse'``.
346343
"""
347344

348-
pvl_logger.debug('planeofarray.total_irrad()')
349-
350345
solar_zenith = apparent_zenith
351346
solar_azimuth = azimuth
352347

@@ -498,12 +493,8 @@ def grounddiffuse(surface_tilt, ghi, albedo=.25, surface_type=None):
498493
http://en.wikipedia.org/wiki/Albedo
499494
'''
500495

501-
pvl_logger.debug('diffuse_ground.get_diffuse_ground()')
502-
503496
if surface_type is not None:
504497
albedo = SURFACE_ALBEDOS[surface_type]
505-
pvl_logger.info('surface_type=%s mapped to albedo=%s',
506-
surface_type, albedo)
507498

508499
diffuse_irrad = ghi * albedo * (1 - np.cos(np.radians(surface_tilt))) * 0.5
509500

@@ -555,8 +546,6 @@ def isotropic(surface_tilt, dhi):
555546
heat collector. Trans. ASME 64, 91.
556547
'''
557548

558-
pvl_logger.debug('diffuse_sky.isotropic()')
559-
560549
sky_diffuse = dhi * (1 + tools.cosd(surface_tilt)) * 0.5
561550

562551
return sky_diffuse
@@ -628,8 +617,6 @@ def klucher(surface_tilt, surface_azimuth, dhi, ghi, solar_zenith,
628617
tilted surfaces. Solar Energy 23 (2), 111-114.
629618
'''
630619

631-
pvl_logger.debug('diffuse_sky.klucher()')
632-
633620
# zenith angle with respect to panel normal.
634621
cos_tt = aoi_projection(surface_tilt, surface_azimuth,
635622
solar_zenith, solar_azimuth)
@@ -719,8 +706,6 @@ def haydavies(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
719706
Ministry of Supply and Services, Canada.
720707
'''
721708

722-
pvl_logger.debug('diffuse_sky.haydavies()')
723-
724709
# if necessary, calculate ratio of titled and horizontal beam irradiance
725710
if projection_ratio is None:
726711
cos_tt = aoi_projection(surface_tilt, surface_azimuth,
@@ -819,8 +804,6 @@ def reindl(surface_tilt, surface_azimuth, dhi, dni, ghi, dni_extra,
819804
hourly tilted surface radiation models. Solar Energy 45(1), 9-17.
820805
'''
821806

822-
pvl_logger.debug('diffuse_sky.reindl()')
823-
824807
cos_tt = aoi_projection(surface_tilt, surface_azimuth,
825808
solar_zenith, solar_azimuth)
826809

@@ -881,8 +864,6 @@ def king(surface_tilt, dhi, ghi, solar_zenith):
881864
The diffuse component of the solar radiation.
882865
'''
883866

884-
pvl_logger.debug('diffuse_sky.king()')
885-
886867
sky_diffuse = (dhi * ((1 + tools.cosd(surface_tilt))) / 2 + ghi *
887868
((0.012 * solar_zenith - 0.04)) *
888869
((1 - tools.cosd(surface_tilt))) / 2)

pvlib/modelchain.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"""
88

99
from functools import partial
10-
import logging
1110
import warnings
1211
import pandas as pd
1312

@@ -683,7 +682,6 @@ def complete_irradiance(self, times=None, weather=None):
683682
"https://github.com/pvlib/pvlib-python \n")
684683

685684
if {'ghi', 'dhi'} <= icolumns and 'dni' not in icolumns:
686-
logging.debug('Estimate dni from ghi and dhi')
687685
clearsky = self.location.get_clearsky(
688686
times, solar_position=self.solar_position)
689687
self.weather.loc[:, 'dni'] = pvlib.irradiance.dni(
@@ -693,13 +691,11 @@ def complete_irradiance(self, times=None, weather=None):
693691
clearsky_tolerance=1.1)
694692
elif {'dni', 'dhi'} <= icolumns and 'ghi' not in icolumns:
695693
warnings.warn(wrn_txt, UserWarning)
696-
logging.debug('Estimate ghi from dni and dhi')
697694
self.weather.loc[:, 'ghi'] = (
698695
self.weather.dni * tools.cosd(self.solar_position.zenith) +
699696
self.weather.dhi)
700697
elif {'dni', 'ghi'} <= icolumns and 'dhi' not in icolumns:
701698
warnings.warn(wrn_txt, UserWarning)
702-
logging.debug('Estimate dhi from dni and ghi')
703699
self.weather.loc[:, 'dhi'] = (
704700
self.weather.ghi - self.weather.dni *
705701
tools.cosd(self.solar_position.zenith))

pvlib/solarposition.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
from pvlib import atmosphere
2525
from pvlib.tools import datetime_to_djd, djd_to_datetime
2626

27-
import logging
28-
pvl_logger = logging.getLogger('pvlib')
29-
3027

3128
def get_solarposition(time, latitude, longitude,
3229
altitude=None, pressure=None,
@@ -182,8 +179,6 @@ def spa_c(time, latitude, longitude, pressure=101325, altitude=0,
182179
raise ImportError('Could not import built-in SPA calculator. ' +
183180
'You may need to recompile the SPA code.')
184181

185-
pvl_logger.debug('using built-in spa code to calculate solar position')
186-
187182
# if localized, convert to UTC. otherwise, assume UTC.
188183
try:
189184
time_utc = time.tz_convert('UTC')
@@ -236,14 +231,12 @@ def _spa_python_import(how):
236231
# the PVLIB_USE_NUMBA env variable is used to tell the module
237232
# to not compile with numba
238233
os.environ['PVLIB_USE_NUMBA'] = '0'
239-
pvl_logger.debug('Reloading spa module without compiling')
240234
spa = reload(spa)
241235
del os.environ['PVLIB_USE_NUMBA']
242236
elif how == 'numba' and not using_numba:
243237
# The spa module was not compiled to numba code, so set
244238
# PVLIB_USE_NUMBA so it does compile to numba on reload.
245239
os.environ['PVLIB_USE_NUMBA'] = '1'
246-
pvl_logger.debug('Reloading spa module, compiling with numba')
247240
spa = reload(spa)
248241
del os.environ['PVLIB_USE_NUMBA']
249242
elif how != 'numba' and how != 'numpy':
@@ -323,8 +316,6 @@ def spa_python(time, latitude, longitude,
323316

324317
# Added by Tony Lorenzo (@alorenzo175), University of Arizona, 2015
325318

326-
pvl_logger.debug('Calculating solar position with spa_python code')
327-
328319
lat = latitude
329320
lon = longitude
330321
elev = altitude
@@ -404,8 +395,6 @@ def get_sun_rise_set_transit(time, latitude, longitude, how='numpy',
404395
"""
405396
# Added by Tony Lorenzo (@alorenzo175), University of Arizona, 2015
406397

407-
pvl_logger.debug('Calculating sunrise, set, transit with spa_python code')
408-
409398
lat = latitude
410399
lon = longitude
411400

@@ -493,8 +482,6 @@ def pyephem(time, latitude, longitude, altitude=0, pressure=101325,
493482
except ImportError:
494483
raise ImportError('PyEphem must be installed')
495484

496-
pvl_logger.debug('using PyEphem to calculate solar position')
497-
498485
# if localized, convert to UTC. otherwise, assume UTC.
499486
try:
500487
time_utc = time.tz_convert('UTC')
@@ -790,7 +777,6 @@ def pyephem_earthsun_distance(time):
790777
-------
791778
pd.Series. Earth-sun distance in AU.
792779
"""
793-
pvl_logger.debug('solarposition.pyephem_earthsun_distance()')
794780

795781
import ephem
796782

pvlib/spa.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
import os
1111
import threading
1212
import warnings
13-
import logging
14-
pvl_logger = logging.getLogger('pvlib')
15-
1613

1714
import numpy as np
1815

@@ -995,13 +992,11 @@ def solar_position_numba(unixtime, lat, lon, elev, pressure, temp, delta_t,
995992
unixtime = unixtime.astype(np.float64)
996993

997994
if ulength < numthreads:
998-
pvl_logger.warning('The number of threads is more than the length of' +
999-
' the time array. Only using %s threads.',
1000-
ulength)
995+
warnings.warn('The number of threads is more than the length of '
996+
'the time array. Only using %s threads.'.format(ulength))
1001997
numthreads = ulength
1002998

1003999
if numthreads <= 1:
1004-
pvl_logger.debug('Only using one thread for calculation')
10051000
solar_position_loop(unixtime, loc_args, result)
10061001
return result
10071002

@@ -1312,16 +1307,16 @@ def calculate_deltat(year, month):
13121307
Equations taken from http://eclipse.gsfc.nasa.gov/SEcat5/deltatpoly.html
13131308
"""
13141309

1315-
plw = ' Deltat is unknown for years before -1999 and after 3000.'\
1316-
+ ' Delta values will be calculated, but the calculations'\
1317-
+ ' are not intended to be used for these years.'
1310+
plw = 'Deltat is unknown for years before -1999 and after 3000. ' \
1311+
'Delta values will be calculated, but the calculations ' \
1312+
'are not intended to be used for these years.'
13181313

13191314
try:
13201315
if np.any((year > 3000) | (year < -1999)):
1321-
pvl_logger.warning(plw)
1316+
warnings.warn(plw)
13221317
except ValueError:
13231318
if (year > 3000) | (year < -1999):
1324-
pvl_logger.warning(plw)
1319+
warnings.warn(plw)
13251320
except TypeError:
13261321
return 0
13271322

pvlib/tracking.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
from pvlib.location import Location
99
from pvlib import irradiance, atmosphere
1010

11-
import logging
12-
pvl_logger = logging.getLogger('pvlib')
13-
1411

1512
class SingleAxisTracker(PVSystem):
1613
"""
@@ -307,15 +304,6 @@ def singleaxis(apparent_zenith, apparent_azimuth,
307304
Photovoltaics: Research and Applications, v. 19, pp. 747-753.
308305
"""
309306

310-
pvl_logger.debug('tracking.singleaxis')
311-
312-
pvl_logger.debug('axis_tilt=%s, axis_azimuth=%s, max_angle=%s, '
313-
'backtrack=%s, gcr=%.3f',
314-
axis_tilt, axis_azimuth, max_angle, backtrack, gcr)
315-
316-
pvl_logger.debug('\napparent_zenith=\n%s\napparent_azimuth=\n%s',
317-
apparent_zenith.head(), apparent_azimuth.head())
318-
319307
# MATLAB to Python conversion by
320308
# Will Holmgren (@wholmgren), U. Arizona. March, 2015.
321309

@@ -354,7 +342,6 @@ def singleaxis(apparent_zenith, apparent_azimuth,
354342
# wholmgren: strange to see axis_azimuth calculated differently from az,
355343
# (not that it matters, or at least it shouldn't...).
356344
axis_azimuth_south = axis_azimuth - 180
357-
pvl_logger.debug('axis_azimuth_south=%s', axis_azimuth_south)
358345

359346
# translate input array tilt angle axis_tilt to [1] coordinate system.
360347

@@ -418,7 +405,6 @@ def singleaxis(apparent_zenith, apparent_azimuth,
418405
# Account for backtracking; modified from [1] to account for rotation
419406
# angle convention being used here.
420407
if backtrack:
421-
pvl_logger.debug('applying backtracking')
422408
axes_distance = 1/gcr
423409
temp = np.minimum(axes_distance*cosd(wid), 1)
424410

@@ -431,7 +417,6 @@ def singleaxis(apparent_zenith, apparent_azimuth,
431417
widc[~v] = wid[~v] - wc[~v] # Eq 4 applied when wid in QI
432418
widc[v] = wid[v] + wc[v] # Eq 4 applied when wid in QIV
433419
else:
434-
pvl_logger.debug('no backtracking')
435420
widc = wid
436421

437422
tracker_theta = widc.copy()
@@ -469,34 +454,27 @@ def singleaxis(apparent_zenith, apparent_azimuth,
469454
rot_x = np.array([[1, 0, 0],
470455
[0, cosd(-axis_tilt), -sind(-axis_tilt)],
471456
[0, sind(-axis_tilt), cosd(-axis_tilt)]])
472-
pvl_logger.debug('rot_x=\n%s', rot_x)
473457

474458
# panel_norm_earth contains the normal vector
475459
# expressed in earth-surface coordinates
476460
# (z normal to surface, y aligned with tracker axis parallel to earth)
477461
panel_norm_earth = np.dot(rot_x, panel_norm).T
478-
pvl_logger.debug('panel_norm_earth=%s', panel_norm_earth)
479462

480463
# projection to plane tangent to earth surface,
481464
# in earth surface coordinates
482465
projected_normal = np.array([panel_norm_earth[:, 0],
483466
panel_norm_earth[:, 1],
484467
panel_norm_earth[:, 2]*0]).T
485-
pvl_logger.debug('projected_normal=%s', projected_normal)
486468

487469
# calculate vector magnitudes
488470
panel_norm_earth_mag = np.sqrt(np.nansum(panel_norm_earth**2, axis=1))
489471
projected_normal_mag = np.sqrt(np.nansum(projected_normal**2, axis=1))
490-
pvl_logger.debug('panel_norm_earth_mag=%s, projected_normal_mag=%s',
491-
panel_norm_earth_mag, projected_normal_mag)
492472

493473
# renormalize the projected vector
494474
# avoid creating nan values.
495475
non_zeros = projected_normal_mag != 0
496476
projected_normal[non_zeros] = (projected_normal[non_zeros].T /
497477
projected_normal_mag[non_zeros]).T
498-
pvl_logger.debug('renormalized projected_normal=%s',
499-
projected_normal)
500478

501479
# calculation of surface_azimuth
502480
# 1. Find the angle.

0 commit comments

Comments
 (0)