Esempio n. 1
0
def test_detect_clearsky_iterations(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    alpha = 1.0448
    with pytest.warns(RuntimeWarning):
        clear_samples = clearsky.detect_clearsky(
            expected['GHI'], cs['ghi']*alpha, cs.index, 10, max_iterations=1)
    assert (clear_samples[:'2012-04-01 10:41:00'] == True).all()
    assert (clear_samples['2012-04-01 10:42:00':] == False).all()
    clear_samples = clearsky.detect_clearsky(
            expected['GHI'], cs['ghi']*alpha, cs.index, 10, max_iterations=20)
    assert_series_equal(expected['Clear or not'], clear_samples,
                        check_dtype=False, check_names=False)
Esempio n. 2
0
def test_detect_clearsky_kwargs(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(
        expected['GHI'], cs['ghi'], cs.index, 10,
        mean_diff=1000, max_diff=1000, lower_line_length=-1000,
        upper_line_length=1000, var_diff=10, slope_dev=1000)
    assert clear_samples.all()
def test_detect_clearsky_arrays(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(expected['GHI'].values,
                                             cs['ghi'].values,
                                             times=cs.index,
                                             window_length=10)
    assert isinstance(clear_samples, np.ndarray)
    assert (clear_samples == expected['Clear or not'].values).all()
Esempio n. 4
0
def test_detect_clearsky_irregular_times(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    times = cs.index.values.copy()
    times[0] += 10**9
    times = pd.DatetimeIndex(times)
    with pytest.raises(NotImplementedError):
        clear_samples = clearsky.detect_clearsky(
            expected['GHI'].values, cs['ghi'].values, times, 10)
Esempio n. 5
0
def test_detect_clearsky_components(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples, components, alpha = clearsky.detect_clearsky(
        expected['GHI'], cs['ghi'], cs.index, 10, return_components=True)
    assert_series_equal(expected['Clear or not'], clear_samples,
                        check_dtype=False, check_names=False)
    assert isinstance(components, OrderedDict)
    assert np.allclose(alpha, 0.95345573579557108)
Esempio n. 6
0
def test_detect_clearsky_irregular_times(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    times = cs.index.values.copy()
    times[0] += 10**9
    times = pd.DatetimeIndex(times)
    with pytest.raises(NotImplementedError):
        clear_samples = clearsky.detect_clearsky(
            expected['GHI'].values, cs['ghi'].values, times, 10)
Esempio n. 7
0
def test_detect_clearsky(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(expected['GHI'], cs['ghi'],
                                             cs.index, 10)
    assert_series_equal(expected['Clear or not'],
                        clear_samples,
                        check_dtype=False,
                        check_names=False)
Esempio n. 8
0
def test_detect_clearsky_components(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples, components, alpha = clearsky.detect_clearsky(
        expected['GHI'], cs['ghi'], cs.index, 10, return_components=True)
    assert_series_equal(expected['Clear or not'], clear_samples,
                        check_dtype=False, check_names=False)
    assert isinstance(components, OrderedDict)
    assert np.allclose(alpha, 0.9633903181941296)
Esempio n. 9
0
def test_detect_clearsky_window(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(
        expected['GHI'], cs['ghi'], cs.index, 3)
    expected = expected['Clear or not'].copy()
    expected.iloc[-3:] = True
    assert_series_equal(expected, clear_samples,
                        check_dtype=False, check_names=False)
Esempio n. 10
0
def test_detect_clearsky_window(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(
        expected['GHI'], cs['ghi'], cs.index, 3)
    expected = expected['Clear or not'].copy()
    expected.iloc[-3:] = True
    assert_series_equal(expected, clear_samples,
                        check_dtype=False, check_names=False)
def test_detect_clearsky_iterations(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    alpha = 1.0448
    with pytest.warns(RuntimeWarning):
        clear_samples = clearsky.detect_clearsky(expected['GHI'],
                                                 cs['ghi'] * alpha,
                                                 cs.index,
                                                 10,
                                                 max_iterations=1)
    assert (clear_samples[:'2012-04-01 10:41:00'] == True).all()
    assert (clear_samples['2012-04-01 10:42:00':] == False).all()
    clear_samples = clearsky.detect_clearsky(expected['GHI'],
                                             cs['ghi'] * alpha,
                                             cs.index,
                                             10,
                                             max_iterations=20)
    assert_series_equal(expected['Clear or not'],
                        clear_samples,
                        check_dtype=False,
                        check_names=False)
Esempio n. 12
0
def test_detect_clearsky_time_interval(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    u = np.arange(0, len(cs), 2)
    cs2 = cs.iloc[u]
    expected2 = expected.iloc[u]
    clear_samples = clearsky.detect_clearsky(expected2['GHI'],
                                             cs2['ghi'],
                                             window_length=6)
    assert_series_equal(expected2['Clear or not'],
                        clear_samples,
                        check_dtype=False,
                        check_names=False)
def test_detect_clearsky_kwargs(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(expected['GHI'],
                                             cs['ghi'],
                                             cs.index,
                                             10,
                                             mean_diff=1000,
                                             max_diff=1000,
                                             lower_line_length=-1000,
                                             upper_line_length=1000,
                                             var_diff=10,
                                             slope_dev=1000)
    assert clear_samples.all()
Esempio n. 14
0
def test_detect_clearsky_arrays(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(
        expected['GHI'].values, cs['ghi'].values, cs.index, 10)
    assert isinstance(clear_samples, np.ndarray)
    assert (clear_samples == expected['Clear or not'].values).all()
Esempio n. 15
0
def test_detect_clearsky_missing_index(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    with pytest.raises(ValueError):
        clearsky.detect_clearsky(expected['GHI'].values, cs['ghi'].values)
Esempio n. 16
0
def test_detect_clearsky(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(
        expected['GHI'], cs['ghi'], cs.index, 10)
    assert_series_equal(expected['Clear or not'], clear_samples,
                        check_dtype=False, check_names=False)
 def time_detect_clearsky(self, ndays):
     clearsky.detect_clearsky(
         self.measured, self.clearsky, self.times, self.window_length
     )
Esempio n. 18
0
def find_clearsky_poa(df,
                      lat,
                      lon,
                      irradiance_poa_key='irradiance_poa_o_###',
                      mounting='fixed',
                      tilt=0,
                      azimuth=180,
                      altitude=0):
    loc = Location(lat, lon, altitude=altitude)

    CS = loc.get_clearsky(df.index)

    df['csghi'] = CS.ghi
    df['csdhi'] = CS.dhi
    df['csdni'] = CS.dni

    if mounting.lower() == "fixed":
        sun = get_solarposition(df.index, lat, lon)

        fixedpoa = get_total_irradiance(tilt, azimuth, sun.zenith, sun.azimuth,
                                        CS.dni, CS.ghi, CS.dhi)

        df['cspoa'] = fixedpoa.poa_global

    if mounting.lower() == "tracking":
        sun = get_solarposition(df.index, lat, lon)

        # default to axis_tilt=0 and axis_azimuth=180

        tracker_data = singleaxis(sun.apparent_zenith,
                                  sun.azimuth,
                                  axis_tilt=tilt,
                                  axis_azimuth=azimuth,
                                  max_angle=50,
                                  backtrack=True,
                                  gcr=0.35)

        track = get_total_irradiance(tracker_data['surface_tilt'],
                                     tracker_data['surface_azimuth'],
                                     sun.zenith, sun.azimuth, CS.dni, CS.ghi,
                                     CS.dhi)

        df['cspoa'] = track.poa_global

    # the following code is assuming clear sky poa has been generated per pvlib, aligned in the same
    # datetime index, and daylight savings or any time shifts were previously corrected
    # the inputs below were tuned for POA at a 15 minute frequency
    # note that detect_clearsky has a scaling factor but I still got slightly different results when I scaled measured poa first

    df['poa'] = df[irradiance_poa_key] / df[irradiance_poa_key].quantile(
        0.98) * df.cspoa.quantile(0.98)

    # inputs for detect_clearsky

    measured = df.poa.copy()
    clear = df.cspoa.copy()
    dur = 60
    lower_line_length = -41.416
    upper_line_length = 77.789
    var_diff = .00745
    mean_diff = 80
    max_diff = 90
    slope_dev = 3

    is_clear_results = detect_clearsky(measured.values,
                                       clear.values,
                                       df.index,
                                       dur,
                                       mean_diff,
                                       max_diff,
                                       lower_line_length,
                                       upper_line_length,
                                       var_diff,
                                       slope_dev,
                                       return_components=True)

    clearSeries = pd.Series(index=df.index, data=is_clear_results[0])

    clearSeries = clearSeries.reindex(index=df.index, method='ffill', limit=3)

    return clearSeries