|
12 | 12 | import pandas as pd |
13 | 13 |
|
14 | 14 | from pvlib import atmosphere, solarposition, tools |
| 15 | +import pvlib # used to avoid dni name collision in complete_irradiance |
15 | 16 |
|
16 | 17 |
|
17 | 18 | # see References section of get_ground_diffuse function |
@@ -2948,3 +2949,67 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1, |
2948 | 2949 | (zenith < zenith_threshold_for_zero_dni) & |
2949 | 2950 | (dni > max_dni)] = max_dni |
2950 | 2951 | return dni |
| 2952 | + |
| 2953 | + |
| 2954 | +def complete_irradiance(solar_zenith, |
| 2955 | + ghi=None, |
| 2956 | + dhi=None, |
| 2957 | + dni=None, |
| 2958 | + dni_clear=None): |
| 2959 | + r""" |
| 2960 | + Use the component sum equations to calculate the missing series, using |
| 2961 | + the other available time series. One of the three parameters (ghi, dhi, |
| 2962 | + dni) is passed as None, and the other associated series passed are used to |
| 2963 | + calculate the missing series value. |
| 2964 | +
|
| 2965 | + The "component sum" or "closure" equation relates the three |
| 2966 | + primary irradiance components as follows: |
| 2967 | +
|
| 2968 | + .. math:: |
| 2969 | +
|
| 2970 | + GHI = DHI + DNI \cos(\theta_z) |
| 2971 | +
|
| 2972 | + Parameters |
| 2973 | + ---------- |
| 2974 | + solar_zenith : Series |
| 2975 | + Zenith angles in decimal degrees, with datetime index. |
| 2976 | + Angles must be >=0 and <=180. Must have the same datetime index |
| 2977 | + as ghi, dhi, and dni series, when available. |
| 2978 | + ghi : Series, optional |
| 2979 | + Pandas series of dni data, with datetime index. Must have the same |
| 2980 | + datetime index as dni, dhi, and zenith series, when available. |
| 2981 | + dhi : Series, optional |
| 2982 | + Pandas series of dni data, with datetime index. Must have the same |
| 2983 | + datetime index as ghi, dni, and zenith series, when available. |
| 2984 | + dni : Series, optional |
| 2985 | + Pandas series of dni data, with datetime index. Must have the same |
| 2986 | + datetime index as ghi, dhi, and zenith series, when available. |
| 2987 | + dni_clear : Series, optional |
| 2988 | + Pandas series of clearsky dni data. Must have the same datetime index |
| 2989 | + as ghi, dhi, dni, and zenith series, when available. See |
| 2990 | + :py:func:`dni` for details. |
| 2991 | +
|
| 2992 | + Returns |
| 2993 | + ------- |
| 2994 | + component_sum_df : Dataframe |
| 2995 | + Pandas series of 'ghi', 'dhi', and 'dni' columns with datetime index |
| 2996 | + """ |
| 2997 | + if ghi is not None and dhi is not None and dni is None: |
| 2998 | + dni = pvlib.irradiance.dni(ghi, dhi, solar_zenith, |
| 2999 | + clearsky_dni=dni_clear, |
| 3000 | + clearsky_tolerance=1.1) |
| 3001 | + elif dni is not None and dhi is not None and ghi is None: |
| 3002 | + ghi = (dhi + dni * tools.cosd(solar_zenith)) |
| 3003 | + elif dni is not None and ghi is not None and dhi is None: |
| 3004 | + dhi = (ghi - dni * tools.cosd(solar_zenith)) |
| 3005 | + else: |
| 3006 | + raise ValueError( |
| 3007 | + "Please check that exactly one of ghi, dhi and dni parameters " |
| 3008 | + "is set to None" |
| 3009 | + ) |
| 3010 | + # Merge the outputs into a master dataframe containing 'ghi', 'dhi', |
| 3011 | + # and 'dni' columns |
| 3012 | + component_sum_df = pd.DataFrame({'ghi': ghi, |
| 3013 | + 'dhi': dhi, |
| 3014 | + 'dni': dni}) |
| 3015 | + return component_sum_df |
0 commit comments