def generate_synthetic_clearsky_clearness_index(location, time, accuracy="30min", sun_position=None): """ Generate clearsky kt synthetic time series :param location: :param time: :param accuracy: :param sun_position :return: DataFrame with kt, clearsky and toa columns """ if sun_position is None: sun_position = get_solar_position( date_range(time[0], time[-1], freq=accuracy), location.latitude, location.longitude, location.altitude) clearsky = generate_synthetic_clear_sky_irradiation( time, location, sun_position=sun_position, accuracy=accuracy) toa = generate_synthetic_toa_irradiation(time, location, sun_position=sun_position, accuracy=accuracy) kt = clearsky / toa kt[toa == 0] = 0 return DataFrame({"kt": kt, "clearsky": clearsky, "toa": toa})
def generate_daily_toa_and_clear_sky_sequence(location, accuracy, base_year): """ Generate sequence of daily TOA and clear-sky irradiation over the year Compute both at the same time in order to speed up computation :param location: :param accuracy: :param base_year: :return: """ time = date_range("1/1/%d" % base_year, "1/1/%d" % (base_year + 1), freq="1D", tz=location.tz) sun_position = get_solar_position( date_range(time[0], time[-1], freq=accuracy), location.latitude, location.longitude, location.altitude) return generate_synthetic_toa_irradiation(time, location, sun_position, accuracy), \ generate_synthetic_clear_sky_irradiation(time, location, sun_position, accuracy)
def generate_toa_sequence(time, location=None, sun_position=None): """ Generate TOA irradiance sequence :param time: :param location: pvlib.location.Location object :param sun_position: :return: """ if sun_position is None: try: sun_position = get_solar_position(time, location.latitude, location.longitude, location.altitude) except AttributeError: raise ValueError( "Either 'location' or 'sun_position' must be passed as input argument" ) return Series(toa_radiation(sun_position["elevation"]), time)
def generate_clearsky_clearness_index_sequence(location, time, sun_position=None): """ Generate clear-sky kt and toa/cls irradiance time series :param location: :param time: :param sun_position: :return: """ if sun_position is None: sun_position = get_solar_position(time, location.latitude, location.longitude, location.altitude) clearsky = generate_clearsky_sequence(time, location, sun_position) toa = generate_toa_sequence(time, sun_position=sun_position) kt = clearsky / toa kt[toa == 0] = 0 return DataFrame({"kt": kt, "clearsky": clearsky, "toa": toa})
def generate_hourly_ghi_sequence(daily_kt, daily_kc, daily_toa, location, accuracy="30min", base_year=2018, tolerance=0.05): """ Generate sequence of hourly Global Horizontal Irradiation :param daily_kt: Series of daily kt values :param daily_kc: Series of daily kc values :param daily_toa: Series of daily TOA irradiation values :param location: pvlib.location.Location object :param accuracy: :param base_year: :param tolerance: relative tolerance for resulting GHI :return: Series of hourly GHI """ time_centre = date_range("1/1/%d 0:30" % base_year, '12/31/%d 23:30' % base_year, freq="1H", tz=location.tz) time_hourly = date_range("1/1/%d 0:00" % base_year, "1/1/%d 0:00" % (base_year + 1), freq="1H", tz=location.tz) sun_position = get_solar_position(time_centre, location.latitude, location.longitude, location.altitude) sunrise, sunset = get_sunrise_and_sunset(daily_kc.index, location) df = generate_synthetic_clearsky_clearness_index(location, time_hourly, accuracy=accuracy) hourly_kt = Series( generate_hourly_kt_sequence(daily_kt, daily_kc, daily_toa, sun_position["apparent_elevation"], sunrise, sunset, df, tolerance), df.index) ghi = df["toa"] * hourly_kt return ghi
def erbs(ghi, location=None, sun_position=None, kt=None): """ Retrieve DNI and DHI from GHI using Erbs model :param ghi: Series of GHI values :param location: :param sun_position: :param kt: clearness index :return: dhi and dni """ if sun_position is None: try: sun_position = get_solar_position(ghi.index, location.latitude, location.longitude, location.altitude) except AttributeError: raise ValueError( "Either 'location' or 'sun_position' argument must be passed") if kt is None: toa = generate_toa_sequence(ghi.index, sun_position=sun_position) kt = ghi / toa kt[toa == 0] = 0 # Diffuse fraction # kt <= 0.22 kd = 1 - 0.09 * kt # kt > 0.22 and kt <= 0.8 kd = kd.where( (kt <= 0.22) | (kt > 0.8), 0.9511 - 0.1604 * kt + 4.388 * kt**2 - 16.638 * kt**3 + 12.336 * kt**4) # kt > 0.8 kd[kt > 0.8] = 0.165 dhi = kd * ghi dni = (ghi - dhi) / np.cos(sun_position["zenith"] * np.pi / 180) return DataFrame({'dni': dni, 'dhi': dhi, 'kt': kt, 'kd': kd})
def generate_clearsky_sequence(time, location, sun_position=None, p_0=101325.0, model="ineichen"): """ Generate clear-sky irradiance sequence :param time: :param location: pvlib.location.Location object :param sun_position: :param p_0: sea level pressure :param model: {'ineichen', 'solis'} #TODO: implement solis clearsky model :return: """ if sun_position is None: sun_position = get_solar_position(time, location.latitude, location.longitude, location.altitude) # Altitude corrected (King et al. 1997; Rigollier et al. 2000) pressure = p_0 * np.exp(-0.0001184 * location.altitude) # Relative airmass am = get_relative_airmass(sun_position["zenith"]) # Absolute airmass am_a = get_absolute_airmass(am, pressure) # Linke turbidity linke_turbidity = lookup_linke_turbidity(time, location.latitude, location.longitude) if model == "ineichen": return ineichen(sun_position["apparent_zenith"], am_a, linke_turbidity)["ghi"] elif model == "solis": pass
# Diffuse fraction # kt <= 0.22 kd = 1 - 0.09 * kt # kt > 0.22 and kt <= 0.8 kd = kd.where( (kt <= 0.22) | (kt > 0.8), 0.9511 - 0.1604 * kt + 4.388 * kt**2 - 16.638 * kt**3 + 12.336 * kt**4) # kt > 0.8 kd[kt > 0.8] = 0.165 dhi = kd * ghi dni = (ghi - dhi) / np.cos(sun_position["zenith"] * np.pi / 180) return DataFrame({'dni': dni, 'dhi': dhi, 'kt': kt, 'kd': kd}) if __name__ == "__main__": import pvlib time = date_range("1/1/2011", "12/31/2011", freq="30 min") loc = pvlib.location.Location(42, 9) sun_pos = get_solar_position(time, loc.latitude, loc.longitude, loc.altitude) clearsky = generate_clearsky_sequence(time, loc) with Timer() as t: diff_frac = erbs(clearsky, location=loc) print("time: %s" % t) for col in diff_frac: print(col)