Skip to content

Commit 14d9a0f

Browse files
committed
clean up and fixes. closes #6, closes #24, closes #25
1 parent e24d1c9 commit 14d9a0f

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

pvlib/clearsky.py

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,10 @@ def _linearly_scale(inputmatrix, inputmin, inputmax, outputmin, outputmax):
284284

285285

286286

287-
def disc(GHI, SunZen, Time, pressure=101325):
287+
def disc(GHI, zenith, times, pressure=101325):
288288
'''
289-
Estimate Direct Normal Irradiance from Global Horizontal Irradiance using the DISC model
289+
Estimate Direct Normal Irradiance from Global Horizontal Irradiance
290+
using the DISC model.
290291
291292
The DISC algorithm converts global horizontal irradiance to direct
292293
normal irradiance through empirical relationships between the global
@@ -295,35 +296,28 @@ def disc(GHI, SunZen, Time, pressure=101325):
295296
Parameters
296297
----------
297298
298-
GHI : float or DataFrame
299-
global horizontal irradiance in W/m^2. GHI must be >=0.
299+
GHI : Series
300+
Global horizontal irradiance in W/m^2.
300301
301-
Z : float or DataFrame
302-
True (not refraction - corrected) zenith angles in decimal degrees.
303-
Z must be >=0 and <=180.
302+
zenith : Series
303+
True (not refraction - corrected) solar zenith
304+
angles in decimal degrees.
304305
305-
doy : float or DataFrame
306-
the day of the year. doy must be >= 1 and < 367.
306+
times : Series or DatetimeIndex
307307
308-
Other Parameters
309-
----------------
310-
311-
pressure : float or DataFrame (optional, Default=101325)
312-
313-
site pressure in Pascal. Pressure may be measured
314-
or an average pressure may be calculated from site altitude. If
315-
pressure is omitted, standard pressure (101325 Pa) will be used, this
316-
is acceptable if the site is near sea level. If the site is not near
317-
sea:level, inclusion of a measured or average pressure is highly
318-
recommended.
308+
pressure : float or Series
309+
Site pressure in Pascal.
319310
320311
Returns
321312
-------
322-
DNI : float or DataFrame
323-
The modeled direct normal irradiance in W/m^2 provided by the
324-
Direct Insolation Simulation Code (DISC) model.
325-
Kt : float or DataFrame
326-
Ratio of global to extraterrestrial irradiance on a horizontal plane.
313+
DataFrame with the following keys:
314+
* ``DNI_gen_DISC``: The modeled direct normal irradiance
315+
in W/m^2 provided by the
316+
Direct Insolation Simulation Code (DISC) model.
317+
* ``Kt_gen_DISC``: Ratio of global to extraterrestrial
318+
irradiance on a horizontal plane.
319+
* ``AM``: Airmass
320+
* ``Ztemp``: Zenith
327321
328322
References
329323
----------
@@ -343,46 +337,56 @@ def disc(GHI, SunZen, Time, pressure=101325):
343337
ephemeris
344338
alt2pres
345339
dirint
346-
347340
'''
348341

