1010from pvlib .irradiance import beam_component , aoi , haydavies
1111
1212def _vf_ground_sky_integ (surface_tilt , surface_azimuth , gcr , height ,
13- pitch , max_rows = 10 , npoints = 100 ):
13+ pitch , max_rows = 10 , npoints = 100 , vectorize = False ):
1414 """
15- Integrated and per-point view factors from the ground to the sky at points
16- between interior rows of the array.
15+ Integrated view factor to the sky from the ground underneath
16+ interior rows of the array.
1717
1818 Parameters
1919 ----------
@@ -35,20 +35,16 @@ def _vf_ground_sky_integ(surface_tilt, surface_azimuth, gcr, height,
3535 Maximum number of rows to consider in front and behind the current row.
3636 npoints : int, default 100
3737 Number of points used to discretize distance along the ground.
38+ vectorize : bool, default False
39+ If True, vectorize the view factor calculation across ``surface_tilt``.
40+ This increases speed with the cost of increased memory usage.
3841
3942 Returns
4043 -------
41- fgnd_sky : float
44+ fgnd_sky : numeric
4245 Integration of view factor over the length between adjacent, interior
43- rows. [unitless]
44- fz : ndarray
45- Fraction of distance from the previous row to the next row. [unitless]
46- fz_sky : ndarray
47- View factors at discrete points between adjacent, interior rows.
48- [unitless]
49-
46+ rows. Shape matches that of ``surface_tilt``. [unitless]
5047 """
51- # TODO: vectorize over surface_tilt
5248 # Abuse utils._vf_ground_sky_2d by supplying surface_tilt in place
5349 # of a signed rotation. This is OK because
5450 # 1) z span the full distance between 2 rows, and
@@ -57,12 +53,16 @@ def _vf_ground_sky_integ(surface_tilt, surface_azimuth, gcr, height,
5753 # The VFs to the sky will thus be symmetric around z=0.5
5854 z = np .linspace (0 , 1 , npoints )
5955 rotation = np .atleast_1d (surface_tilt )
60- fz_sky = np .zeros ((len (rotation ), npoints ))
61- for k , r in enumerate (rotation ):
62- vf , _ = utils ._vf_ground_sky_2d (z , r , gcr , pitch , height , max_rows )
63- fz_sky [k , :] = vf
56+ if vectorize :
57+ fz_sky = utils ._vf_ground_sky_2d (z , rotation , gcr , pitch , height ,
58+ max_rows )
59+ else :
60+ fz_sky = np .zeros ((npoints , len (rotation )))
61+ for k , r in enumerate (rotation ):
62+ vf = utils ._vf_ground_sky_2d (z , r , gcr , pitch , height , max_rows )
63+ fz_sky [:, k ] = vf [:, 0 ] # remove spurious rotation dimension
6464 # calculate the integrated view factor for all of the ground between rows
65- return np .trapz (fz_sky , z , axis = 1 )
65+ return np .trapz (fz_sky , z , axis = 0 )
6666
6767
6868def _poa_ground_shadows (poa_ground , f_gnd_beam , df , vf_gnd_sky ):
@@ -401,7 +401,7 @@ def _shaded_fraction(solar_zenith, solar_azimuth, surface_tilt,
401401def get_irradiance_poa (surface_tilt , surface_azimuth , solar_zenith ,
402402 solar_azimuth , gcr , height , pitch , ghi , dhi , dni ,
403403 albedo , model = 'isotropic' , dni_extra = None , iam = 1.0 ,
404- npoints = 100 ):
404+ npoints = 100 , vectorize = False ):
405405 r"""
406406 Calculate plane-of-array (POA) irradiance on one side of a row of modules.
407407
@@ -469,7 +469,12 @@ def get_irradiance_poa(surface_tilt, surface_azimuth, solar_zenith,
469469 on the surface that is not reflected away. [unitless]
470470
471471 npoints : int, default 100
472- Number of points used to discretize distance along the ground.
472+ Number of discretization points for calculating integrated view
473+ factors.
474+
475+ vectorize : bool, default False
476+ If True, vectorize the view factor calculation across ``surface_tilt``.
477+ This increases speed with the cost of increased memory usage.
473478
474479 Returns
475480 -------
@@ -537,7 +542,8 @@ def get_irradiance_poa(surface_tilt, surface_azimuth, solar_zenith,
537542 # method differs from [1], Eq. 7 and Eq. 8; height is defined at row
538543 # center rather than at row lower edge as in [1].
539544 vf_gnd_sky = _vf_ground_sky_integ (
540- surface_tilt , surface_azimuth , gcr , height , pitch , max_rows , npoints )
545+ surface_tilt , surface_azimuth , gcr , height , pitch , max_rows , npoints ,
546+ vectorize )
541547 # fraction of row slant height that is shaded from direct irradiance
542548 f_x = _shaded_fraction (solar_zenith , solar_azimuth , surface_tilt ,
543549 surface_azimuth , gcr )
@@ -610,7 +616,7 @@ def get_irradiance(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
610616 gcr , height , pitch , ghi , dhi , dni ,
611617 albedo , model = 'isotropic' , dni_extra = None , iam_front = 1.0 ,
612618 iam_back = 1.0 , bifaciality = 0.8 , shade_factor = - 0.02 ,
613- transmission_factor = 0 , npoints = 100 ):
619+ transmission_factor = 0 , npoints = 100 , vectorize = False ):
614620 """
615621 Get front and rear irradiance using the infinite sheds model.
616622
@@ -701,7 +707,12 @@ def get_irradiance(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
701707 etc. A negative value is a reduction in back irradiance. [unitless]
702708
703709 npoints : int, default 100
704- Number of points used to discretize distance along the ground.
710+ Number of discretization points for calculating integrated view
711+ factors.
712+
713+ vectorize : bool, default False
714+ If True, vectorize the view factor calculation across ``surface_tilt``.
715+ This increases speed with the cost of increased memory usage.
705716
706717 Returns
707718 -------
@@ -756,14 +767,14 @@ def get_irradiance(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth,
756767 solar_zenith = solar_zenith , solar_azimuth = solar_azimuth ,
757768 gcr = gcr , height = height , pitch = pitch , ghi = ghi , dhi = dhi , dni = dni ,
758769 albedo = albedo , model = model , dni_extra = dni_extra , iam = iam_front ,
759- npoints = npoints )
770+ npoints = npoints , vectorize = vectorize )
760771 # back side POA irradiance
761772 irrad_back = get_irradiance_poa (
762773 surface_tilt = backside_tilt , surface_azimuth = backside_sysaz ,
763774 solar_zenith = solar_zenith , solar_azimuth = solar_azimuth ,
764775 gcr = gcr , height = height , pitch = pitch , ghi = ghi , dhi = dhi , dni = dni ,
765776 albedo = albedo , model = model , dni_extra = dni_extra , iam = iam_back ,
766- npoints = npoints )
777+ npoints = npoints , vectorize = vectorize )
767778
768779 colmap_front = {
769780 'poa_global' : 'poa_front' ,
0 commit comments