Skip to content

Commit dc05ba0

Browse files
committed
update clearsky variable style
1 parent 2cd68b8 commit dc05ba0

File tree

4 files changed

+49
-47
lines changed

4 files changed

+49
-47
lines changed

pvlib/clearsky.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ def ineichen(time, location, linke_turbidity=None,
4949
Sets the solar position algorithm.
5050
See solarposition.get_solarposition()
5151
52-
zenith_data : None or pandas.Series
52+
zenith_data : None or Series
5353
If None, ephemeris data will be calculated using ``solarposition_method``.
5454
5555
airmass_model : string
5656
See pvlib.airmass.relativeairmass().
5757
58-
airmass_data : None or pandas.Series
58+
airmass_data : None or Series
5959
If None, absolute air mass data will be calculated using
6060
``airmass_model`` and location.alitude.
6161
@@ -65,14 +65,14 @@ def ineichen(time, location, linke_turbidity=None,
6565
6666
Returns
6767
--------
68-
DataFrame with the following columns: ``GHI, DNI, DHI``.
68+
DataFrame with the following columns: ``ghi, dni, dhi``.
6969
7070
Notes
7171
-----
7272
If you are using this function
7373
in a loop, it may be faster to load LinkeTurbidities.mat outside of
74-
the loop and feed it in as a variable, rather than
75-
having the function open the file each time it is called.
74+
the loop and feed it in as a keyword argument, rather than
75+
having the function open and process the file each time it is called.
7676
7777
References
7878
----------
@@ -96,7 +96,7 @@ def ineichen(time, location, linke_turbidity=None,
9696
'''
9797
# Initial implementation of this algorithm by Matthew Reno.
9898
# Ported to python by Rob Andrews
99-
# Added functionality by Will Holmgren
99+
# Added functionality by Will Holmgren (@wholmgren)
100100

101101
I0 = irradiance.extraradiation(time.dayofyear)
102102

@@ -161,7 +161,7 @@ def ineichen(time, location, linke_turbidity=None,
161161
# alt2pres) using Kasten and Young's 1989 formula for airmass.
162162

163163
if airmass_data is None:
164-
AMabsolute = atmosphere.absoluteairmass(AMrelative=atmosphere.relativeairmass(ApparentZenith, airmass_model),
164+
AMabsolute = atmosphere.absoluteairmass(airmass_relative=atmosphere.relativeairmass(ApparentZenith, airmass_model),
165165
pressure=atmosphere.alt2pres(location.altitude))
166166
else:
167167
AMabsolute = airmass_data
@@ -195,7 +195,9 @@ def ineichen(time, location, linke_turbidity=None,
195195

196196
cos_zenith = tools.cosd(ApparentZenith)
197197

198-
clearsky_GHI = cg1 * I0 * cos_zenith * np.exp(-cg2*AMabsolute*(fh1 + fh2*(TL - 1))) * np.exp(0.01*AMabsolute**1.8)
198+
clearsky_GHI = ( cg1 * I0 * cos_zenith *
199+
np.exp(-cg2*AMabsolute*(fh1 + fh2*(TL - 1))) *
200+
np.exp(0.01*AMabsolute**1.8) )
199201
clearsky_GHI[clearsky_GHI < 0] = 0
200202

201203
# BncI == "normal beam clear sky radiation"
@@ -204,25 +206,24 @@ def ineichen(time, location, linke_turbidity=None,
204206
logger.debug('b={}'.format(b))
205207

206208
# "empirical correction" SE 73, 157 & SE 73, 312.
207-
BncI_2 = clearsky_GHI * ( 1 - (0.1 - 0.2*np.exp(-TL))/(0.1 + 0.882/fh1) ) / cos_zenith
208-
#return BncI, BncI_2
209-
clearsky_DNI = np.minimum(BncI, BncI_2) # Will H: use np.minimum explicitly
209+
BncI_2 = ( clearsky_GHI *
210+
( 1 - (0.1 - 0.2*np.exp(-TL))/(0.1 + 0.882/fh1) ) /
211+
cos_zenith )
212+
213+
clearsky_DNI = np.minimum(BncI, BncI_2)
210214

211215
clearsky_DHI = clearsky_GHI - clearsky_DNI*cos_zenith
212216

213-
df_out = pd.DataFrame({'GHI':clearsky_GHI, 'DNI':clearsky_DNI,
214-
'DHI':clearsky_DHI})
217+
df_out = pd.DataFrame({'ghi':clearsky_GHI, 'dni':clearsky_DNI,
218+
'dhi':clearsky_DHI})
215219
df_out.fillna(0, inplace=True)
216-
#df_out['BncI'] = BncI
217-
#df_out['BncI_2'] = BncI
218220

219221
return df_out
220-
221-
222-
223-
def haurwitz(ApparentZenith):
222+
223+
224+
def haurwitz(apparent_zenith):
224225
'''
225-
Determine clear sky GHI from Haurwitz model
226+
Determine clear sky GHI from Haurwitz model.
226227
227228
Implements the Haurwitz clear sky model for global horizontal
228229
irradiance (GHI) as presented in [1, 2]. A report on clear
@@ -232,7 +233,7 @@ def haurwitz(ApparentZenith):
232233
233234
Parameters
234235
----------
235-
ApparentZenith : DataFrame
236+
apparent_zenith : Series
236237
The apparent (refraction corrected) sun zenith angle
237238
in degrees.
238239
@@ -258,13 +259,13 @@ def haurwitz(ApparentZenith):
258259
Laboratories, SAND2012-2389, 2012.
259260
'''
260261

261-
cos_zenith = tools.cosd(ApparentZenith)
262+
cos_zenith = tools.cosd(apparent_zenith)
262263

263264
clearsky_GHI = 1098.0 * cos_zenith * np.exp(-0.059/cos_zenith)
264265

265266
clearsky_GHI[clearsky_GHI < 0] = 0
266267

267-
df_out = pd.DataFrame({'GHI':clearsky_GHI})
268+
df_out = pd.DataFrame({'ghi':clearsky_GHI})
268269

269270
return df_out
270271

@@ -274,5 +275,5 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax):
274275

275276
inputrange = inputmax - inputmin
276277
outputrange = outputmax - outputmin
277-
OutputMatrix = (inputmatrix - inputmin) * outputrange / inputrange + outputmin
278+
OutputMatrix = (inputmatrix-inputmin) * outputrange/inputrange + outputmin
278279
return OutputMatrix

pvlib/test/test_clearsky.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ def test_ineichen_airmass():
4646

4747
def test_ineichen_keys():
4848
clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
49-
assert 'GHI' in clearsky_data.columns
50-
assert 'DNI' in clearsky_data.columns
51-
assert 'DHI' in clearsky_data.columns
49+
assert 'ghi' in clearsky_data.columns
50+
assert 'dni' in clearsky_data.columns
51+
assert 'dhi' in clearsky_data.columns
5252

5353
# test the haurwitz clear sky implementation
5454
def test_haurwitz():
5555
clearsky.haurwitz(ephem_data['zenith'])
5656

5757
def test_haurwitz_keys():
5858
clearsky_data = clearsky.haurwitz(ephem_data['zenith'])
59-
assert 'GHI' in clearsky_data.columns
59+
assert 'ghi' in clearsky_data.columns

pvlib/test/test_irradiance.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
dni_et = irradiance.extraradiation(times.dayofyear)
3232

33-
ghi = irrad_data['GHI']
33+
ghi = irrad_data['ghi']
3434

3535

3636
# the test functions. these are almost all functional tests.
@@ -99,41 +99,41 @@ def test_isotropic_float():
9999

100100

101101
def test_isotropic_series():
102-
irradiance.isotropic(40, irrad_data['DHI'])
102+
irradiance.isotropic(40, irrad_data['dhi'])
103103

104104

105105
def test_klucher_series_float():
106106
irradiance.klucher(40, 180, 100, 900, 20, 180)
107107

108108

109109
def test_klucher_series():
110-
irradiance.klucher(40, 180, irrad_data['DHI'], irrad_data['GHI'],
110+
irradiance.klucher(40, 180, irrad_data['dhi'], irrad_data['ghi'],
111111
ephem_data['apparent_zenith'],
112112
ephem_data['apparent_azimuth'])
113113

114114

115115
def test_haydavies():
116-
irradiance.haydavies(40, 180, irrad_data['DHI'], irrad_data['DNI'],
116+
irradiance.haydavies(40, 180, irrad_data['dhi'], irrad_data['dni'],
117117
dni_et,
118118
ephem_data['apparent_zenith'],
119119
ephem_data['apparent_azimuth'])
120120

121121

122122
def test_reindl():
123-
irradiance.reindl(40, 180, irrad_data['DHI'], irrad_data['DNI'],
124-
irrad_data['GHI'], dni_et,
123+
irradiance.reindl(40, 180, irrad_data['dhi'], irrad_data['dni'],
124+
irrad_data['ghi'], dni_et,
125125
ephem_data['apparent_zenith'],
126126
ephem_data['apparent_azimuth'])
127127

128128

129129
def test_king():
130-
irradiance.king(40, irrad_data['DHI'], irrad_data['GHI'],
130+
irradiance.king(40, irrad_data['dhi'], irrad_data['ghi'],
131131
ephem_data['apparent_zenith'])
132132

133133

134134
def test_perez():
135135
AM = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
136-
irradiance.perez(40, 180, irrad_data['DHI'], irrad_data['DNI'],
136+
irradiance.perez(40, 180, irrad_data['dhi'], irrad_data['dni'],
137137
dni_et, ephem_data['apparent_zenith'],
138138
ephem_data['apparent_azimuth'], AM)
139139

@@ -144,17 +144,17 @@ def test_globalinplane():
144144
AM = atmosphere.relativeairmass(ephem_data['apparent_zenith'])
145145
gr_sand = irradiance.grounddiffuse(40, ghi, surface_type='sand')
146146
diff_perez = irradiance.perez(
147-
40, 180, irrad_data['DHI'], irrad_data['DNI'], dni_et,
147+
40, 180, irrad_data['dhi'], irrad_data['dni'], dni_et,
148148
ephem_data['apparent_zenith'], ephem_data['apparent_azimuth'], AM)
149149
irradiance.globalinplane(
150-
AOI=AOI, DNI=irrad_data['DNI'], In_Plane_SkyDiffuse=diff_perez,
150+
AOI=AOI, DNI=irrad_data['dni'], In_Plane_SkyDiffuse=diff_perez,
151151
GR=gr_sand)
152152

153153

154154
# test DISC
155155
def test_disc_keys():
156156
clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
157-
disc_data = irradiance.disc(clearsky_data['GHI'], ephem_data['zenith'],
157+
disc_data = irradiance.disc(clearsky_data['ghi'], ephem_data['zenith'],
158158
ephem_data.index)
159159
assert 'DNI_gen_DISC' in disc_data.columns
160160
assert 'Kt_gen_DISC' in disc_data.columns
@@ -172,7 +172,7 @@ def test_disc_value():
172172
def test_dirint():
173173
clearsky_data = clearsky.ineichen(times, tus, linke_turbidity=3)
174174
pressure = 93193.
175-
dirint_data = irradiance.dirint(clearsky_data['GHI'], ephem_data['zenith'],
175+
dirint_data = irradiance.dirint(clearsky_data['ghi'], ephem_data['zenith'],
176176
ephem_data.index, pressure=pressure)
177177

178178
def test_dirint_value():

pvlib/test/test_pvsystem.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,17 @@ def test_retrieve_sam_network():
105105
def test_sapm():
106106
modules = sam_data['sandiamod']
107107
module = modules.Canadian_Solar_CS5P_220M___2009_
108-
109-
sapm = pvsystem.sapm(module, irrad_data.DNI, irrad_data.DHI, 25, am, aoi)
110-
111-
sapm = pvsystem.sapm(module.to_dict(), irrad_data.DNI,
112-
irrad_data.DHI, 25, am, aoi)
108+
109+
sapm = pvsystem.sapm(module, irrad_data['dni'],
110+
irrad_data['dhi'], 25, am, aoi)
111+
112+
sapm = pvsystem.sapm(module.to_dict(), irrad_data['dni'],
113+
irrad_data['dhi'], 25, am, aoi)
113114

114115

115116
def test_calcparams_desoto():
116117
cecmodule = sam_data['cecmod'].Example_Module
117-
pvsystem.calcparams_desoto(irrad_data.GHI,
118+
pvsystem.calcparams_desoto(irrad_data['ghi'],
118119
temp_cell=25,
119120
alpha_isc=cecmodule['Alpha_sc'],
120121
module_parameters=cecmodule,
@@ -130,7 +131,7 @@ def test_i_from_v():
130131
def test_singlediode_series():
131132
cecmodule = sam_data['cecmod'].Example_Module
132133
IL, I0, Rs, Rsh, nNsVth = pvsystem.calcparams_desoto(
133-
irrad_data.GHI,
134+
irrad_data['ghi'],
134135
temp_cell=25,
135136
alpha_isc=cecmodule['Alpha_sc'],
136137
module_parameters=cecmodule,

0 commit comments

Comments
 (0)