def test_earthsun_distance(): times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D') assert_almost_equals( 1, solarposition.pyephem_earthsun_distance(times).values[0], 0)
def test_earthsun_distance(): times = pd.date_range(datetime.datetime(2003, 10, 17, 13, 30, 30), periods=1, freq='D') distance = solarposition.pyephem_earthsun_distance(times).values[0] assert_allclose(1, distance, atol=0.1)
def extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): """ Determine extraterrestrial radiation from day of year. Parameters ---------- datetime_or_doy : int, float, array, pd.DatetimeIndex 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'``. Returns ------- float or Series 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. '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. 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] <http://solardat.uoregon.edu/SolarRadiationBasics.html>, Eqs. SR1 and SR2 [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, 2nd edn. J. Wiley and Sons, New York. See Also -------- pvlib.clearsky.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? doy = datetime_or_doy input_to_datetimeindex = _array_to_datetimeindex 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) + 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 extraradiation(datetime_or_doy, solar_constant=1366.1, method='spencer'): """ Determine extraterrestrial radiation from day of year. Parameters ---------- datetime_or_doy : int, float, array, pd.DatetimeIndex 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'``. Returns ------- float or Series 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. '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. 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] <http://solardat.uoregon.edu/SolarRadiationBasics.html>, Eqs. SR1 and SR2 [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, 2nd edn. J. Wiley and Sons, New York. See Also -------- pvlib.clearsky.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? doy = datetime_or_doy input_to_datetimeindex = _array_to_datetimeindex 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) + 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 test_earthsun_distance(): times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, freq='D') assert_almost_equals(1, solarposition.pyephem_earthsun_distance(times).values[0], 0)
def test_earthsun_distance(): times = pd.date_range(datetime.datetime(2003,10,17,13,30,30), periods=1, freq='D') distance = solarposition.pyephem_earthsun_distance(times).values[0] assert_allclose(1, distance, atol=0.1)