Skip to content

Commit e83927d

Browse files
authored
make physicaliam return a Series if called with a Series (#398)
* physicaliam now preserves series type * update whatsnew * improve docstring * add github issue note to test
1 parent 726cf07 commit e83927d

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ Enhancements
1414
Bug fixes
1515
~~~~~~~~~
1616
* fixed redeclaration of test_simplified_solis_series_elevation (:issue:`387`)
17+
* physicaliam now returns a Series if called with a Series as an
18+
argument. (:issue:`397`)
1719

1820
Documentation
1921
~~~~~~~~~~~~~
20-
*
22+
* Improve physicaliam doc string. (:issue:`397`)
2123

2224
Testing
2325
~~~~~~~

pvlib/pvsystem.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -746,18 +746,17 @@ def ashraeiam(aoi, b=0.05):
746746
def physicaliam(aoi, n=1.526, K=4., L=0.002):
747747
'''
748748
Determine the incidence angle modifier using refractive index,
749-
glazing thickness, and extinction coefficient
749+
extinction coefficient, and glazing thickness.
750750
751751
physicaliam calculates the incidence angle modifier as described in
752752
De Soto et al. "Improvement and validation of a model for
753753
photovoltaic array performance", section 3. The calculation is based
754-
upon a physical model of absorbtion and transmission through a
755-
cover. Required information includes, incident angle, cover
756-
extinction coefficient, cover thickness
754+
on a physical model of absorbtion and transmission through a
755+
cover.
757756
758757
Note: The authors of this function believe that eqn. 14 in [1] is
759758
incorrect. This function uses the following equation in its place:
760-
theta_r = arcsin(1/n * sin(theta))
759+
theta_r = arcsin(1/n * sin(aoi))
761760
762761
Parameters
763762
----------
@@ -788,14 +787,8 @@ def physicaliam(aoi, n=1.526, K=4., L=0.002):
788787
789788
Returns
790789
-------
791-
IAM : numeric
792-
The incident angle modifier as specified in eqns. 14-16 of [1].
793-
IAM is a column vector with the same number of elements as the
794-
largest input vector.
795-
796-
Theta must be a numeric scalar or vector. For any values of
797-
theta where abs(aoi)>90, IAM is set to 0. For any values of aoi
798-
where -90 < aoi < 0, theta is set to abs(aoi) and evaluated.
790+
iam : numeric
791+
The incident angle modifier
799792
800793
References
801794
----------
@@ -816,6 +809,11 @@ def physicaliam(aoi, n=1.526, K=4., L=0.002):
816809
'''
817810
zeroang = 1e-06
818811

812+
# hold a new reference to the input aoi object since we're going to
813+
# overwrite the aoi reference below, but we'll need it for the
814+
# series check at the end of the function
815+
aoi_input = aoi
816+
819817
aoi = np.where(aoi == 0, zeroang, aoi)
820818

821819
# angle of reflection
@@ -849,8 +847,8 @@ def physicaliam(aoi, n=1.526, K=4., L=0.002):
849847
# for light coming from behind the plane, none can enter the module
850848
iam = np.where(aoi > 90, 0, iam)
851849

852-
if isinstance(aoi, pd.Series):
853-
iam = pd.Series(iam, index=aoi.index)
850+
if isinstance(aoi_input, pd.Series):
851+
iam = pd.Series(iam, index=aoi_input.index)
854852

855853
return iam
856854

pvlib/test/test_pvsystem.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,18 @@ def test_PVSystem_ashraeiam():
114114

115115
@needs_numpy_1_10
116116
def test_physicaliam():
117-
thetas = np.array([-90. , -67.5, -45. , -22.5, 0. , 22.5, 45. , 67.5, 90. , np.nan])
118-
iam = pvsystem.physicaliam(thetas, 1.526, 0.002, 4)
117+
aoi = np.array([-90. , -67.5, -45. , -22.5, 0. , 22.5, 45. , 67.5, 90. , np.nan])
118+
iam = pvsystem.physicaliam(aoi, 1.526, 0.002, 4)
119119
expected = np.array([ 0, 0.8893998, 0.98797788, 0.99926198, 1,
120120
0.99926198, 0.98797788, 0.8893998, 0, np.nan])
121121
assert_allclose(iam, expected, equal_nan=True)
122122

123+
# GitHub issue 397
124+
aoi = pd.Series(aoi)
125+
iam = pvsystem.physicaliam(aoi, 1.526, 0.002, 4)
126+
expected = pd.Series(expected)
127+
assert_series_equal(iam, expected)
128+
123129

124130
@needs_numpy_1_10
125131
def test_PVSystem_physicaliam():

0 commit comments

Comments
 (0)