Example #1
0
def test_orientation_fit_pvwatts_missing_data(naive_times):
    tilt = 30
    azimuth = 100
    system_location = location.Location(35, -106)
    local_time = naive_times.tz_localize('MST')
    clearsky = system_location.get_clearsky(local_time,
                                            model='simplified_solis')
    clearsky.loc['3/1/2020':'3/15/2020'] = np.nan
    solar_position = system_location.get_solarposition(clearsky.index)
    solar_position.loc['3/1/2020':'3/15/2020'] = np.nan
    poa = irradiance.get_total_irradiance(tilt, azimuth,
                                          solar_position['zenith'],
                                          solar_position['azimuth'],
                                          **clearsky)
    temp_cell = pvlib.temperature.sapm_cell(
        poa['poa_global'], 25, 0,
        **pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']
        ['open_rack_glass_glass'])
    pdc = pvsystem.pvwatts_dc(poa['poa_global'], temp_cell, 100, -0.002)
    pac = pvsystem.inverter.pvwatts(pdc, 120)
    solar_position.dropna(inplace=True)
    with pytest.raises(ValueError,
                       match=".* must not contain undefined values"):
        system.infer_orientation_fit_pvwatts(
            pac,
            solar_zenith=solar_position['zenith'],
            solar_azimuth=solar_position['azimuth'],
            **clearsky)
    pac.dropna(inplace=True)
    with pytest.raises(ValueError,
                       match=".* must not contain undefined values"):
        system.infer_orientation_fit_pvwatts(
            pac,
            solar_zenith=solar_position['zenith'],
            solar_azimuth=solar_position['azimuth'],
            **clearsky)
    clearsky.dropna(inplace=True)
    tilt_out, azimuth_out, rsquared = system.infer_orientation_fit_pvwatts(
        pac,
        solar_zenith=solar_position['zenith'],
        solar_azimuth=solar_position['azimuth'],
        **clearsky)
    assert rsquared > 0.9
    assert tilt_out == pytest.approx(tilt, abs=10)
    assert azimuth_out == pytest.approx(azimuth, abs=10)
Example #2
0
def test_orientation_fit_pvwatts(system_power):
    day_mask = system_power['ac'] > 0
    tilt, azimuth, rsquared = system.infer_orientation_fit_pvwatts(
        system_power['ac'][day_mask],
        solar_zenith=system_power['solar_position']['zenith'][day_mask],
        solar_azimuth=system_power['solar_position']['azimuth'][day_mask],
        **system_power['clearsky'][day_mask])
    assert rsquared > 0.9
    assert tilt == pytest.approx(system_power['tilt'], abs=10)
    if system_power['tilt'] == 0:
        # Any azimuth will give the same results at tilt 0.
        return
    if system_power['azimuth'] == 0:
        # 0 degrees equals 360 degrees.
        assert (azimuth == pytest.approx(0, abs=10)
                or azimuth == pytest.approx(360, abs=10))
    else:
        assert azimuth == pytest.approx(system_power['azimuth'], abs=10)
Example #3
0
def test_orientation_fit_pvwatts_temp_wind_as_series(naive_times):
    tilt = 30
    azimuth = 100
    system_location = location.Location(35, -106)
    local_time = naive_times.tz_localize('MST')
    clearsky = system_location.get_clearsky(local_time,
                                            model='simplified_solis')
    solar_position = system_location.get_solarposition(clearsky.index)
    poa = irradiance.get_total_irradiance(tilt, azimuth,
                                          solar_position['zenith'],
                                          solar_position['azimuth'],
                                          **clearsky)
    temp_cell = pvlib.temperature.sapm_cell(
        poa['poa_global'], 25, 1,
        **pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']
        ['open_rack_glass_glass'])
    temperature = pd.Series(25, index=clearsky.index)
    wind_speed = pd.Series(1, index=clearsky.index)
    temperature_missing = temperature.copy()
    temperature_missing.loc['4/5/2020':'4/10/2020'] = np.nan
    wind_speed_missing = wind_speed.copy()
    wind_speed_missing.loc['5/5/2020':'5/15/2020'] = np.nan
    pdc = pvsystem.pvwatts_dc(poa['poa_global'], temp_cell, 100, -0.002)
    pac = pvsystem.inverter.pvwatts(pdc, 120)
    with pytest.raises(ValueError,
                       match=".* must not contain undefined values"):
        system.infer_orientation_fit_pvwatts(
            pac,
            solar_zenith=solar_position['zenith'],
            solar_azimuth=solar_position['azimuth'],
            temperature=temperature_missing,
            wind_speed=wind_speed_missing,
            **clearsky)
    with pytest.raises(ValueError,
                       match="temperature must not contain undefined values"):
        system.infer_orientation_fit_pvwatts(
            pac,
            solar_zenith=solar_position['zenith'],
            solar_azimuth=solar_position['azimuth'],
            temperature=temperature_missing,
            wind_speed=wind_speed,
            **clearsky)
    with pytest.raises(ValueError,
                       match="wind_speed must not contain undefined values"):
        system.infer_orientation_fit_pvwatts(
            pac,
            solar_zenith=solar_position['zenith'],
            solar_azimuth=solar_position['azimuth'],
            temperature=temperature,
            wind_speed=wind_speed_missing,
            **clearsky)
    # ValueError if indices don't match
    with pytest.raises(ValueError):
        system.infer_orientation_fit_pvwatts(
            pac,
            solar_zenith=solar_position['zenith'],
            solar_azimuth=solar_position['azimuth'],
            temperature=temperature_missing.dropna(),
            wind_speed=wind_speed_missing.dropna(),
            **clearsky)
    tilt_out, azimuth_out, rsquared = system.infer_orientation_fit_pvwatts(
        pac,
        solar_zenith=solar_position['zenith'],
        solar_azimuth=solar_position['azimuth'],
        **clearsky)
    assert rsquared > 0.9
    assert tilt_out == pytest.approx(tilt, abs=10)
    assert azimuth_out == pytest.approx(azimuth, abs=10)