def apply_decomposition_model(weather_df, model, location): """ Uses the specified decomposition model to calculate DNI and DHI. Parameters ---------- weather_df : :pandas:`DataFrame` Weather DataFrame containing all variables needed to apply the decomposition model. See model functions for more information. model : :obj:`str` Decomposition model to use. Choose from 'reindl', 'erbs' or 'disc'. location : :pvlib:`Location` Returns ------- :pandas:`DataFrame` DataFrame with DNI and DHI. """ solar_position = location.get_solarposition( weather_df.index, pressure=weather_df['pressure'].mean(), temperature=weather_df['temp_air'].mean()) if model == 'reindl': solar_position = location.get_solarposition( weather_df.index, pressure=weather_df['pressure'].mean(), temperature=weather_df['temp_air'].mean()) df = reindl(weather_df.ghi, weather_df.i0_h, solar_position.elevation) df['dni_corrected'] = irradiance.dni( weather_df['ghi'], df['dhi'], solar_position.zenith, clearsky_dni=location.get_clearsky( weather_df.index, solar_position=solar_position).dni, clearsky_tolerance=1.1, zenith_threshold_for_zero_dni=88.0, zenith_threshold_for_clearsky_limit=80.0) elif model == 'erbs': df = irradiance.erbs(weather_df.ghi, solar_position.zenith, weather_df.index) df['dni_corrected'] = irradiance.dni( weather_df['ghi'], df['dhi'], solar_position.zenith, clearsky_dni=location.get_clearsky( weather_df.index, solar_position=solar_position).dni, clearsky_tolerance=1.1, zenith_threshold_for_zero_dni=88.0, zenith_threshold_for_clearsky_limit=80.0) elif model == 'disc': df = irradiance.disc(weather_df.ghi, solar_position.zenith, weather_df.index, weather_df.pressure.mean()) df['dhi'] = weather_df.ghi - df.dni * pvlib.tools.cosd( solar_position.zenith) df['gni'] = df.dni + df.dhi return df
def test_erbs_min_cos_zenith_max_zenith(): # map out behavior under difficult conditions with various # limiting kwargs settings columns = ['dni', 'dhi', 'kt'] times = pd.DatetimeIndex(['2016-07-19 06:11:00'], tz='America/Phoenix') # max_zenith keeps these results reasonable out = irradiance.erbs(ghi=1.0, zenith=89.99999, datetime_or_doy=times, min_cos_zenith=0) expected = pd.DataFrame(np.array([[0., 1., 1.]]), columns=columns, index=times) assert_frame_equal(out, expected) # 4-5 9s will produce bad behavior without max_zenith limit out = irradiance.erbs(ghi=1.0, zenith=89.99999, datetime_or_doy=times, max_zenith=100) expected = pd.DataFrame(np.array( [[6.00115286e+03, 9.98952601e-01, 1.16377640e-02]]), columns=columns, index=times) assert_frame_equal(out, expected) # 1-2 9s will produce bad behavior without either limit out = irradiance.erbs(ghi=1.0, zenith=89.99, datetime_or_doy=times, min_cos_zenith=0, max_zenith=100) expected = pd.DataFrame(np.array( [[4.78419761e+03, 1.65000000e-01, 1.00000000e+00]]), columns=columns, index=times) assert_frame_equal(out, expected) # check default behavior under hardest condition out = irradiance.erbs(ghi=1.0, zenith=90, datetime_or_doy=times) expected = pd.DataFrame(np.array([[0., 1., 0.01163776]]), columns=columns, index=times) assert_frame_equal(out, expected)
def test_erbs_all_scalar(): ghi = 1000 zenith = 10 doy = 180 expected = pd.DataFrame(np. array([[ 8.42358014e+02, 1.70439297e+02, 7.68919470e-01]]), columns=['dni', 'dhi', 'kt']) out = irradiance.erbs(ghi, zenith, doy) assert_frame_equal(out, expected)
def test_erbs_all_scalar(): ghi = 1000 zenith = 10 doy = 180 expected = pd.DataFrame(np.array( [[8.42358014e+02, 1.70439297e+02, 7.68919470e-01]]), columns=['dni', 'dhi', 'kt']) out = irradiance.erbs(ghi, zenith, doy) assert_frame_equal(out, expected)
def dhi(self, time, lat, lon, ghi): dhi = [] try: ghi = self.ghi(ghi) zenith = self.zenith(time, lat, lon) dhi = irradiance.erbs(ghi, zenith, time)['dhi'] except Exception as e: f = sys.exc_info()[2].tb_frame.f_back print("error: %s, line %s, in %s" % (f.f_code.co_filename, str(f.f_lineno), f.f_code.co_name)) print(e) return (dhi)
def calc_dhi_erbs(self, time_range, ghi): """ Compute the dhi-value based on given ghi value within a time range using the ERBS algortihm. Parameter: ========== time_range: pandas Series - time range. ghi: pandas Series - with global horizontal irradiance (ghi) >> taken from DWD Forecast. [W/m2] """ dhi = erbs(ghi=ghi, zenith=self.solpos.zenith, datetime_or_doy=time_range) return dhi
def test_erbs_all_scalar(): ghi = 1000 zenith = 10 doy = 180 expected = OrderedDict() expected['dni'] = 8.42358014e+02 expected['dhi'] = 1.70439297e+02 expected['kt'] = 7.68919470e-01 out = irradiance.erbs(ghi, zenith, doy) for k, v in out.items(): assert_allclose(v, expected[k], 5)
def test_erbs(): ghi = pd.Series([0, 50, 1000, 1000]) zenith = pd.Series([120, 85, 10, 10]) doy = pd.Series([1, 1, 1, 180]) expected = pd.DataFrame(np. array([[ -0.00000000e+00, 0.00000000e+00, -0.00000000e+00], [ 9.67127061e+01, 4.15709323e+01, 4.05715990e-01], [ 7.94187742e+02, 2.17877755e+02, 7.18119416e-01], [ 8.42358014e+02, 1.70439297e+02, 7.68919470e-01]]), columns=['dni', 'dhi', 'kt']) out = irradiance.erbs(ghi, zenith, doy) assert_frame_equal(np.round(out, 0), np.round(expected, 0))
def test_erbs(): ghi = pd.Series([0, 50, 1000, 1000]) zenith = pd.Series([120, 85, 10, 10]) doy = pd.Series([1, 1, 1, 180]) expected = pd.DataFrame(np.array( [[-0.00000000e+00, 0.00000000e+00, -0.00000000e+00], [9.67127061e+01, 4.15709323e+01, 4.05715990e-01], [7.94187742e+02, 2.17877755e+02, 7.18119416e-01], [8.42358014e+02, 1.70439297e+02, 7.68919470e-01]]), columns=['dni', 'dhi', 'kt']) out = irradiance.erbs(ghi, zenith, doy) assert_frame_equal(np.round(out, 0), np.round(expected, 0))
def test_erbs(): index = pd.DatetimeIndex(['20190101'] * 3 + ['20190620']) ghi = pd.Series([0, 50, 1000, 1000], index=index) zenith = pd.Series([120, 85, 10, 10], index=index) expected = pd.DataFrame(np.array( [[0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [9.67192672e+01, 4.15703604e+01, 4.05723511e-01], [7.94205651e+02, 2.17860117e+02, 7.18132729e-01], [8.42001578e+02, 1.70790318e+02, 7.68214312e-01]]), columns=['dni', 'dhi', 'kt'], index=index) out = irradiance.erbs(ghi, zenith, index) assert_frame_equal(np.round(out, 0), np.round(expected, 0))
def ghi_from_obstruction(GHI, sza, obstr, SVF, doy): """ Description of ghi_from_obstruction Returns solar irradiance value for a location Args: GHI (undefined): Global Horizontal Irradiance sza (undefined): Solar Zenith Angle in degrees obstr (undefined): Obstruction information calculated with get_obstruction method SVF (undefined): Sky View Factor doy (undefined): Day of the year """ sol = erbs(GHI, sza, doy) if obstr != 0: obstr = 0 else: obstr = 1 return sol['dni'] * np.cos(np.deg2rad(sza)) * obstr + SVF * sol['dhi']
def time_erbs(self): irradiance.erbs(self.clearsky_irradiance.ghi, self.solar_position.apparent_zenith, self.times)