From 03e86fa9772c14af40430b828db477f3c405d133 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 18 Mar 2015 09:58:56 +0100 Subject: [PATCH 01/14] removed outdated parsing tool --- pvlib/irradiance.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 7c50fdaf72..fa7c4f64a0 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -458,11 +458,9 @@ def globalinplane(SurfTilt,SurfAz,AOI,DNI,In_Plane_SkyDiffuse, GR): 'GR':('x>=0'), } - var=tools.Parse(Vars,Expect) - - Eb = var.DNI*np.cos(np.radians(var.AOI)) - E = Eb + var.In_Plane_SkyDiffuse + var.GR - Ediff = var.In_Plane_SkyDiffuse + var.GR + Eb = DNI*np.cos(np.radians(AOI)) + E = Eb + In_Plane_SkyDiffuse + GR + Ediff = In_Plane_SkyDiffuse + GR return pd.DataFrame({'E':E,'Eb':Eb,'Ediff':Ediff}) From 3c3cdd14e4270e9c9acfbb5d1d7a167bc02c1a82 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 18 Mar 2015 10:54:40 +0100 Subject: [PATCH 02/14] removed obsolete variables --- pvlib/irradiance.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index fa7c4f64a0..0107daa608 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -449,14 +449,6 @@ def globalinplane(SurfTilt,SurfAz,AOI,DNI,In_Plane_SkyDiffuse, GR): * ``Eb`` : Total in-plane beam irradiance (W/m^2) * ``Ediff`` : Total in-plane diffuse irradiance (W/m^2) ''' - Vars=locals() - Expect={'SurfTilt':('num','x>=0'), - 'SurfAz':('num','x>=-180','x<=180'), - 'AOI':('x>=0'), - 'DNI':('x>=0'), - 'In_Plane_SkyDiffuse':('x>=0'), - 'GR':('x>=0'), - } Eb = DNI*np.cos(np.radians(AOI)) E = Eb + In_Plane_SkyDiffuse + GR From 21cb88cc7d9c1aa28a7d68730041523c921cdfdf Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 18 Mar 2015 18:22:50 +0100 Subject: [PATCH 03/14] some pep8 fixes --- pvlib/irradiance.py | 819 ++++++++++++++++++++++---------------------- 1 file changed, 404 insertions(+), 415 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 0107daa608..2fbf995177 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -1,7 +1,7 @@ """ -The ``irradiance`` module contains functions for modeling -global horizontal irradiance, direct normal irradiance, -diffuse horizontal irradiance, and total irradiance +The ``irradiance`` module contains functions for modeling +global horizontal irradiance, direct normal irradiance, +diffuse horizontal irradiance, and total irradiance under various conditions. """ @@ -10,32 +10,30 @@ import logging pvl_logger = logging.getLogger('pvlib') -import pdb - import numpy as np import pandas as pd from pvlib import tools -from pvlib import solarposition - -SURFACE_ALBEDOS = {'urban':0.18, - 'grass':0.20, - 'fresh grass':0.26, - 'soil':0.17, - 'sand':0.40, - 'snow':0.65, - 'fresh snow':0.75, - 'asphalt':0.12, - 'concrete':0.30, - 'aluminum':0.85, - 'copper':0.74, - 'fresh steel':0.35, - 'dirty steel':0.08, - } - - - -# would be nice if this took pandas index as well. Use try:except of isinstance. +from pvlib import solarposition + +SURFACE_ALBEDOS = {'urban': 0.18, + 'grass': 0.20, + 'fresh grass': 0.26, + 'soil': 0.17, + 'sand': 0.40, + 'snow': 0.65, + 'fresh snow': 0.75, + 'asphalt': 0.12, + 'concrete': 0.30, + 'aluminum': 0.85, + 'copper': 0.74, + 'fresh steel': 0.35, + 'dirty steel': 0.08} + +# would be nice if this took pandas index as well. +# Use try:except of isinstance. + + def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): """ Determine extraterrestrial radiation from day of year. @@ -43,12 +41,12 @@ def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): Parameters ---------- datetime_or_doy : int, float, array, pd.DatetimeIndex - Day of year, array of days of year e.g. pd.DatetimeIndex.dayofyear, + Day of year, array of days of year e.g. pd.DatetimeIndex.dayofyear, or pd.DatetimeIndex. - + solar_constant : float The solar constant. - + method : string The method by which the ET radiation should be calculated. Options include ``'pyephem', 'spencer', 'asce'``. @@ -59,286 +57,280 @@ def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): The extraterrestrial radiation present in watts per square meter on a surface which is normal to the sun. Ea is of the same size as the - input doy. - + input doy. + 'pyephem' always returns a series. - + Notes ----- The Spencer method contains a minus sign discrepancy between - equation 12 of [1]. It's unclear what the correct formula is. + equation 12 of [1]. It's unclear what the correct formula is. References ---------- [1] M. Reno, C. Hansen, and J. Stein, "Global Horizontal Irradiance Clear Sky Models: Implementation and Analysis", Sandia National - Laboratories, SAND2012-2389, 2012. - - [2] , + Laboratories, SAND2012-2389, 2012. + + [2] , Eqs. SR1 and SR2 - [3] Partridge, G. W. and Platt, C. M. R. 1976. + [3] Partridge, G. W. and Platt, C. M. R. 1976. Radiative Processes in Meteorology and Climatology. - [4] Duffie, J. A. and Beckman, W. A. 1991. - Solar Engineering of Thermal Processes, + [4] Duffie, J. A. and Beckman, W. A. 1991. + Solar Engineering of Thermal Processes, 2nd edn. J. Wiley and Sons, New York. - See Also + See Also -------- disc """ - + pvl_logger.debug('irradiance.extraradiation()') - + method = method.lower() - + if isinstance(datetime_or_doy, pd.DatetimeIndex): doy = datetime_or_doy.dayofyear input_to_datetimeindex = lambda x: datetime_or_doy elif isinstance(datetime_or_doy, (int, float)): doy = datetime_or_doy input_to_datetimeindex = _scalar_to_datetimeindex - else: # assume that we have an array-like object of doy. danger? + else: # assume that we have an array-like object of doy. danger? doy = datetime_or_doy input_to_datetimeindex = _array_to_datetimeindex - - B = ( 2*np.pi / 365 ) * doy - + + B = (2 * np.pi / 365) * doy + if method == 'asce': pvl_logger.debug('Calculating ET rad using ASCE method') RoverR0sqrd = 1 + 0.033*np.cos(B) elif method == 'spencer': pvl_logger.debug('Calculating ET rad using Spencer method') - RoverR0sqrd = (1.00011 + 0.034221*np.cos(B) + 0.00128*np.sin(B) + + RoverR0sqrd = (1.00011 + 0.034221*np.cos(B) + 0.00128*np.sin(B) + 0.000719*np.cos(2*B) + 7.7e-05*np.sin(2*B)) elif method == 'pyephem': pvl_logger.debug('Calculating ET rad using pyephem method') times = input_to_datetimeindex(datetime_or_doy) RoverR0sqrd = solarposition.pyephem_earthsun_distance(times) ** (-2) - + Ea = solar_constant * RoverR0sqrd - + return Ea - - - + + def _scalar_to_datetimeindex(doy_scalar): """ Convert a scalar day of year number to a pd.DatetimeIndex. - + Parameters ---------- doy_array : int or float Contains days of the year - + Returns ------- pd.DatetimeIndex """ return pd.DatetimeIndex([_doy_to_timestamp(doy_scalar)]) - - - + + def _array_to_datetimeindex(doy_array): """ Convert an array of day of year numbers to a pd.DatetimeIndex. - + Parameters ---------- doy_array : Iterable Contains days of the year - + Returns ------- pd.DatetimeIndex """ return pd.DatetimeIndex(map(_doy_to_timestamp, doy_array)) - - - + + def _doy_to_timestamp(doy, epoch='2013-12-31'): """ Convert a numeric day of the year to a pd.Timestamp. - + Parameters ---------- doy : int or float. Numeric day of year. epoch : pd.Timestamp compatible object. Date to which to add the day of year to. - + Returns ------- pd.Timestamp """ return pd.Timestamp('2013-12-31') + pd.Timedelta(days=float(doy)) - - - + + def aoi_projection(surf_tilt, surf_az, sun_zen, sun_az): """ Calculates the dot product of the solar vector and the surface normal. - + Input all angles in degrees. - + Parameters ========== - - surf_tilt : float or Series. + + surf_tilt : float or Series. Panel tilt from horizontal. - surf_az : float or Series. + surf_az : float or Series. Panel azimuth from north. - sun_zen : float or Series. + sun_zen : float or Series. Solar zenith angle. - sun_az : float or Series. + sun_az : float or Series. Solar azimuth angle. - + Returns ======= float or Series. Dot product of panel normal and solar angle. """ - - projection = tools.cosd(surf_tilt)*tools.cosd(sun_zen) + tools.sind(surf_tilt)*tools.sind(sun_zen)*tools.cosd(sun_az - surf_az) - + + projection = ( + tools.cosd(surf_tilt) * tools.cosd(sun_zen) + tools.sind(surf_tilt) * + tools.sind(sun_zen) * tools.cosd(sun_az - surf_az)) + try: projection.name = 'aoi_projection' except AttributeError: pass - - return projection + return projection def aoi(surf_tilt, surf_az, sun_zen, sun_az): """ Calculates the angle of incidence of the solar vector on a surface. This is the angle between the solar vector and the surface normal. - + Input all angles in degrees. - + Parameters ========== - - surf_tilt : float or Series. + + surf_tilt : float or Series. Panel tilt from horizontal. - surf_az : float or Series. + surf_az : float or Series. Panel azimuth from north. - sun_zen : float or Series. + sun_zen : float or Series. Solar zenith angle. - sun_az : float or Series. + sun_az : float or Series. Solar azimuth angle. - + Returns ======= float or Series. Angle of incidence in degrees. """ - + projection = aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) aoi_value = np.rad2deg(np.arccos(projection)) - + try: aoi_value.name = 'aoi' except AttributeError: pass - + return aoi_value - def poa_horizontal_ratio(surf_tilt, surf_az, sun_zen, sun_az): """ Calculates the ratio of the beam components of the - plane of array irradiance and the horizontal irradiance. - + plane of array irradiance and the horizontal irradiance. + Input all angles in degrees. - + Parameters ========== - - surf_tilt : float or Series. + + surf_tilt : float or Series. Panel tilt from horizontal. - surf_az : float or Series. + surf_az : float or Series. Panel azimuth from north. - sun_zen : float or Series. + sun_zen : float or Series. Solar zenith angle. - sun_az : float or Series. + sun_az : float or Series. Solar azimuth angle. - + Returns ======= float or Series. Ratio of the plane of array irradiance to the horizontal plane irradiance """ - + cos_poa_zen = aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) - + cos_sun_zen = tools.cosd(sun_zen) - + # ratio of titled and horizontal beam irradiance ratio = cos_poa_zen / cos_sun_zen - + try: ratio.name = 'poa_ratio' except AttributeError: pass - + return ratio - - - + + def beam_component(surf_tilt, surf_az, sun_zen, sun_az, DNI): """ Calculates the beam component of the plane of array irradiance. - + Parameters ---------- - surf_tilt : float or Series. + surf_tilt : float or Series. Panel tilt from horizontal. - surf_az : float or Series. + surf_az : float or Series. Panel azimuth from north. - sun_zen : float or Series. + sun_zen : float or Series. Solar zenith angle. - sun_az : float or Series. + sun_az : float or Series. Solar azimuth angle. DNI : float or Series Direct Normal Irradiance - + Returns ------- Series """ beam = DNI * aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) beam[beam < 0] = 0 - + return beam - - -# how to best structure this function? wholmgren 2014-11-03 -def total_irrad(surf_tilt, surf_az, + +# ToDo: how to best structure this function? wholmgren 2014-11-03 +def total_irrad(surf_tilt, surf_az, sun_zen, sun_az, DNI, GHI, DHI, DNI_ET=None, AM=None, albedo=.25, surface_type=None, model='isotropic', model_perez='allsitescomposite1990'): ''' - Determine diffuse irradiance from the sky on a + Determine diffuse irradiance from the sky on a tilted surface. .. math:: I_{tot} = I_{beam} + I_{sky} + I_{ground} - + Parameters ---------- - surf_tilt : float or Series. + surf_tilt : float or Series. Panel tilt from horizontal. - surf_az : float or Series. + surf_az : float or Series. Panel azimuth from north. - sun_zen : float or Series. + sun_zen : float or Series. Solar zenith angle. - sun_az : float or Series. + sun_az : float or Series. Solar azimuth angle. DNI : float or Series Direct Normal Irradiance @@ -360,7 +352,7 @@ def total_irrad(surf_tilt, surf_az, See perez. Returns - ------- + ------- DataFrame with columns ``'total', 'beam', 'sky', 'ground'``. References @@ -371,9 +363,9 @@ def total_irrad(surf_tilt, surf_az, ''' pvl_logger.debug('planeofarray.total_irrad()') - + beam = beam_component(surf_tilt, surf_az, sun_zen, sun_az, DNI) - + model = model.lower() if model == 'isotropic': sky = isotropic(surf_tilt, DHI) @@ -382,35 +374,36 @@ def total_irrad(surf_tilt, surf_az, elif model == 'haydavies': sky = haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az) elif model == 'reindl': - sky = reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az) + sky = reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, + sun_az) elif model == 'king': sky = king(surf_tilt, DHI, GHI, sun_zen) elif model == 'perez': - sky = perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, - modelt=model_perez) + sky = perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, + modelt=model_perez) else: raise ValueError('invalid model selection {}'.format(model)) - + ground = grounddiffuse(surf_tilt, GHI, albedo, surface_type) - - total = beam + sky + ground - - all_irrad = pd.DataFrame({'total':total, - 'beam':beam, - 'sky':sky, - 'ground':ground}) - + + total = beam + sky + ground + + all_irrad = pd.DataFrame({'total': total, + 'beam': beam, + 'sky': sky, + 'ground': ground}) + return all_irrad - - - -# keep this or not? wholmgren, 2014-11-03 -def globalinplane(SurfTilt,SurfAz,AOI,DNI,In_Plane_SkyDiffuse, GR): + + +# ToDo: keep this or not? wholmgren, 2014-11-03 +def globalinplane(SurfTilt, SurfAz, AOI, DNI, In_Plane_SkyDiffuse, GR): ''' Determine the three components on in-plane irradiance - Combines in-plane irradaince compoents from the chosen diffuse translation, ground - reflection and beam irradiance algorithms into the total in-plane irradiance. + Combines in-plane irradaince compoents from the chosen diffuse translation, + ground reflection and beam irradiance algorithms into the total in-plane + irradiance. Parameters ---------- @@ -424,23 +417,25 @@ def globalinplane(SurfTilt,SurfAz,AOI,DNI,In_Plane_SkyDiffuse, GR): SurfAz : float or DataFrame Surface azimuth angles in decimal degrees. SurfAz must be >=0 and <=360. The Azimuth convention is defined - as degrees east of north (e.g. North = 0, south=180, East = 90, West = 270). + as degrees east of north (e.g. North = 0, south=180, East = 90, + West = 270). AOI : float or DataFrame Angle of incedence of solar rays with respect - to the module surface, from :py:mod:`pvl_getaoi`. AOI must be >=0 and <=180. + to the module surface, from :py:mod:`pvl_getaoi`. + AOI must be >=0 and <=180. DNI : float or DataFrame - Direct normal irradiance (W/m^2), as measured - from a TMY file or calculated with a clearsky model. + Direct normal irradiance (W/m^2), as measured + from a TMY file or calculated with a clearsky model. In_Plane_SkyDiffuse : float or DataFrame Diffuse irradiance (W/m^2) in the plane of the modules, as calculated by a diffuse irradiance translation function GR : float or DataFrame - a scalar or DataFrame of ground reflected irradiance (W/m^2), as calculated - by a albedo model (eg. :py:mod:`pvl_grounddiffuse`) + a scalar or DataFrame of ground reflected irradiance (W/m^2), + as calculated by a albedo model (eg. :py:mod:`pvl_grounddiffuse`) Returns ------- @@ -454,47 +449,45 @@ def globalinplane(SurfTilt,SurfAz,AOI,DNI,In_Plane_SkyDiffuse, GR): E = Eb + In_Plane_SkyDiffuse + GR Ediff = In_Plane_SkyDiffuse + GR - - return pd.DataFrame({'E':E,'Eb':Eb,'Ediff':Ediff}) - + return pd.DataFrame({'E': E, 'Eb': Eb, 'Ediff': Ediff}) def grounddiffuse(surf_tilt, ghi, albedo=.25, surface_type=None): - ''' - Estimate diffuse irradiance from ground reflections given - irradiance, albedo, and surface tilt + ''' + Estimate diffuse irradiance from ground reflections given + irradiance, albedo, and surface tilt Function to determine the portion of irradiance on a tilted surface due to ground reflections. Any of the inputs may be DataFrames or scalars. Parameters ---------- - surf_tilt : float or DataFrame - Surface tilt angles in decimal degrees. + surf_tilt : float or DataFrame + Surface tilt angles in decimal degrees. SurfTilt must be >=0 and <=180. The tilt angle is defined as degrees from horizontal (e.g. surface facing up = 0, surface facing horizon = 90). - ghi : float or DataFrame - Global horizontal irradiance in W/m^2. + ghi : float or DataFrame + Global horizontal irradiance in W/m^2. - albedo : float or DataFrame + albedo : float or DataFrame Ground reflectance, typically 0.1-0.4 for - surfaces on Earth (land), may increase over snow, ice, etc. May also + surfaces on Earth (land), may increase over snow, ice, etc. May also be known as the reflection coefficient. Must be >=0 and <=1. Will be overridden if surface_type is supplied. - - surface_type: None or string in + + surface_type: None or string in ``'urban', 'grass', 'fresh grass', 'snow', 'fresh snow', - 'asphalt', 'concrete', 'aluminum', 'copper', + 'asphalt', 'concrete', 'aluminum', 'copper', 'fresh steel', 'dirty steel'``. Overrides albedo. Returns ------- - float or DataFrame - Ground reflected irradiances in W/m^2. + float or DataFrame + Ground reflected irradiances in W/m^2. References @@ -502,38 +495,37 @@ def grounddiffuse(surf_tilt, ghi, albedo=.25, surface_type=None): [1] Loutzenhiser P.G. et. al. "Empirical validation of models to compute solar irradiance on inclined surfaces for building energy simulation" - 2007, Solar Energy vol. 81. pp. 254-267. - + 2007, Solar Energy vol. 81. pp. 254-267. + The calculation is the last term of equations 3, 4, 7, 8, 10, 11, and 12. - - [2] albedos from: + + [2] albedos from: http://pvpmc.org/modeling-steps/incident-irradiance/plane-of-array-poa-irradiance/calculating-poa-irradiance/poa-ground-reflected/albedo/ - + and - + http://en.wikipedia.org/wiki/Albedo ''' pvl_logger.debug('diffuse_ground.get_diffuse_ground()') - + if surface_type is not None: albedo = SURFACE_ALBEDOS[surface_type] pvl_logger.info('surface_type={} mapped to albedo={}' .format(surface_type, albedo)) diffuse_irrad = ghi * albedo * (1 - np.cos(np.radians(surf_tilt))) * 0.5 - + try: diffuse_irrad.name = 'diffuse_ground' except AttributeError: pass - + return diffuse_irrad - - + def isotropic(surf_tilt, DHI): r''' - Determine diffuse irradiance from the sky on a + Determine diffuse irradiance from the sky on a tilted surface using the isotropic sky model. .. math:: @@ -550,7 +542,7 @@ def isotropic(surf_tilt, DHI): ---------- surf_tilt : float or Series - Surface tilt angle in decimal degrees. + Surface tilt angle in decimal degrees. surf_tilt must be >=0 and <=180. The tilt angle is defined as degrees from horizontal (e.g. surface facing up = 0, surface facing horizon = 90) @@ -561,7 +553,7 @@ def isotropic(surf_tilt, DHI): Returns - ------- + ------- float or Series The diffuse component of the solar radiation on an @@ -591,20 +583,20 @@ def isotropic(surf_tilt, DHI): return sky_diffuse - def klucher(surf_tilt, surf_az, DHI, GHI, sun_zen, sun_az): r''' - Determine diffuse irradiance from the sky on a tilted surface + Determine diffuse irradiance from the sky on a tilted surface using Klucher's 1979 model .. math:: - I_{d} = DHI \frac{1 + \cos\beta}{2} (1 + F' \sin^3(\beta/2)) (1 + F' \cos^2\theta\sin^3\theta_z) - + I_{d} = DHI \frac{1 + \cos\beta}{2} (1 + F' \sin^3(\beta/2)) + (1 + F' \cos^2\theta\sin^3\theta_z) + where .. math:: - + F' = 1 - (I_{d0} / GHI) Klucher's 1979 model determines the diffuse irradiance from the sky @@ -626,19 +618,20 @@ def klucher(surf_tilt, surf_az, DHI, GHI, sun_zen, sun_az): surf_az : float or Series Surface azimuth angles in decimal degrees. surf_az must be >=0 and <=360. The Azimuth convention is defined - as degrees east of north (e.g. North = 0, South=180 East = 90, West = 270). + as degrees east of north (e.g. North = 0, South=180 East = 90, + West = 270). DHI : float or Series - diffuse horizontal irradiance in W/m^2. + diffuse horizontal irradiance in W/m^2. DHI must be >=0. GHI : float or Series - Global irradiance in W/m^2. + Global irradiance in W/m^2. DNI must be >=0. sun_zen : float or Series apparent (refraction-corrected) zenith - angles in decimal degrees. + angles in decimal degrees. sun_zen must be >=0 and <=180. sun_az : float or Series @@ -664,15 +657,15 @@ def klucher(surf_tilt, surf_az, DHI, GHI, sun_zen, sun_az): solar irradiance on inclined surfaces for building energy simulation" 2007, Solar Energy vol. 81. pp. 254-267 - [2] Klucher, T.M., 1979. Evaluation of models to predict insolation on tilted - surfaces. Solar Energy 23 (2), 111-114. + [2] Klucher, T.M., 1979. Evaluation of models to predict insolation on + tilted surfaces. Solar Energy 23 (2), 111-114. ''' pvl_logger.debug('diffuse_sky.klucher()') # zenith angle with respect to panel normal. cos_tt = aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) - + F = 1 - ((DHI / GHI) ** 2) try: # fails with single point input @@ -689,10 +682,9 @@ def klucher(surf_tilt, surf_az, DHI, GHI, sun_zen, sun_az): return sky_diffuse - def haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az): r''' - Determine diffuse irradiance from the sky on a + Determine diffuse irradiance from the sky on a tilted surface using Hay & Davies' 1980 model .. math:: @@ -701,7 +693,7 @@ def haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az): Hay and Davies' 1980 model determines the diffuse irradiance from the sky (ground reflected irradiance is not included in this algorithm) on a tilted surface using the surface tilt angle, surface azimuth angle, - diffuse horizontal irradiance, direct normal irradiance, + diffuse horizontal irradiance, direct normal irradiance, extraterrestrial irradiance, sun zenith angle, and sun azimuth angle. Parameters @@ -716,20 +708,21 @@ def haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az): surf_az : float or Series Surface azimuth angles in decimal degrees. The Azimuth convention is defined - as degrees east of north (e.g. North = 0, South=180 East = 90, West = 270). + as degrees east of north (e.g. North = 0, South=180 East = 90, + West = 270). DHI : float or Series - diffuse horizontal irradiance in W/m^2. + diffuse horizontal irradiance in W/m^2. DNI : float or Series - direct normal irradiance in W/m^2. + direct normal irradiance in W/m^2. DNI_ET : float or Series - extraterrestrial normal irradiance in W/m^2. + extraterrestrial normal irradiance in W/m^2. sun_zen : float or Series apparent (refraction-corrected) zenith - angles in decimal degrees. + angles in decimal degrees. sun_az : float or Series Sun azimuth angles in decimal degrees. @@ -744,8 +737,8 @@ def haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az): the diffuse component of the solar radiation on an arbitrarily tilted surface defined by the Perez model as given in reference [3]. - SkyDiffuse is the diffuse component ONLY and does not include the ground - reflected irradiance or the irradiance due to the beam. + SkyDiffuse is the diffuse component ONLY and does not include the + ground reflected irradiance or the irradiance due to the beam. References ----------- @@ -753,21 +746,21 @@ def haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az): solar irradiance on inclined surfaces for building energy simulation" 2007, Solar Energy vol. 81. pp. 254-267 - [2] Hay, J.E., Davies, J.A., 1980. Calculations of the solar radiation incident - on an inclined surface. In: Hay, J.E., Won, T.K. (Eds.), Proc. of First - Canadian Solar Radiation Data Workshop, 59. Ministry of Supply + [2] Hay, J.E., Davies, J.A., 1980. Calculations of the solar radiation + incident on an inclined surface. In: Hay, J.E., Won, T.K. (Eds.), Proc. of + First Canadian Solar Radiation Data Workshop, 59. Ministry of Supply and Services, Canada. ''' - + pvl_logger.debug('diffuse_sky.haydavies()') - + cos_tt = aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) - + cos_sun_zen = tools.cosd(sun_zen) - + # ratio of titled and horizontal beam irradiance Rb = cos_tt / cos_sun_zen - + # Anisotropy Index AI = DNI / DNI_ET @@ -775,21 +768,21 @@ def haydavies(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az): term1 = 1 - AI term2 = 0.5 * (1 + tools.cosd(surf_tilt)) - sky_diffuse = DHI * ( AI*Rb + term1 * term2 ) + sky_diffuse = DHI * (AI * Rb + term1 * term2) sky_diffuse[sky_diffuse < 0] = 0 - - return sky_diffuse + return sky_diffuse def reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az): r''' - Determine diffuse irradiance from the sky on a + Determine diffuse irradiance from the sky on a tilted surface using Reindl's 1990 model .. math:: - I_{d} = DHI (A R_b + (1 - A) (\frac{1 + \cos\beta}{2}) (1 + \sqrt{\frac{I_{hb}}{I_h}} \sin^3(\beta/2)) ) + I_{d} = DHI (A R_b + (1 - A) (\frac{1 + \cos\beta}{2}) + (1 + \sqrt{\frac{I_{hb}}{I_h}} \sin^3(\beta/2)) ) Reindl's 1990 model determines the diffuse irradiance from the sky (ground reflected irradiance is not included in this algorithm) on a @@ -810,26 +803,27 @@ def reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az): surf_az : float or Series. Surface azimuth angles in decimal degrees. The Azimuth convention is defined - as degrees east of north (e.g. North = 0, South=180 East = 90, West = 270). + as degrees east of north (e.g. North = 0, South=180 East = 90, + West = 270). DHI : float or Series. - diffuse horizontal irradiance in W/m^2. + diffuse horizontal irradiance in W/m^2. DNI : float or Series. - direct normal irradiance in W/m^2. + direct normal irradiance in W/m^2. GHI: float or Series. - Global irradiance in W/m^2. + Global irradiance in W/m^2. DNI_ET : float or Series. - extraterrestrial normal irradiance in W/m^2. + extraterrestrial normal irradiance in W/m^2. sun_zen : float or Series. apparent (refraction-corrected) zenith - angles in decimal degrees. + angles in decimal degrees. sun_az : float or Series. - Sun azimuth angles in decimal degrees. + Sun azimuth angles in decimal degrees. The Azimuth convention is defined as degrees east of north (e.g. North = 0, East = 90, West = 270). @@ -841,8 +835,8 @@ def reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az): The diffuse component of the solar radiation on an arbitrarily tilted surface defined by the Reindl model as given in Loutzenhiser et. al (2007) equation 8. - SkyDiffuse is the diffuse component ONLY and does not include the ground - reflected irradiance or the irradiance due to the beam. + SkyDiffuse is the diffuse component ONLY and does not include the + ground reflected irradiance or the irradiance due to the beam. SkyDiffuse is a column vector vector with a number of elements equal to the input vector(s). @@ -868,22 +862,22 @@ def reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az): [3] Reindl, D.T., Beckmann, W.A., Duffie, J.A., 1990b. Evaluation of hourly tilted surface radiation models. Solar Energy 45(1), 9-17. - ''' - + ''' + pvl_logger.debug('diffuse_sky.reindl()') - + cos_tt = aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) - + cos_sun_zen = tools.cosd(sun_zen) - + # ratio of titled and horizontal beam irradiance Rb = cos_tt / cos_sun_zen - + # Anisotropy Index AI = DNI / DNI_ET - + # DNI projected onto horizontal - HB = DNI * cos_sun_zen + HB = DNI * cos_sun_zen HB[HB < 0] = 0 # these are actually the () and [] sub-terms of the second term of eqn 8 @@ -891,16 +885,16 @@ def reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az): term2 = 0.5 * (1 + tools.cosd(surf_tilt)) term3 = 1 + np.sqrt(HB / GHI) * (tools.sind(0.5*surf_tilt) ** 3) - sky_diffuse = DHI * ( AI*Rb + term1 * term2 * term3 ) + sky_diffuse = DHI * (AI * Rb + term1 * term2 * term3) sky_diffuse[sky_diffuse < 0] = 0 - + return sky_diffuse - def king(surf_tilt, DHI, GHI, sun_zen): ''' - Determine diffuse irradiance from the sky on a tilted surface using the King model + Determine diffuse irradiance from the sky on a tilted surface using the + King model. King's model determines the diffuse irradiance from the sky (ground reflected irradiance is not included in this algorithm) on a @@ -917,16 +911,16 @@ def king(surf_tilt, DHI, GHI, sun_zen): The tilt angle is defined as degrees from horizontal (e.g. surface facing up = 0, surface facing horizon = 90) - + DHI : float or Series - diffuse horizontal irradiance in W/m^2. - + diffuse horizontal irradiance in W/m^2. + GHI : float or Series - global horizontal irradiance in W/m^2. + global horizontal irradiance in W/m^2. sun_zen : float or Series apparent (refraction-corrected) zenith - angles in decimal degrees. + angles in decimal degrees. Returns -------- @@ -934,24 +928,25 @@ def king(surf_tilt, DHI, GHI, sun_zen): SkyDiffuse : float or Series the diffuse component of the solar radiation on an - arbitrarily tilted surface as given by a model developed by David L. - King at Sandia National Laboratories. + arbitrarily tilted surface as given by a model developed by + David L. King at Sandia National Laboratories. ''' - + pvl_logger.debug('diffuse_sky.king()') - sky_diffuse = DHI * ((1 + tools.cosd(surf_tilt))) / 2 + GHI*((0.012 * sun_zen - 0.04))*((1 - tools.cosd(surf_tilt))) / 2 + sky_diffuse = (DHI * ((1 + tools.cosd(surf_tilt))) / 2 + GHI * + ((0.012 * sun_zen - 0.04)) * + ((1 - tools.cosd(surf_tilt))) / 2) sky_diffuse[sky_diffuse < 0] = 0 - - return sky_diffuse - + return sky_diffuse -def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, +def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, modelt='allsitescomposite1990'): - ''' - Determine diffuse irradiance from the sky on a tilted surface using one of the Perez models + ''' + Determine diffuse irradiance from the sky on a tilted surface using one of + the Perez models. Perez models determine the diffuse irradiance from the sky (ground reflected irradiance is not included in this algorithm) on a tilted @@ -974,23 +969,24 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, surf_az : float or Series Surface azimuth angles in decimal degrees. surf_az must be >=0 and <=360. The Azimuth convention is defined - as degrees east of north (e.g. North = 0, South=180 East = 90, West = 270). + as degrees east of north (e.g. North = 0, South=180 East = 90, + West = 270). DHI : float or Series - diffuse horizontal irradiance in W/m^2. + diffuse horizontal irradiance in W/m^2. DHI must be >=0. DNI : float or Series - direct normal irradiance in W/m^2. + direct normal irradiance in W/m^2. DNI must be >=0. DNI_ET : float or Series - extraterrestrial normal irradiance in W/m^2. + extraterrestrial normal irradiance in W/m^2. DNI_ET must be >=0. sun_zen : float or Series apparent (refraction-corrected) zenith - angles in decimal degrees. + angles in decimal degrees. sun_zen must be >=0 and <=180. sun_az : float or Series @@ -999,10 +995,10 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, as degrees east of north (e.g. North = 0, East = 90, West = 270). AM : float or Series - relative (not pressure-corrected) airmass - values. If AM is a DataFrame it must be of the same size as all other - DataFrame inputs. AM must be >=0 (careful using the 1/sec(z) model of AM - generation) + relative (not pressure-corrected) airmass + values. If AM is a DataFrame it must be of the same size as all other + DataFrame inputs. AM must be >=0 (careful using the 1/sec(z) model of + AM generation) Other Parameters ---------------- @@ -1012,7 +1008,7 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, a character string which selects the desired set of Perez coefficients. If model is not provided as an input, the default, '1990' will be used. - All possible model selections are: + All possible model selections are: * '1990' * 'allsitescomposite1990' (same as '1990') @@ -1035,8 +1031,8 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, the diffuse component of the solar radiation on an arbitrarily tilted surface defined by the Perez model as given in reference [3]. - SkyDiffuse is the diffuse component ONLY and does not include the ground - reflected irradiance or the irradiance due to the beam. + SkyDiffuse is the diffuse component ONLY and does not include the + ground reflected irradiance or the irradiance due to the beam. References @@ -1046,13 +1042,13 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, solar irradiance on inclined surfaces for building energy simulation" 2007, Solar Energy vol. 81. pp. 254-267 - [2] Perez, R., Seals, R., Ineichen, P., Stewart, R., Menicucci, D., 1987. A new - simplified version of the Perez diffuse irradiance model for tilted + [2] Perez, R., Seals, R., Ineichen, P., Stewart, R., Menicucci, D., 1987. + A new simplified version of the Perez diffuse irradiance model for tilted surfaces. Solar Energy 39(3), 221-232. [3] Perez, R., Ineichen, P., Seals, R., Michalsky, J., Stewart, R., 1990. Modeling daylight availability and irradiance components from direct - and global irradiance. Solar Energy 44 (5), 271-289. + and global irradiance. Solar Energy 44 (5), 271-289. [4] Perez, R. et. al 1988. "The Development and Verification of the Perez Diffuse Radiation Model". SAND88-7030 @@ -1060,43 +1056,44 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, pvl_logger.debug('diffuse_sky.perez()') - kappa = 1.041 #for sun_zen in radians - z = np.radians(sun_zen) # convert to radians + kappa = 1.041 # for sun_zen in radians + z = np.radians(sun_zen) # convert to radians # epsilon is the sky's "clearness" - eps = ( (DHI + DNI)/DHI + kappa*(z**3) ) / ( 1 + kappa*(z**3) ) - + eps = ((DHI + DNI)/DHI + kappa * (z**3)) / (1 + kappa * (z**3)) + # Perez et al define clearness bins according to the following rules. - # 1 = overcast ... 8 = clear + # 1 = overcast ... 8 = clear # (these names really only make sense for small zenith angles, but...) # these values will eventually be used as indicies for coeffecient look ups ebin = eps.copy() - ebin[(eps<1.065)] = 1 - ebin[(eps>=1.065) & (eps<1.23)] = 2 - ebin[(eps>=1.23) & (eps<1.5)] = 3 - ebin[(eps>=1.5) & (eps<1.95)] = 4 - ebin[(eps>=1.95) & (eps<2.8)] = 5 - ebin[(eps>=2.8) & (eps<4.5)] = 6 - ebin[(eps>=4.5) & (eps<6.2)] = 7 - ebin[eps>=6.2] = 8 + ebin[(eps < 1.065)] = 1 + ebin[(eps >= 1.065) & (eps < 1.23)] = 2 + ebin[(eps >= 1.23) & (eps < 1.5)] = 3 + ebin[(eps >= 1.5) & (eps < 1.95)] = 4 + ebin[(eps >= 1.95) & (eps < 2.8)] = 5 + ebin[(eps >= 2.8) & (eps < 4.5)] = 6 + ebin[(eps >= 4.5) & (eps < 6.2)] = 7 + ebin[eps >= 6.2] = 8 - ebin = ebin - 1 #correct for 0 indexing in coeffecient lookup + ebin = ebin - 1 # correct for 0 indexing in coeffecient lookup # remove night time values ebin = ebin.dropna().astype(int) # This is added because in cases where the sun is below the horizon - # (var.sun_zen > 90) but there is still diffuse horizontal light (var.DHI>0), it is - # possible that the airmass (var.AM) could be NaN, which messes up later - # calculations. Instead, if the sun is down, and there is still var.DHI, we set - # the airmass to the airmass value on the horizon (approximately 37-38). - #var.AM(var.sun_zen >=90 & var.DHI >0) = 37; - - #var.DNI_ET[var.DNI_ET==0] = .00000001 #very hacky, fix this - + # (var.sun_zen > 90) but there is still diffuse horizontal light + # (var.DHI>0), it is possible that the airmass (var.AM) could be NaN, which + # messes up later calculations. Instead, if the sun is down, and there is + # still var.DHI, we set the airmass to the airmass value on the horizon + # (approximately 37-38). + # var.AM(var.sun_zen >=90 & var.DHI >0) = 37; + + # var.DNI_ET[var.DNI_ET==0] = .00000001 #very hacky, fix this + # delta is the sky's "brightness" delta = DHI * AM / DNI_ET - + # keep only valid times delta = delta[ebin.index] z = z[ebin.index] @@ -1105,37 +1102,35 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, # in a subfunction to clean up the code. F1c, F2c = _get_perez_coefficients(modelt) - F1 = F1c[ebin,0] + F1c[ebin,1]*delta + F1c[ebin,2]*z - F1[F1 < 0] = 0; + F1 = F1c[ebin, 0] + F1c[ebin, 1] * delta + F1c[ebin, 2] * z + F1[F1 < 0] = 0 F1 = F1.astype(float) - F2 = F2c[ebin,0] + F2c[ebin,1]*delta + F2c[ebin,2]*z + F2 = F2c[ebin, 0] + F2c[ebin, 1]*delta + F2c[ebin, 2] * z F2[F2 < 0] = 0 F2 = F2.astype(float) A = aoi_projection(surf_tilt, surf_az, sun_zen, sun_az) A[A < 0] = 0 - B = tools.cosd(sun_zen); + B = tools.cosd(sun_zen) B[B < tools.cosd(85)] = tools.cosd(85) + # Calculate Diffuse POA from sky dome - #Calculate Diffuse POA from sky dome - term1 = 0.5 * (1 - F1) * (1 + tools.cosd(surf_tilt)) term2 = F1 * A[ebin.index] / B[ebin.index] term3 = F2*tools.sind(surf_tilt) - + sky_diffuse = DHI[ebin.index] * (term1 + term2 + term3) sky_diffuse[sky_diffuse < 0] = 0 return sky_diffuse - def _get_perez_coefficients(perezmodelt): - ''' - Find coefficients for the Perez model + ''' + Find coefficients for the Perez model Parameters ---------- @@ -1146,7 +1141,7 @@ def _get_perez_coefficients(perezmodelt): coefficients. If model is not provided as an input, the default, '1990' will be used. - All possible model selections are: + All possible model selections are: * '1990' * 'allsitescomposite1990' (same as '1990') @@ -1167,7 +1162,7 @@ def _get_perez_coefficients(perezmodelt): F1coeffs : array F1 coefficients for the Perez model F2coeffs : array - F2 coefficients for the Perez model + F2 coefficients for the Perez model References ---------- @@ -1176,121 +1171,118 @@ def _get_perez_coefficients(perezmodelt): solar irradiance on inclined surfaces for building energy simulation" 2007, Solar Energy vol. 81. pp. 254-267 - [2] Perez, R., Seals, R., Ineichen, P., Stewart, R., Menicucci, D., 1987. A new - simplified version of the Perez diffuse irradiance model for tilted + [2] Perez, R., Seals, R., Ineichen, P., Stewart, R., Menicucci, D., 1987. + A new simplified version of the Perez diffuse irradiance model for tilted surfaces. Solar Energy 39(3), 221-232. [3] Perez, R., Ineichen, P., Seals, R., Michalsky, J., Stewart, R., 1990. Modeling daylight availability and irradiance components from direct - and global irradiance. Solar Energy 44 (5), 271-289. + and global irradiance. Solar Energy 44 (5), 271-289. [4] Perez, R. et. al 1988. "The Development and Verification of the Perez Diffuse Radiation Model". SAND88-7030 ''' - coeffdict= {'allsitescomposite1990': - [[-0.0080, 0.5880, -0.0620, -0.0600, 0.0720, -0.0220], - [ 0.1300, 0.6830, -0.1510, -0.0190, 0.0660, -0.0290], - [ 0.3300, 0.4870, -0.2210, 0.0550, -0.0640, -0.0260], - [ 0.5680, 0.1870, -0.2950, 0.1090, -0.1520, -0.0140], - [ 0.8730, -0.3920, -0.3620, 0.2260, -0.4620, 0.0010], - [ 1.1320, -1.2370, -0.4120, 0.2880, -0.8230, 0.0560], - [ 1.0600, -1.6000, -0.3590, 0.2640, -1.1270, 0.1310], - [ 0.6780, -0.3270, -0.2500, 0.1560, -1.3770, 0.2510]], - 'allsitescomposite1988': - [[-0.0180, 0.7050, -0.071,0, -0.0580, 0.1020, -0.0260], - [ 0.1910, 0.6450, -0.1710, 0.0120, 0.0090, -0.0270], - [ 0.4400, 0.3780, -0.2560, 0.0870, -0.1040, -0.0250], - [ 0.7560, -0.1210, -0.3460, 0.1790, -0.3210, -0.0080], - [ 0.9960, -0.6450, -0.4050, 0.2600, -0.5900, 0.0170], - [ 1.0980, -1.2900, -0.3930, 0.2690, -0.8320, 0.0750], - [ 0.9730, -1.1350, -0.3780, 0.1240, -0.2580, 0.1490], - [ 0.6890, -0.4120, -0.2730, 0.1990, -1.6750, 0.2370]], - - 'sandiacomposite1988': - [[-0.1960, 1.0840, -0.0060, -0.1140, 0.1800, -0.0190], - [0.2360, 0.5190, -0.1800, -0.0110, 0.0200, -0.0380], - [0.4540, 0.3210, -0.2550, 0.0720, -0.0980, -0.0460], - [0.8660, -0.3810, -0.3750, 0.2030, -0.4030, -0.0490], - [1.0260, -0.7110, -0.4260, 0.2730, -0.6020, -0.0610], - [0.9780, -0.9860, -0.3500, 0.2800, -0.9150, -0.0240], - [0.7480, -0.9130, -0.2360, 0.1730, -1.0450, 0.0650], - [0.3180, -0.7570, 0.1030, 0.0620, -1.6980, 0.2360]], - 'usacomposite1988': - [[-0.0340, 0.6710, -0.0590, -0.0590, 0.0860, -0.0280], - [ 0.2550, 0.4740, -0.1910, 0.0180, -0.0140, -0.0330], - [ 0.4270, 0.3490, -0.2450, 0.0930, -0.1210, -0.0390], - [ 0.7560, -0.2130, -0.3280, 0.1750, -0.3040, -0.0270], - [ 1.0200, -0.8570, -0.3850, 0.2800, -0.6380, -0.0190], - [ 1.0500, -1.3440, -0.3480, 0.2800, -0.8930, 0.0370], - [ 0.9740, -1.5070, -0.3700, 0.1540, -0.5680, 0.1090], - [ 0.7440, -1.8170, -0.2560, 0.2460, -2.6180, 0.2300]], - 'france1988': - - [[0.0130, 0.7640, -0.1000, -0.0580, 0.1270, -0.0230], - [0.0950, 0.9200, -0.1520, 0, 0.0510, -0.0200], - [0.4640, 0.4210, -0.2800, 0.0640, -0.0510, -0.0020], - [0.7590, -0.0090, -0.3730, 0.2010, -0.3820, 0.0100], - [0.9760, -0.4000, -0.4360, 0.2710, -0.6380, 0.0510], - [1.1760, -1.2540, -0.4620, 0.2950, -0.9750, 0.1290], - [1.1060, -1.5630, -0.3980, 0.3010, -1.4420, 0.2120], - [0.9340, -1.5010, -0.2710, 0.4200, -2.9170, 0.2490]], - 'phoenix1988': - [[-0.0030, 0.7280, -0.0970, -0.0750, 0.1420, -0.0430], - [0.2790, 0.3540, -0.1760, 0.0300, -0.0550, -0.0540], - [0.4690, 0.1680, -0.2460, 0.0480, -0.0420, -0.0570], - [0.8560, -0.5190, -0.3400, 0.1760, -0.3800, -0.0310], - [0.9410, -0.6250, -0.3910, 0.1880, -0.3600, -0.0490], - [1.0560, -1.1340, -0.4100, 0.2810, -0.7940, -0.0650], - [0.9010, -2.1390, -0.2690, 0.1180, -0.6650, 0.0460], - [0.1070, 0.4810, 0.1430, -0.1110, -0.1370, 0.2340]], - 'elmonte1988': - [[0.0270, 0.7010, -0.1190, -0.0580, 0.1070 , -0.0600], - [0.1810, 0.6710, -0.1780, -0.0790, 0.1940 , -0.0350], - [0.4760, 0.4070, -0.2880, 0.0540, -0.0320 , -0.0550], - [0.8750, -0.2180, -0.4030, 0.1870, -0.3090 , -0.0610], - [1.1660, -1.0140, -0.4540, 0.2110, -0.4100 , -0.0440], - [1.1430, -2.0640, -0.2910, 0.0970, -0.3190 , 0.0530], - [1.0940, -2.6320, -0.2590, 0.0290, -0.4220 , 0.1470], - [0.1550, 1.7230, 0.1630, -0.1310, -0.0190 , 0.2770]], - 'osage1988': - [[-0.3530, 1.4740 , 0.0570, -0.1750, 0.3120 , 0.0090], - [ 0.3630, 0.2180 , -0.2120, 0.0190, -0.0340 , -0.0590], - [-0.0310, 1.2620 , -0.0840, -0.0820, 0.2310 , -0.0170], - [ 0.6910, 0.0390 , -0.2950, 0.0910, -0.1310 , -0.0350], - [1.1820, -1.3500 , -0.3210, 0.4080, -0.9850 , -0.0880], - [0.7640, 0.0190 , -0.2030, 0.2170, -0.2940 , -0.1030], - [0.2190, 1.4120 , 0.2440, 0.4710, -2.9880 , 0.0340], - [3.5780, 22.2310 , -10.7450, 2.4260, 4.8920 , -5.6870]], - 'albuquerque1988': - [[0.0340, 0.5010, -0.0940, -0.0630, 0.1060 , -0.0440], - [0.2290, 0.4670, -0.1560, -0.0050, -0.0190 , -0.0230], - [0.4860, 0.2410, -0.2530, 0.0530, -0.0640 , -0.0220], - [0.8740, -0.3930, -0.3970, 0.1810, -0.3270 , -0.0370], - [1.1930, -1.2960, -0.5010, 0.2810, -0.6560 , -0.0450], - [1.0560, -1.7580, -0.3740, 0.2260, -0.7590 , 0.0340], - [0.9010, -4.7830, -0.1090, 0.0630, -0.9700 , 0.1960], - [0.8510, -7.0550, -0.0530, 0.0600, -2.8330 , 0.3300]], - 'capecanaveral1988': - [[0.0750, 0.5330, -0.1240 , -0.0670 , 0.0420 , -0.0200], - [ 0.2950, 0.4970, -0.2180 , -0.0080 , 0.0030 , -0.0290], - [ 0.5140, 0.0810, -0.2610 , 0.0750 , -0.1600 , -0.0290], - [ 0.7470, -0.3290, -0.3250 , 0.1810 , -0.4160 , -0.0300], - [ 0.9010, -0.8830, -0.2970 , 0.1780 , -0.4890 , 0.0080], - [ 0.5910, -0.0440, -0.1160 , 0.2350 , -0.9990 , 0.0980], - [ 0.5370, -2.4020, 0.3200 , 0.1690 , -1.9710 , 0.3100], - [-0.8050, 4.5460, 1.0720 , -0.2580 , -0.9500, 0.7530]], - 'albany1988': - [[0.0120, 0.5540, -0.0760 , -0.0520, 0.0840 , -0.0290], - [0.2670, 0.4370, -0.1940 , 0.0160, 0.0220 , -0.0360], - [0.4200, 0.3360, -0.2370 , 0.0740, -0.0520 , -0.0320], - [0.6380, -0.0010, -0.2810 , 0.1380, -0.1890 , -0.0120], - [1.0190, -1.0270, -0.3420 , 0.2710, -0.6280 , 0.0140], - [1.1490, -1.9400, -0.3310 , 0.3220, -1.0970 , 0.0800], - [1.4340, -3.9940, -0.4920 , 0.4530, -2.3760 , 0.1170], - [1.0070, -2.2920, -0.4820 , 0.3900, -3.3680 , 0.2290]], - } - + coeffdict = { + 'allsitescomposite1990': [ + [-0.0080, 0.5880, -0.0620, -0.0600, 0.0720, -0.0220], + [0.1300, 0.6830, -0.1510, -0.0190, 0.0660, -0.0290], + [0.3300, 0.4870, -0.2210, 0.0550, -0.0640, -0.0260], + [0.5680, 0.1870, -0.2950, 0.1090, -0.1520, -0.0140], + [0.8730, -0.3920, -0.3620, 0.2260, -0.4620, 0.0010], + [1.1320, -1.2370, -0.4120, 0.2880, -0.8230, 0.0560], + [1.0600, -1.6000, -0.3590, 0.2640, -1.1270, 0.1310], + [0.6780, -0.3270, -0.2500, 0.1560, -1.3770, 0.2510]], + 'allsitescomposite1988': [ + [-0.0180, 0.7050, -0.071, -0.0580, 0.1020, -0.0260], + [0.1910, 0.6450, -0.1710, 0.0120, 0.0090, -0.0270], + [0.4400, 0.3780, -0.2560, 0.0870, -0.1040, -0.0250], + [0.7560, -0.1210, -0.3460, 0.1790, -0.3210, -0.0080], + [0.9960, -0.6450, -0.4050, 0.2600, -0.5900, 0.0170], + [1.0980, -1.2900, -0.3930, 0.2690, -0.8320, 0.0750], + [0.9730, -1.1350, -0.3780, 0.1240, -0.2580, 0.1490], + [0.6890, -0.4120, -0.2730, 0.1990, -1.6750, 0.2370]], + 'sandiacomposite1988': [ + [-0.1960, 1.0840, -0.0060, -0.1140, 0.1800, -0.0190], + [0.2360, 0.5190, -0.1800, -0.0110, 0.0200, -0.0380], + [0.4540, 0.3210, -0.2550, 0.0720, -0.0980, -0.0460], + [0.8660, -0.3810, -0.3750, 0.2030, -0.4030, -0.0490], + [1.0260, -0.7110, -0.4260, 0.2730, -0.6020, -0.0610], + [0.9780, -0.9860, -0.3500, 0.2800, -0.9150, -0.0240], + [0.7480, -0.9130, -0.2360, 0.1730, -1.0450, 0.0650], + [0.3180, -0.7570, 0.1030, 0.0620, -1.6980, 0.2360]], + 'usacomposite1988': [ + [-0.0340, 0.6710, -0.0590, -0.0590, 0.0860, -0.0280], + [0.2550, 0.4740, -0.1910, 0.0180, -0.0140, -0.0330], + [0.4270, 0.3490, -0.2450, 0.0930, -0.1210, -0.0390], + [0.7560, -0.2130, -0.3280, 0.1750, -0.3040, -0.0270], + [1.0200, -0.8570, -0.3850, 0.2800, -0.6380, -0.0190], + [1.0500, -1.3440, -0.3480, 0.2800, -0.8930, 0.0370], + [0.9740, -1.5070, -0.3700, 0.1540, -0.5680, 0.1090], + [0.7440, -1.8170, -0.2560, 0.2460, -2.6180, 0.2300]], + 'france1988': [ + [0.0130, 0.7640, -0.1000, -0.0580, 0.1270, -0.0230], + [0.0950, 0.9200, -0.1520, 0, 0.0510, -0.0200], + [0.4640, 0.4210, -0.2800, 0.0640, -0.0510, -0.0020], + [0.7590, -0.0090, -0.3730, 0.2010, -0.3820, 0.0100], + [0.9760, -0.4000, -0.4360, 0.2710, -0.6380, 0.0510], + [1.1760, -1.2540, -0.4620, 0.2950, -0.9750, 0.1290], + [1.1060, -1.5630, -0.3980, 0.3010, -1.4420, 0.2120], + [0.9340, -1.5010, -0.2710, 0.4200, -2.9170, 0.2490]], + 'phoenix1988': [ + [-0.0030, 0.7280, -0.0970, -0.0750, 0.1420, -0.0430], + [0.2790, 0.3540, -0.1760, 0.0300, -0.0550, -0.0540], + [0.4690, 0.1680, -0.2460, 0.0480, -0.0420, -0.0570], + [0.8560, -0.5190, -0.3400, 0.1760, -0.3800, -0.0310], + [0.9410, -0.6250, -0.3910, 0.1880, -0.3600, -0.0490], + [1.0560, -1.1340, -0.4100, 0.2810, -0.7940, -0.0650], + [0.9010, -2.1390, -0.2690, 0.1180, -0.6650, 0.0460], + [0.1070, 0.4810, 0.1430, -0.1110, -0.1370, 0.2340]], + 'elmonte1988': [ + [0.0270, 0.7010, -0.1190, -0.0580, 0.1070, -0.0600], + [0.1810, 0.6710, -0.1780, -0.0790, 0.1940, -0.0350], + [0.4760, 0.4070, -0.2880, 0.0540, -0.0320, -0.0550], + [0.8750, -0.2180, -0.4030, 0.1870, -0.3090, -0.0610], + [1.1660, -1.0140, -0.4540, 0.2110, -0.4100, -0.0440], + [1.1430, -2.0640, -0.2910, 0.0970, -0.3190, 0.0530], + [1.0940, -2.6320, -0.2590, 0.0290, -0.4220, 0.1470], + [0.1550, 1.7230, 0.1630, -0.1310, -0.0190, 0.2770]], + 'osage1988': [ + [-0.3530, 1.4740, 0.0570, -0.1750, 0.3120, 0.0090], + [0.3630, 0.2180, -0.2120, 0.0190, -0.0340, -0.0590], + [-0.0310, 1.2620, -0.0840, -0.0820, 0.2310, -0.0170], + [0.6910, 0.0390, -0.2950, 0.0910, -0.1310, -0.0350], + [1.1820, -1.3500, -0.3210, 0.4080, -0.9850, -0.0880], + [0.7640, 0.0190, -0.2030, 0.2170, -0.2940, -0.1030], + [0.2190, 1.4120, 0.2440, 0.4710, -2.9880, 0.0340], + [3.5780, 22.2310, -10.7450, 2.4260, 4.8920, -5.6870]], + 'albuquerque1988': [ + [0.0340, 0.5010, -0.0940, -0.0630, 0.1060, -0.0440], + [0.2290, 0.4670, -0.1560, -0.0050, -0.0190, -0.0230], + [0.4860, 0.2410, -0.2530, 0.0530, -0.0640, -0.0220], + [0.8740, -0.3930, -0.3970, 0.1810, -0.3270, -0.0370], + [1.1930, -1.2960, -0.5010, 0.2810, -0.6560, -0.0450], + [1.0560, -1.7580, -0.3740, 0.2260, -0.7590, 0.0340], + [0.9010, -4.7830, -0.1090, 0.0630, -0.9700, 0.1960], + [0.8510, -7.0550, -0.0530, 0.0600, -2.8330, 0.3300]], + 'capecanaveral1988': [ + [0.0750, 0.5330, -0.1240, -0.0670, 0.0420, -0.0200], + [0.2950, 0.4970, -0.2180, -0.0080, 0.0030, -0.0290], + [0.5140, 0.0810, -0.2610, 0.0750, -0.1600, -0.0290], + [0.7470, -0.3290, -0.3250, 0.1810, -0.4160, -0.0300], + [0.9010, -0.8830, -0.2970, 0.1780, -0.4890, 0.0080], + [0.5910, -0.0440, -0.1160, 0.2350, -0.9990, 0.0980], + [0.5370, -2.4020, 0.3200, 0.1690, -1.9710, 0.3100], + [-0.8050, 4.5460, 1.0720, -0.2580, -0.9500, 0.7530]], + 'albany1988': [ + [0.0120, 0.5540, -0.0760, -0.0520, 0.0840, -0.0290], + [0.2670, 0.4370, -0.1940, 0.0160, 0.0220, -0.0360], + [0.4200, 0.3360, -0.2370, 0.0740, -0.0520, -0.0320], + [0.6380, -0.0010, -0.2810, 0.1380, -0.1890, -0.0120], + [1.0190, -1.0270, -0.3420, 0.2710, -0.6280, 0.0140], + [1.1490, -1.9400, -0.3310, 0.3220, -1.0970, 0.0800], + [1.4340, -3.9940, -0.4920, 0.4530, -2.3760, 0.1170], + [1.0070, -2.2920, -0.4820, 0.3900, -3.3680, 0.2290]], } array = np.array(coeffdict[perezmodelt]) @@ -1298,6 +1290,3 @@ def _get_perez_coefficients(perezmodelt): F2coeffs = array.T[3:7].T return F1coeffs, F2coeffs - - - From 822002af02e66222d941684795ff5afa3959f7fc Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 18 Mar 2015 19:06:39 +0100 Subject: [PATCH 04/14] removed unused variables --- pvlib/irradiance.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 2fbf995177..21f4501e8d 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -397,7 +397,7 @@ def total_irrad(surf_tilt, surf_az, # ToDo: keep this or not? wholmgren, 2014-11-03 -def globalinplane(SurfTilt, SurfAz, AOI, DNI, In_Plane_SkyDiffuse, GR): +def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): ''' Determine the three components on in-plane irradiance @@ -408,18 +408,6 @@ def globalinplane(SurfTilt, SurfAz, AOI, DNI, In_Plane_SkyDiffuse, GR): Parameters ---------- - SurfTilt : float or DataFrame - surface tilt angles in decimal degrees. - SurfTilt must be >=0 and <=180. The tilt angle is defined as - degrees from horizontal (e.g. surface facing up = 0, surface facing - horizon = 90) - - SurfAz : float or DataFrame - Surface azimuth angles in decimal degrees. - SurfAz must be >=0 and <=360. The Azimuth convention is defined - as degrees east of north (e.g. North = 0, south=180, East = 90, - West = 270). - AOI : float or DataFrame Angle of incedence of solar rays with respect to the module surface, from :py:mod:`pvl_getaoi`. From 7355466b1e6a8ac625bae0d9c36ab9514f16208f Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 18 Mar 2015 20:16:23 +0100 Subject: [PATCH 05/14] fixed sphinx references --- pvlib/irradiance.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 21f4501e8d..ff1538a740 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -409,8 +409,8 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): ---------- AOI : float or DataFrame - Angle of incedence of solar rays with respect - to the module surface, from :py:mod:`pvl_getaoi`. + Angle of incidence of solar rays with respect + to the module surface, from :func:`aoi`. AOI must be >=0 and <=180. DNI : float or DataFrame @@ -423,7 +423,7 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): GR : float or DataFrame a scalar or DataFrame of ground reflected irradiance (W/m^2), - as calculated by a albedo model (eg. :py:mod:`pvl_grounddiffuse`) + as calculated by a albedo model (eg. :func:`grounddiffuse`) Returns ------- From e033abda9e3ff18426eb597900ec0c5c2da3711b Mon Sep 17 00:00:00 2001 From: uwe_ Date: Wed, 18 Mar 2015 20:42:12 +0100 Subject: [PATCH 06/14] some more pep8 fixes --- pvlib/irradiance.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index ff1538a740..4634f02fd1 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -105,11 +105,11 @@ def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): if method == 'asce': pvl_logger.debug('Calculating ET rad using ASCE method') - RoverR0sqrd = 1 + 0.033*np.cos(B) + RoverR0sqrd = 1 + 0.033 * np.cos(B) elif method == 'spencer': pvl_logger.debug('Calculating ET rad using Spencer method') - RoverR0sqrd = (1.00011 + 0.034221*np.cos(B) + 0.00128*np.sin(B) + - 0.000719*np.cos(2*B) + 7.7e-05*np.sin(2*B)) + RoverR0sqrd = (1.00011 + 0.034221 * np.cos(B) + 0.00128 * np.sin(B) + + 0.000719 * np.cos(2 * B) + 7.7e-05 * np.sin(2 * B)) elif method == 'pyephem': pvl_logger.debug('Calculating ET rad using pyephem method') times = input_to_datetimeindex(datetime_or_doy) @@ -149,7 +149,7 @@ def _array_to_datetimeindex(doy_array): ------- pd.DatetimeIndex """ - return pd.DatetimeIndex(map(_doy_to_timestamp, doy_array)) + return pd.DatetimeIndex(list(map(_doy_to_timestamp, doy_array))) def _doy_to_timestamp(doy, epoch='2013-12-31'): @@ -433,7 +433,7 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): * ``Ediff`` : Total in-plane diffuse irradiance (W/m^2) ''' - Eb = DNI*np.cos(np.radians(AOI)) + Eb = DNI * np.cos(np.radians(AOI)) E = Eb + In_Plane_SkyDiffuse + GR Ediff = In_Plane_SkyDiffuse + GR @@ -662,7 +662,7 @@ def klucher(surf_tilt, surf_az, DHI, GHI, sun_zen, sun_az): F = 0 term1 = 0.5 * (1 + tools.cosd(surf_tilt)) - term2 = 1 + F * (tools.sind(0.5*surf_tilt) ** 3) + term2 = 1 + F * (tools.sind(0.5 * surf_tilt) ** 3) term3 = 1 + F * (cos_tt ** 2) * (tools.sind(sun_zen) ** 3) sky_diffuse = DHI * term1 * term2 * term3 @@ -871,7 +871,7 @@ def reindl(surf_tilt, surf_az, DHI, DNI, GHI, DNI_ET, sun_zen, sun_az): # these are actually the () and [] sub-terms of the second term of eqn 8 term1 = 1 - AI term2 = 0.5 * (1 + tools.cosd(surf_tilt)) - term3 = 1 + np.sqrt(HB / GHI) * (tools.sind(0.5*surf_tilt) ** 3) + term3 = 1 + np.sqrt(HB / GHI) * (tools.sind(0.5 * surf_tilt) ** 3) sky_diffuse = DHI * (AI * Rb + term1 * term2 * term3) sky_diffuse[sky_diffuse < 0] = 0 @@ -1048,7 +1048,7 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, z = np.radians(sun_zen) # convert to radians # epsilon is the sky's "clearness" - eps = ((DHI + DNI)/DHI + kappa * (z**3)) / (1 + kappa * (z**3)) + eps = ((DHI + DNI) / DHI + kappa * (z ** 3)) / (1 + kappa * (z ** 3)) # Perez et al define clearness bins according to the following rules. # 1 = overcast ... 8 = clear @@ -1094,7 +1094,7 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, F1[F1 < 0] = 0 F1 = F1.astype(float) - F2 = F2c[ebin, 0] + F2c[ebin, 1]*delta + F2c[ebin, 2] * z + F2 = F2c[ebin, 0] + F2c[ebin, 1] * delta + F2c[ebin, 2] * z F2[F2 < 0] = 0 F2 = F2.astype(float) @@ -1108,7 +1108,7 @@ def perez(surf_tilt, surf_az, DHI, DNI, DNI_ET, sun_zen, sun_az, AM, term1 = 0.5 * (1 - F1) * (1 + tools.cosd(surf_tilt)) term2 = F1 * A[ebin.index] / B[ebin.index] - term3 = F2*tools.sind(surf_tilt) + term3 = F2 * tools.sind(surf_tilt) sky_diffuse = DHI[ebin.index] * (term1 + term2 + term3) sky_diffuse[sky_diffuse < 0] = 0 From a5d59bc141fc4ac3788da2dd61a86abdd68d9478 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Thu, 19 Mar 2015 14:11:23 +0100 Subject: [PATCH 07/14] fixed wrong sphinx reference --- pvlib/irradiance.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 4634f02fd1..eb463c9628 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -84,7 +84,7 @@ def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): See Also -------- - disc + pvlib.clearsky.disc """ pvl_logger.debug('irradiance.extraradiation()') @@ -491,7 +491,6 @@ def grounddiffuse(surf_tilt, ghi, albedo=.25, surface_type=None): http://pvpmc.org/modeling-steps/incident-irradiance/plane-of-array-poa-irradiance/calculating-poa-irradiance/poa-ground-reflected/albedo/ and - http://en.wikipedia.org/wiki/Albedo ''' pvl_logger.debug('diffuse_ground.get_diffuse_ground()') From ba5b0dde4eeda9b5039aaabdd766f333f3a654f6 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 09:58:16 +0100 Subject: [PATCH 08/14] some pep8 fixes --- pvlib/test/test_irradiance.py | 89 ++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index 6b4407da66..d462c46687 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -14,8 +14,8 @@ from pvlib import atmosphere # setup times and location to be tested. -times = pd.date_range(start=datetime.datetime(2014,6,24), - end=datetime.datetime(2014,6,26), freq='1Min') +times = pd.date_range(start=datetime.datetime(2014, 6, 24), + end=datetime.datetime(2014, 6, 26), freq='1Min') tus = Location(32.2, -111, 'US/Arizona', 700) @@ -36,80 +36,101 @@ def test_extraradiation(): assert_almost_equals(1382, irradiance.extraradiation(300), -1) - + + def test_extraradiation_dtindex(): irradiance.extraradiation(times) - + + def test_extraradiation_doyarray(): irradiance.extraradiation(times.dayofyear) - + + def test_extraradiation_asce(): - assert_almost_equals(1382, irradiance.extraradiation(300, method='asce'), -1) - + assert_almost_equals( + 1382, irradiance.extraradiation(300, method='asce'), -1) + + def test_extraradiation_spencer(): - assert_almost_equals(1382, irradiance.extraradiation(300, method='spencer'), -1) - + assert_almost_equals( + 1382, irradiance.extraradiation(300, method='spencer'), -1) + + def test_extraradiation_ephem_dtindex(): irradiance.extraradiation(times, method='pyephem') - + + def test_extraradiation_ephem_scalar(): - assert_almost_equals(1382, irradiance.extraradiation(300, method='pyephem').values[0], -1) - + assert_almost_equals( + 1382, irradiance.extraradiation(300, method='pyephem').values[0], -1) + + def test_extraradiation_ephem_doyarray(): irradiance.extraradiation(times.dayofyear, method='pyephem') + def test_grounddiffuse_simple_float(): irradiance.grounddiffuse(40, 900) + def test_grounddiffuse_simple_series(): ground_irrad = irradiance.grounddiffuse(40, ghi) assert ground_irrad.name == 'diffuse_ground' - + + def test_grounddiffuse_albedo_0(): ground_irrad = irradiance.grounddiffuse(40, ghi, albedo=0) assert 0 == ground_irrad.all() + @raises(KeyError) def test_grounddiffuse_albedo_invalid_surface(): irradiance.grounddiffuse(40, ghi, surface_type='invalid') - + + def test_grounddiffuse_albedo_surface(): irradiance.grounddiffuse(40, ghi, surface_type='sand') - + + def test_isotropic_float(): irradiance.isotropic(40, 100) - + + def test_isotropic_series(): irradiance.isotropic(40, irrad_data['DHI']) + def test_klucher_series_float(): irradiance.klucher(40, 180, 100, 900, 20, 180) - + + def test_klucher_series(): irradiance.klucher(40, 180, irrad_data['DHI'], irrad_data['GHI'], - ephem_data['apparent_zenith'], - ephem_data['apparent_azimuth']) - + ephem_data['apparent_zenith'], + ephem_data['apparent_azimuth']) + + def test_haydavies(): irradiance.haydavies(40, 180, irrad_data['DHI'], irrad_data['DNI'], - dni_et, - ephem_data['apparent_zenith'], - ephem_data['apparent_azimuth']) - + dni_et, + ephem_data['apparent_zenith'], + ephem_data['apparent_azimuth']) + + def test_reindl(): irradiance.reindl(40, 180, irrad_data['DHI'], irrad_data['DNI'], - irrad_data['GHI'], dni_et, - ephem_data['apparent_zenith'], - ephem_data['apparent_azimuth']) - + irrad_data['GHI'], dni_et, + ephem_data['apparent_zenith'], + ephem_data['apparent_azimuth']) + + def test_king(): irradiance.king(40, irrad_data['DHI'], irrad_data['GHI'], - ephem_data['apparent_zenith']) - + ephem_data['apparent_zenith']) + + def test_perez(): AM = atmosphere.relativeairmass(ephem_data['apparent_zenith']) irradiance.perez(40, 180, irrad_data['DHI'], irrad_data['DNI'], - dni_et, - ephem_data['apparent_zenith'], - ephem_data['apparent_azimuth'], - AM) \ No newline at end of file + dni_et, ephem_data['apparent_zenith'], + ephem_data['apparent_azimuth'],AM) From 46ad0db8dbb471fceee15c45dd15b2037ac78743 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 09:59:16 +0100 Subject: [PATCH 09/14] test function added: test_globalinplane() --- pvlib/test/test_irradiance.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index d462c46687..24f36a22ab 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -133,4 +133,17 @@ def test_perez(): AM = atmosphere.relativeairmass(ephem_data['apparent_zenith']) irradiance.perez(40, 180, irrad_data['DHI'], irrad_data['DNI'], dni_et, ephem_data['apparent_zenith'], - ephem_data['apparent_azimuth'],AM) + ephem_data['apparent_azimuth'], AM) + + +def test_globalinplane(): + aoi = irradiance.aoi(40, 180, ephem_data['apparent_zenith'], + ephem_data['apparent_azimuth']) + am = atmosphere.relativeairmass(ephem_data['apparent_zenith']) + gr_sand = irradiance.grounddiffuse(40, ghi, surface_type='sand') + diff_perez = irradiance.perez( + 40, 180, irrad_data['DHI'], irrad_data['DNI'], dni_et, + ephem_data['apparent_zenith'], ephem_data['apparent_azimuth'], am) + irradiance.globalinplane( + AOI=aoi, DNI=irrad_data['DNI'], In_Plane_SkyDiffuse=diff_perez, + GR=gr_sand) From 5da62e00dfab95a2cf063e0ae2554c82d80c5b09 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 10:03:32 +0100 Subject: [PATCH 10/14] replaced DataFrame by Series in the docstring The input parameter has to be a float or a Series not a DataFrame. --- pvlib/irradiance.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index eb463c9628..f5a277f0be 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -408,20 +408,20 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): Parameters ---------- - AOI : float or DataFrame + AOI : float or Series Angle of incidence of solar rays with respect to the module surface, from :func:`aoi`. AOI must be >=0 and <=180. - - DNI : float or DataFrame + + DNI : float or Series Direct normal irradiance (W/m^2), as measured from a TMY file or calculated with a clearsky model. - In_Plane_SkyDiffuse : float or DataFrame + In_Plane_SkyDiffuse : float or Series Diffuse irradiance (W/m^2) in the plane of the modules, as calculated by a diffuse irradiance translation function - GR : float or DataFrame + GR : float or Series a scalar or DataFrame of ground reflected irradiance (W/m^2), as calculated by a albedo model (eg. :func:`grounddiffuse`) From 5e146ad86d9b2a951b181135214c42288af44b15 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 10:05:42 +0100 Subject: [PATCH 11/14] removed range limitation of AOI in the docstring --- pvlib/irradiance.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index f5a277f0be..62055f0311 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -411,7 +411,6 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): AOI : float or Series Angle of incidence of solar rays with respect to the module surface, from :func:`aoi`. - AOI must be >=0 and <=180. DNI : float or Series Direct normal irradiance (W/m^2), as measured From f61d72ed6bc95a14ba0437996cee6c13d5118ef4 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 10:32:39 +0100 Subject: [PATCH 12/14] negative beam radiation is now set to zero --- pvlib/irradiance.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 62055f0311..208087f834 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -411,7 +411,7 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): AOI : float or Series Angle of incidence of solar rays with respect to the module surface, from :func:`aoi`. - + DNI : float or Series Direct normal irradiance (W/m^2), as measured from a TMY file or calculated with a clearsky model. @@ -430,9 +430,14 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): * ``E`` : Total in-plane irradiance (W/m^2) * ``Eb`` : Total in-plane beam irradiance (W/m^2) * ``Ediff`` : Total in-plane diffuse irradiance (W/m^2) + + Notes + ------ + Negative beam irradiation due to aoi :math:`> 90^{\circ}` or aoi + :math:`< 0^{\circ}` is set to zero. ''' - Eb = DNI * np.cos(np.radians(AOI)) + Eb = pd.Series(DNI * np.cos(np.radians(AOI))).clip_lower(0) E = Eb + In_Plane_SkyDiffuse + GR Ediff = In_Plane_SkyDiffuse + GR From 89b78318621d50e17cc1be91fcc75f4eab330372 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 17:21:03 +0100 Subject: [PATCH 13/14] changing variable names to upper case --- pvlib/irradiance.py | 2 +- pvlib/test/test_irradiance.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py index 208087f834..54f2bf73f9 100644 --- a/pvlib/irradiance.py +++ b/pvlib/irradiance.py @@ -433,7 +433,7 @@ def globalinplane(AOI, DNI, In_Plane_SkyDiffuse, GR): Notes ------ - Negative beam irradiation due to aoi :math:`> 90^{\circ}` or aoi + Negative beam irradiation due to aoi :math:`> 90^{\circ}` or AOI :math:`< 0^{\circ}` is set to zero. ''' diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py index 24f36a22ab..6d1b05d86f 100644 --- a/pvlib/test/test_irradiance.py +++ b/pvlib/test/test_irradiance.py @@ -137,13 +137,13 @@ def test_perez(): def test_globalinplane(): - aoi = irradiance.aoi(40, 180, ephem_data['apparent_zenith'], + AOI = irradiance.aoi(40, 180, ephem_data['apparent_zenith'], ephem_data['apparent_azimuth']) - am = atmosphere.relativeairmass(ephem_data['apparent_zenith']) + AM = atmosphere.relativeairmass(ephem_data['apparent_zenith']) gr_sand = irradiance.grounddiffuse(40, ghi, surface_type='sand') diff_perez = irradiance.perez( 40, 180, irrad_data['DHI'], irrad_data['DNI'], dni_et, - ephem_data['apparent_zenith'], ephem_data['apparent_azimuth'], am) + ephem_data['apparent_zenith'], ephem_data['apparent_azimuth'], AM) irradiance.globalinplane( - AOI=aoi, DNI=irrad_data['DNI'], In_Plane_SkyDiffuse=diff_perez, + AOI=AOI, DNI=irrad_data['DNI'], In_Plane_SkyDiffuse=diff_perez, GR=gr_sand) From 5617b824050229f636d6b1a8fd6d8a7164118cf2 Mon Sep 17 00:00:00 2001 From: uwe_ Date: Fri, 20 Mar 2015 19:38:26 +0100 Subject: [PATCH 14/14] Added a note about the changes to the whatsnew file --- docs/sphinx/source/whatsnew/v0.1.0.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.1.0.txt b/docs/sphinx/source/whatsnew/v0.1.0.txt index 1b65df8210..25fa95c394 100644 --- a/docs/sphinx/source/whatsnew/v0.1.0.txt +++ b/docs/sphinx/source/whatsnew/v0.1.0.txt @@ -44,7 +44,7 @@ Other changes ``clearsky.ineichen`` will work without ``scipy`` so long as the Linke Turbidity is supplied as a keyword argument. (:issue:`13`) * Removed NREL's SPA code to comply with their license (:issue:`9`). - +* Revised the globalinplane function and added a test_globalinplane (:issue:`21`, :issue:`33`). Documentation ~~~~~~~~~~~~~ @@ -92,3 +92,4 @@ and * Jorissup * dacoex * alexisph +* Uwe Krien