349-
#create a temporary dataframe to house masked values, initially filled with NaN
350-
temp=pd.DataFrame(index=Time,columns=['A','B','C'])
351-
352-
353-
pressure=101325
354-
doy=Time.dayofyear
355-
DayAngle=2.0 * np.pi*((doy - 1)) / 365
356-
re=1.00011 + 0.034221*(np.cos(DayAngle)) + (0.00128)*(np.sin(DayAngle)) + 0.000719*(np.cos(2.0 * DayAngle)) + (7.7e-05)*(np.sin(2.0 * DayAngle))
357-
I0=re*(1370)
358-
I0h=I0*(np.cos(np.radians(SunZen)))
359-
Ztemp=SunZen
360-
Ztemp[SunZen > 87]=87
361-
AM=1.0 / (np.cos(np.radians(Ztemp)) + 0.15*(((93.885 - Ztemp) ** (- 1.253))))*(pressure) / 101325
362-
Kt=GHI / (I0h)
363-
Kt[Kt < 0]=0
364-
Kt[Kt > 2]=np.NaN
365-
temp.A[Kt > 0.6]=- 5.743 + 21.77*(Kt[Kt > 0.6]) - 27.49*(Kt[Kt > 0.6] ** 2) + 11.56*(Kt[Kt > 0.6] ** 3)
366-
temp.B[Kt > 0.6]=41.4 - 118.5*(Kt[Kt > 0.6]) + 66.05*(Kt[Kt > 0.6] ** 2) + 31.9*(Kt[Kt > 0.6] ** 3)
367-
temp.C[Kt > 0.6]=- 47.01 + 184.2*(Kt[Kt > 0.6]) - 222.0 * Kt[Kt > 0.6] ** 2 + 73.81*(Kt[Kt > 0.6] ** 3)
368-
temp.A[(Kt <= 0.6-1)]=0.512 - 1.56*(Kt[(Kt <= 0.6-1)]) + 2.286*(Kt[(Kt <= 0.6-1)] ** 2) - 2.222*(Kt[(Kt <= 0.6-1)] ** 3)
369-
temp.B[(Kt <= 0.6-1)]=0.37 + 0.962*(Kt[(Kt <= 0.6-1)])
370-
temp.C[(Kt <= 0.6-1)]=- 0.28 + 0.932*(Kt[(Kt <= 0.6-1)]) - 2.048*(Kt[(Kt <= 0.6-1)] ** 2)
342+
logger.debug('clearsky.disc')
343+
344+
temp = pd.DataFrame(index=times, columns=['A','B','C'])
345+
346+
doy = times.dayofyear
347+
348+
DayAngle = 2. * np.pi*(doy - 1) / 365
349+
350+
re = (1.00011 + 0.034221*np.cos(DayAngle) + 0.00128*np.sin(DayAngle)
351+
+ 0.000719*np.cos(2.*DayAngle) + 7.7e-05*np.sin(2.*DayAngle) )
352+
353+
I0 = re * 1370.
354+
I0h = I0 * np.cos(np.radians(zenith))
355+
356+
Ztemp = zenith.copy()
357+
Ztemp[zenith > 87] = np.NaN
358+
359+
AM = 1.0 / ( np.cos(np.radians(Ztemp)) + 0.15*( (93.885 - Ztemp)**(-1.253) ) ) * (pressure / 101325)
360+
361+
Kt = GHI / I0h
362+
Kt[Kt < 0] = 0
363+
Kt[Kt > 2] = np.NaN
364+
365+
temp.A[Kt > 0.6] = -5.743 + 21.77*(Kt[Kt > 0.6]) - 27.49*(Kt[Kt > 0.6] ** 2) + 11.56*(Kt[Kt > 0.6] ** 3)
366+
temp.B[Kt > 0.6] = 41.4 - 118.5*(Kt[Kt > 0.6]) + 66.05*(Kt[Kt > 0.6] ** 2) + 31.9*(Kt[Kt > 0.6] ** 3)
367+
temp.C[Kt > 0.6] = -47.01 + 184.2*(Kt[Kt > 0.6]) - 222.0 * Kt[Kt > 0.6] ** 2 + 73.81*(Kt[Kt > 0.6] ** 3)
368+
temp.A[Kt <= 0.6] = 0.512 - 1.56*(Kt[Kt <= 0.6]) + 2.286*(Kt[Kt <= 0.6] ** 2) - 2.222*(Kt[Kt <= 0.6] ** 3)
369+
temp.B[Kt <= 0.6] = 0.37 + 0.962*(Kt[Kt <= 0.6])
370+
temp.C[Kt <= 0.6] = -0.28 + 0.932*(Kt[Kt <= 0.6]) - 2.048*(Kt[Kt <= 0.6] ** 2)
371+
371372
#return to numeric after masking operations
372-
temp=temp.astype(float)
373-
delKn=temp.A + temp.B*((temp.C*(AM)).apply(np.exp))
374-
Knc=0.866 - 0.122*(AM) + 0.0121*(AM ** 2) - 0.000653*(AM ** 3) + 1.4e-05*(AM ** 4)
375-
Kn=Knc - delKn
376-
DNI=(Kn)*(I0)
373+
temp = temp.astype(float)
374+
375+
delKn = temp.A + temp.B * np.exp(temp.C*AM)
376+
377+
Knc = 0.866 - 0.122*(AM) + 0.0121*(AM ** 2) - 0.000653*(AM ** 3) + 1.4e-05*(AM ** 4)
378+
Kn = Knc - delKn
379+
380+
DNI = Kn * I0
377381

378-
DNI[SunZen > 87]=np.NaN
379-
DNI[GHI < 1]=np.NaN
380-
DNI[DNI < 0]=np.NaN
382+
DNI[zenith > 87] = np.NaN
383+
DNI[GHI < 1] = np.NaN
384+
DNI[DNI < 0] = np.NaN
381385

382-
DFOut=pd.DataFrame({'DNI_gen_DISC':DNI})
386+
DFOut = pd.DataFrame({'DNI_gen_DISC':DNI})
383387

384-
DFOut['Kt_gen_DISC']=Kt
385-
DFOut['AM']=AM
386-
DFOut['Ztemp']=Ztemp
388+
DFOut['Kt_gen_DISC'] = Kt
389+
DFOut['AM'] = AM
390+
DFOut['Ztemp'] = Ztemp
387391

388392
return DFOut

0 commit comments

Comments
 (0)