Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.9.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Enhancements

Bug fixes
~~~~~~~~~
* Multiple issues fixed that were reported by LGTM analysis.


Testing
Expand All @@ -33,3 +34,4 @@ Requirements

Contributors
~~~~~~~~~~~~
* Christian Orner (:ghuser:`chrisorner`)
1 change: 0 additions & 1 deletion pvlib/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from pvlib.location import Location
from pvlib.irradiance import campbell_norman, get_extra_radiation, disc
from pvlib.irradiance import _liujordan
from siphon.catalog import TDSCatalog
from siphon.ncss import NCSS

Expand Down
10 changes: 6 additions & 4 deletions pvlib/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def martin_ruiz_diffuse(surface_tilt, a_r=0.16, c1=0.4244, c2=None):
# avoid undefined results for horizontal or upside-down surfaces
zeroang = 1e-06


surface_tilt = np.where(surface_tilt == 0, zeroang, surface_tilt)
surface_tilt = np.where(surface_tilt == 180, 180 - zeroang, surface_tilt)

Expand All @@ -361,8 +362,9 @@ def martin_ruiz_diffuse(surface_tilt, a_r=0.16, c1=0.4244, c2=None):
c2 = 0.5 * a_r - 0.154

beta = np.radians(surface_tilt)

from numpy import pi, sin, cos, exp
sin = np.sin
pi = np.pi
cos = np.cos

# avoid RuntimeWarnings for <, sin, and cos with nan
with np.errstate(invalid='ignore'):
Expand All @@ -372,8 +374,8 @@ def martin_ruiz_diffuse(surface_tilt, a_r=0.16, c1=0.4244, c2=None):
trig_term_sky = sin_beta + (pi - beta - sin_beta) / (1 + cos(beta))
trig_term_gnd = sin_beta + (beta - sin_beta) / (1 - cos(beta)) # noqa: E222 E261 E501

iam_sky = 1 - exp(-(c1 + c2 * trig_term_sky) * trig_term_sky / a_r)
iam_gnd = 1 - exp(-(c1 + c2 * trig_term_gnd) * trig_term_gnd / a_r)
iam_sky = 1 - np.exp(-(c1 + c2 * trig_term_sky) * trig_term_sky / a_r)
iam_gnd = 1 - np.exp(-(c1 + c2 * trig_term_gnd) * trig_term_gnd / a_r)

if out_index is not None:
iam_sky = pd.Series(iam_sky, index=out_index, name='iam_sky')
Expand Down
17 changes: 11 additions & 6 deletions pvlib/iotools/epw.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,19 @@ def read_epw(filename, coerce_year=None):
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 '
'Safari/537.36')})
response = urlopen(request)
csvdata = io.StringIO(response.read().decode(errors='ignore'))
with io.StringIO(response.read().decode(errors='ignore')) as csvdata:
try:
data, meta = parse_epw(csvdata, coerce_year)
except Exception as e:
print(e)
else:
# Assume it's accessible via the file system
csvdata = open(str(filename), 'r')
try:
data, meta = parse_epw(csvdata, coerce_year)
finally:
csvdata.close()
with open(str(filename), 'r') as csvdata:
try:
data, meta = parse_epw(csvdata, coerce_year)
except Exception as e:
print(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we definitely want to propagate any parsing errors instead of printing them and letting execution continue, so better to get rid of the try/excepts in these two blocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisorner for the contribution and closing a long-standing annoying issue, and also thanks @kanderso-nrel for quick and thoughtful review. I apologize for commenting after the fact. I agree with Kevin (altho he might not agree with me). In my opinion we should restrict using print() in pvlib, except perhaps in examples, b/c it blocks the main execution thread which reduces performance. An alternative is logging which has many useful features, executes in separate thread, and therefore, does not block the main Python thread. However, as a rule pvlib has avoided logging except during development. Hope this makes sense to folks. Just my thoughts/opinions, definitely do not speak for anyone other than myself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikofski just to be sure, would you change anything about the state of this PR as it was merged? Note that this printing was removed in a later commit and didn't make it into the final squashed diff.

I definitely agree that print() inside pvlib itself is never (or at least very rarely) the best way to present information to the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, no changes. I was very happy with this PR and the review. Thanks again! Just wanted to make sure it was in the record that I extremely discourage print(), and I consider logging a better alternative although to date, hasn't been used in pvlib much.


return data, meta


Expand Down
1 change: 0 additions & 1 deletion pvlib/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import datetime
import warnings

import pandas as pd
import pytz
Expand Down
1 change: 0 additions & 1 deletion pvlib/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ def fuentes(poa_global, temp_air, wind_speed, noct_installed, module_height=5,

# iterate through timeseries inputs
sun0 = 0
tmod0 = 293.15

# n.b. the way Fuentes calculates the first timedelta makes it seem like
# the value doesn't matter -- rather than recreate it here, just assume
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
import sys

try:
from setuptools import setup, find_namespace_packages
Expand Down