示例#1
0
def test_infer_dc_model(system, cec_dc_snl_ac_system, pvsyst_dc_snl_ac_system,
                        pvwatts_dc_pvwatts_ac_system, location, dc_model,
                        weather, mocker):
    dc_systems = {'sapm': system,
                  'cec': cec_dc_snl_ac_system,
                  'desoto': cec_dc_snl_ac_system,
                  'pvsyst': pvsyst_dc_snl_ac_system,
                  'singlediode': cec_dc_snl_ac_system,
                  'pvwatts_dc': pvwatts_dc_pvwatts_ac_system}
    dc_model_function = {'sapm': 'sapm',
                         'cec': 'calcparams_cec',
                         'desoto': 'calcparams_desoto',
                         'pvsyst': 'calcparams_pvsyst',
                         'singlediode': 'calcparams_desoto',
                         'pvwatts_dc': 'pvwatts_dc'}
    system = dc_systems[dc_model]
    # remove Adjust from model parameters for desoto, singlediode
    if dc_model in ['desoto', 'singlediode']:
        system.module_parameters.pop('Adjust')
    m = mocker.spy(system, dc_model_function[dc_model])
    mc = ModelChain(system, location,
                    aoi_model='no_loss', spectral_model='no_loss')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert isinstance(mc.dc, (pd.Series, pd.DataFrame))
示例#2
0
def test_aoi_model_no_loss(system, location, weather):
    mc = ModelChain(system, location, dc_model='sapm',
                    aoi_model='no_loss', spectral_model='no_loss')
    mc.run_model(weather.index, weather=weather)
    assert mc.aoi_modifier == 1.0
    assert not mc.ac.empty
    assert mc.ac[0] > 150 and mc.ac[0] < 200
    assert mc.ac[1] < 1
示例#3
0
def test_run_model(system, location):
    mc = ModelChain(system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array([  1.82033564e+02,  -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected, check_less_precise=2)
示例#4
0
def test_spectral_models(system, location, spectral_model, expected):
    mc = ModelChain(system, location, dc_model='sapm',
                    aoi_model='no_loss', spectral_model=spectral_model)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array(expected), index=times)
    assert_series_equal(ac, expected, check_less_precise=2)
示例#5
0
def test_ac_model_user_func(pvwatts_dc_pvwatts_ac_system, location, weather,
                            mocker):
    m = mocker.spy(sys.modules[__name__], 'acdc')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, ac_model=acdc,
                    aoi_model='no_loss', spectral_model='no_loss')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert_series_equal(mc.ac, mc.dc)
    assert not mc.ac.empty
示例#6
0
def test_dc_model_user_func(pvwatts_dc_pvwatts_ac_system, location, weather,
                            mocker):
    m = mocker.spy(sys.modules[__name__], 'poadc')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, dc_model=poadc,
                    aoi_model='no_loss', spectral_model='no_loss')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, (pd.Series, pd.DataFrame))
    assert not mc.ac.empty
示例#7
0
def test_run_model_with_weather(system, location):
    mc = ModelChain(system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    weather = pd.DataFrame({'wind_speed':5, 'temp_air':10}, index=times)
    ac = mc.run_model(times, weather=weather).ac

    expected = pd.Series(np.array([  1.99952400e+02,  -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected, check_less_precise=2)
示例#8
0
def test_aoi_models(system, location, aoi_model, method, weather, mocker):
    mc = ModelChain(system, location, dc_model='sapm',
                    aoi_model=aoi_model, spectral_model='no_loss')
    m = mocker.spy(system, method)
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, pd.Series)
    assert not mc.ac.empty
    assert mc.ac[0] > 150 and mc.ac[0] < 200
    assert mc.ac[1] < 1
示例#9
0
def test_run_model_perez(system, location):
    mc = ModelChain(system, location, transposition_model='perez')
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150},
                              index=times)
    ac = mc.run_model(times, irradiance=irradiance).ac

    expected = pd.Series(np.array([  190.194545796,  -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected)
示例#10
0
def test_aoi_model_user_func(system, location, weather, mocker):
    m = mocker.spy(sys.modules[__name__], 'constant_aoi_loss')
    mc = ModelChain(system, location, dc_model='sapm',
                    aoi_model=constant_aoi_loss, spectral_model='no_loss')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert mc.aoi_modifier == 0.9
    assert not mc.ac.empty
    assert mc.ac[0] > 140 and mc.ac[0] < 200
    assert mc.ac[1] < 1
示例#11
0
def test_spectral_models(system, location, spectral_model):
    times = pd.date_range('20160101 1200-0700', periods=3, freq='6H')
    weather = pd.DataFrame(data=[0.3, 0.5, 1.0],
                           index=times,
                           columns=['precipitable_water'])
    mc = ModelChain(system, location, dc_model='sapm',
                    aoi_model='no_loss', spectral_model=spectral_model)
    spectral_modifier = mc.run_model(times=times,
                                     weather=weather).spectral_modifier
    assert isinstance(spectral_modifier, (pd.Series, float, int))
示例#12
0
def test_run_model_with_irradiance(system, location):
    mc = ModelChain(system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    irradiance = pd.DataFrame({'dni':900, 'ghi':600, 'dhi':150},
                              index=times)
    ac = mc.run_model(times, irradiance=irradiance).ac

    expected = pd.Series(np.array([  1.90054749e+02,  -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected)
示例#13
0
def test_losses_models_no_loss(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    m = mocker.spy(pvsystem, 'pvwatts_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, dc_model='pvwatts',
                    aoi_model='no_loss', spectral_model='no_loss',
                    losses_model='no_loss')
    assert mc.losses_model == mc.no_extra_losses
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 0
    assert mc.losses == 1
示例#14
0
def test_ModelChain___repr__(system, location):

    strategy = 'south_at_latitude_tilt'

    mc = ModelChain(system, location, orientation_strategy=strategy)

    assert mc.__repr__() == ('ModelChain for: PVSystem with tilt:32.2 and '+
    'azimuth: 180 with Module: None and Inverter: None '+
    'orientation_startegy: south_at_latitude_tilt clearsky_model: '+
    'ineichen transposition_model: haydavies solar_position_method: '+
    'nrel_numpy airmass_model: kastenyoung1989')
示例#15
0
def test_run_model_tracker(system, location, weather, mocker):
    system = SingleAxisTracker(module_parameters=system.module_parameters,
                               inverter_parameters=system.inverter_parameters)
    mocker.spy(system, 'singleaxis')
    mc = ModelChain(system, location)
    mc.run_model(weather.index, weather=weather)
    assert system.singleaxis.call_count == 1
    assert (mc.tracking.columns == ['tracker_theta', 'aoi', 'surface_azimuth',
                                    'surface_tilt']).all()
    assert mc.ac[0] > 0
    assert np.isnan(mc.ac[1])
示例#16
0
def test_losses_models_ext_def(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    m = mocker.spy(sys.modules[__name__], 'constant_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, dc_model='pvwatts',
                    aoi_model='no_loss', spectral_model='no_loss',
                    losses_model=constant_losses)
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, (pd.Series, pd.DataFrame))
    assert mc.losses == 0.9
    assert not mc.ac.empty
示例#17
0
def test_run_model_with_weather(system, location, weather, mocker):
    mc = ModelChain(system, location)
    m = mocker.spy(system, 'sapm_celltemp')
    weather['wind_speed'] = 5
    weather['temp_air'] = 10
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    # assert_called_once_with cannot be used with series, so need to use
    # assert_series_equal on call_args
    assert_series_equal(m.call_args[0][1], weather['wind_speed'])  # wind
    assert_series_equal(m.call_args[0][2], weather['temp_air'])  # temp
    assert not mc.ac.empty
示例#18
0
def test_weather_irradiance_input(system, location):
    """Test will raise a warning and should be removed in future versions."""
    mc = ModelChain(system, location)
    times = pd.date_range('2012-06-01 12:00:00', periods=2, freq='H')
    i = pd.DataFrame({'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times)
    w = pd.DataFrame({'wind_speed': [11, 5], 'temp_air': [30, 32]}, index=times)
    mc.run_model(times, irradiance=i, weather=w)

    assert_series_equal(mc.weather['dni'],
                        pd.Series([2, 3], index=times, name='dni'))
    assert_series_equal(mc.weather['wind_speed'],
                        pd.Series([11, 5], index=times, name='wind_speed'))
示例#19
0
def test_losses_models(pvwatts_dc_pvwatts_ac_system, location, losses_model,
                       expected):
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system,
                    location,
                    dc_model='pvwatts',
                    aoi_model='no_loss',
                    spectral_model='no_loss',
                    losses_model=losses_model)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array(expected), index=times)
    assert_series_equal(ac, expected, check_less_precise=2)
示例#20
0
def test_run_model_with_weather_fuentes_temp(sapm_dc_snl_ac_system, location,
                                             weather, mocker):
    weather['wind_speed'] = 5
    weather['temp_air'] = 10
    sapm_dc_snl_ac_system.temperature_model_parameters = {'noct_installed': 45}
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    mc.temperature_model = 'fuentes'
    m_fuentes = mocker.spy(sapm_dc_snl_ac_system, 'fuentes_celltemp')
    mc.run_model(weather)
    assert m_fuentes.call_count == 1
    assert_series_equal(m_fuentes.call_args[0][1], weather['temp_air'])
    assert_series_equal(m_fuentes.call_args[0][2], weather['wind_speed'])
    assert not mc.ac.empty
示例#21
0
def test_losses_models_pvwatts(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    age = 1
    pvwatts_dc_pvwatts_ac_system.losses_parameters = dict(age=age)
    m = mocker.spy(pvsystem, 'pvwatts_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, dc_model='pvwatts',
                    aoi_model='no_loss', spectral_model='no_loss',
                    losses_model='pvwatts')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    m.assert_called_with(age=age)
    assert isinstance(mc.ac, (pd.Series, pd.DataFrame))
    assert not mc.ac.empty
示例#22
0
def test_losses_models_pvwatts(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    age = 1
    pvwatts_dc_pvwatts_ac_system.losses_parameters = dict(age=age)
    m = mocker.spy(pvsystem, 'pvwatts_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system, location, dc_model='pvwatts',
                    aoi_model='no_loss', spectral_model='no_loss',
                    losses_model='pvwatts')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    m.assert_called_with(age=age)
    assert isinstance(mc.ac, (pd.Series, pd.DataFrame))
    assert not mc.ac.empty
示例#23
0
def test_infer_dc_model(system, cec_dc_snl_ac_system,
                        pvwatts_dc_pvwatts_ac_system, location, dc_model,
                        mocker):
    dc_systems = {'sapm': system, 'singlediode': cec_dc_snl_ac_system,
                  'pvwatts_dc': pvwatts_dc_pvwatts_ac_system}
    system = dc_systems[dc_model]
    m = mocker.spy(system, dc_model)
    mc = ModelChain(system, location,
                    aoi_model='no_loss', spectral_model='no_loss')
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    mc.run_model(times)
    assert m.call_count == 1
    assert isinstance(mc.dc, (pd.Series, pd.DataFrame))
示例#24
0
def test_aoi_models(system, location, aoi_model, method, weather, mocker):
    mc = ModelChain(system,
                    location,
                    dc_model='sapm',
                    aoi_model=aoi_model,
                    spectral_model='no_loss')
    m = mocker.spy(system, method)
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, pd.Series)
    assert not mc.ac.empty
    assert mc.ac[0] > 150 and mc.ac[0] < 200
    assert mc.ac[1] < 1
示例#25
0
def test_spectral_models(system, location, spectral_model):
    times = pd.date_range('20160101 1200-0700', periods=3, freq='6H')
    weather = pd.DataFrame(data=[0.3, 0.5, 1.0],
                           index=times,
                           columns=['precipitable_water'])
    mc = ModelChain(system,
                    location,
                    dc_model='sapm',
                    aoi_model='no_loss',
                    spectral_model=spectral_model)
    spectral_modifier = mc.run_model(times=times,
                                     weather=weather).spectral_modifier
    assert isinstance(spectral_modifier, (pd.Series, float, int))
示例#26
0
def test_run_model_with_irradiance(sapm_dc_snl_ac_system, location):
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    irradiance = pd.DataFrame({
        'dni': 900,
        'ghi': 600,
        'dhi': 150
    },
                              index=times)
    ac = mc.run_model(irradiance).ac

    expected = pd.Series(np.array([187.80746494643176, -0.02]), index=times)
    assert_series_equal(ac, expected)
示例#27
0
def test_ModelChain___repr__():
    system = PVSystem()
    location = Location(32.2, -111, altitude=700)
    strategy = 'south_at_latitude_tilt'

    mc = ModelChain(system, location, orientation_strategy=strategy)

    # the || accounts for the coercion of 'None' to None
    assert mc.__repr__() == ('ModelChain for: PVSystem with tilt:32.2 and '+
    'azimuth: 180 with Module: None and Inverter: None '+
    'orientation_startegy: south_at_latitude_tilt clearsky_model: '+
    'ineichentransposition_model: haydavies solar_position_method: '+
    'nrel_numpyairmass_model: kastenyoung1989')
示例#28
0
def test_aoi_model_user_func(system, location, weather, mocker):
    m = mocker.spy(sys.modules[__name__], 'constant_aoi_loss')
    mc = ModelChain(system,
                    location,
                    dc_model='sapm',
                    aoi_model=constant_aoi_loss,
                    spectral_model='no_loss')
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert mc.aoi_modifier == 0.9
    assert not mc.ac.empty
    assert mc.ac[0] > 140 and mc.ac[0] < 200
    assert mc.ac[1] < 1
示例#29
0
def test_losses_models_no_loss(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    m = mocker.spy(pvsystem, 'pvwatts_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system,
                    location,
                    dc_model='pvwatts',
                    aoi_model='no_loss',
                    spectral_model='no_loss',
                    losses_model='no_loss')
    assert mc.losses_model == mc.no_extra_losses
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 0
    assert mc.losses == 1
示例#30
0
def test_run_model_perez(system, location):
    mc = ModelChain(system, location, transposition_model='perez')
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    irradiance = pd.DataFrame({
        'dni': 900,
        'ghi': 600,
        'dhi': 150
    },
                              index=times)
    ac = mc.run_model(times, weather=irradiance).ac

    expected = pd.Series(np.array([190.194545796, -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected)
示例#31
0
def test_complete_irradiance_clean_run(system, location):
    """The DataFrame should not change if all columns are passed"""
    mc = ModelChain(system, location)
    times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
    i = pd.DataFrame({'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times)

    mc.complete_irradiance(times, weather=i)

    assert_series_equal(mc.weather['dni'],
                        pd.Series([2, 3], index=times, name='dni'))
    assert_series_equal(mc.weather['dhi'],
                        pd.Series([4, 6], index=times, name='dhi'))
    assert_series_equal(mc.weather['ghi'],
                        pd.Series([9, 5], index=times, name='ghi'))
示例#32
0
def test_complete_irradiance(system, location):
    """Check calculations"""
    mc = ModelChain(system, location)
    times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
    i = pd.DataFrame(
        {
            'dni': [30.354455, 77.22822],
            'dhi': [372.103976116, 497.087579068],
            'ghi': [356.543700, 465.44400]
        },
        index=times)

    mc.complete_irradiance(times, weather=i[['ghi', 'dni']])
    assert_series_equal(
        mc.weather['dhi'],
        pd.Series([372.103976116, 497.087579068], index=times, name='dhi'))

    mc.complete_irradiance(times, weather=i[['dhi', 'dni']])
    assert_series_equal(
        mc.weather['ghi'],
        pd.Series([356.543700, 465.44400], index=times, name='ghi'))

    mc.complete_irradiance(times, weather=i[['dhi', 'ghi']])
    assert_series_equal(
        mc.weather['dni'],
        pd.Series([30.354455, 77.22822], index=times, name='dni'))
示例#33
0
def test_run_model_with_irradiance(system, location):
    mc = ModelChain(system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    irradiance = pd.DataFrame({
        'dni': 900,
        'ghi': 600,
        'dhi': 150
    },
                              index=times)
    ac = mc.run_model(times, weather=irradiance).ac

    expected = pd.Series(np.array([1.90054749e+02, -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected)
示例#34
0
def test_losses_models_ext_def(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    m = mocker.spy(sys.modules[__name__], 'constant_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system,
                    location,
                    dc_model='pvwatts',
                    aoi_model='no_loss',
                    spectral_model='no_loss',
                    losses_model=constant_losses)
    mc.run_model(weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, (pd.Series, pd.DataFrame))
    assert mc.losses == 0.9
    assert not mc.ac.empty
示例#35
0
def test_complete_irradiance_clean_run(system, location):
    """The DataFrame should not change if all columns are passed"""
    mc = ModelChain(system, location)
    times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
    i = pd.DataFrame({'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times)

    mc.complete_irradiance(times, weather=i)

    assert_series_equal(mc.weather['dni'],
                        pd.Series([2, 3], index=times, name='dni'))
    assert_series_equal(mc.weather['dhi'],
                        pd.Series([4, 6], index=times, name='dhi'))
    assert_series_equal(mc.weather['ghi'],
                        pd.Series([9, 5], index=times, name='ghi'))
示例#36
0
def test_losses_models_pvwatts(pvwatts_dc_pvwatts_ac_system, location, weather,
                               mocker):
    age = 1
    pvwatts_dc_pvwatts_ac_system.losses_parameters = dict(age=age)
    m = mocker.spy(pvsystem, 'pvwatts_losses')
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system,
                    location,
                    dc_model='pvwatts',
                    aoi_model='no_loss',
                    spectral_model='no_loss',
                    losses_model='pvwatts')
    mc.run_model(weather)
    assert m.call_count == 1
    m.assert_called_with(age=age)
    assert isinstance(mc.ac, (pd.Series, pd.DataFrame))
    assert not mc.ac.empty
    # check that we're applying correction to dc
    # GH 696
    dc_with_loss = mc.dc
    mc = ModelChain(pvwatts_dc_pvwatts_ac_system,
                    location,
                    dc_model='pvwatts',
                    aoi_model='no_loss',
                    spectral_model='no_loss',
                    losses_model='no_loss')
    mc.run_model(weather)
    assert not np.allclose(mc.dc, dc_with_loss, equal_nan=True)
示例#37
0
def test_run_model_tracker(system, location, weather, mocker):
    system = SingleAxisTracker(
        module_parameters=system.module_parameters,
        temperature_model_parameters=system.temperature_model_parameters,
        inverter_parameters=system.inverter_parameters)
    mocker.spy(system, 'singleaxis')
    mc = ModelChain(system, location)
    mc.run_model(weather)
    assert system.singleaxis.call_count == 1
    assert (mc.tracking.columns == [
        'tracker_theta', 'aoi', 'surface_azimuth', 'surface_tilt'
    ]).all()
    assert mc.ac[0] > 0
    assert np.isnan(mc.ac[1])
示例#38
0
def test_ModelChain___repr__():
    system = PVSystem()
    location = Location(32.2, -111, altitude=700)
    strategy = 'south_at_latitude_tilt'

    mc = ModelChain(system, location, orientation_strategy=strategy)

    # the || accounts for the coercion of 'None' to None
    assert mc.__repr__() == (
        'ModelChain for: PVSystem with tilt:32.2 and ' +
        'azimuth: 180 with Module: None and Inverter: None ' +
        'orientation_startegy: south_at_latitude_tilt clearsky_model: ' +
        'ineichentransposition_model: haydavies solar_position_method: ' +
        'nrel_numpyairmass_model: kastenyoung1989')
示例#39
0
def test_complete_irradiance(system, location):
    """Check calculations"""
    mc = ModelChain(system, location)
    times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
    i = pd.DataFrame(
        {
            'dni': [49.756966, 62.153947],
            'ghi': [372.103976116, 497.087579068],
            'dhi': [356.543700, 465.44400]
        },
        index=times)

    with pytest.warns(UserWarning):
        mc.complete_irradiance(i[['ghi', 'dni']])
    assert_series_equal(
        mc.weather['dhi'],
        pd.Series([356.543700, 465.44400], index=times, name='dhi'))

    with pytest.warns(UserWarning):
        mc.complete_irradiance(i[['dhi', 'dni']])
    assert_series_equal(
        mc.weather['ghi'],
        pd.Series([372.103976116, 497.087579068], index=times, name='ghi'))

    mc.complete_irradiance(i[['dhi', 'ghi']])
    assert_series_equal(
        mc.weather['dni'],
        pd.Series([49.756966, 62.153947], index=times, name='dni'))
示例#40
0
def test_prepare_inputs_from_poa(sapm_dc_snl_ac_system, location,
                                 weather, total_irrad):
    data = pd.concat([weather, total_irrad], axis=1)
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    mc.prepare_inputs_from_poa(data)
    weather_expected = weather.copy()
    weather_expected['temp_air'] = 20
    weather_expected['wind_speed'] = 0
    # order as expected
    weather_expected = weather_expected[
        ['ghi', 'dhi', 'dni', 'wind_speed', 'temp_air']]
    # weather attribute
    assert_frame_equal(mc.weather, weather_expected)
    # total_irrad attribute
    assert_frame_equal(mc.total_irrad, total_irrad)
示例#41
0
def test_run_model_with_weather_sapm_temp(sapm_dc_snl_ac_system, location,
                                          weather, mocker):
    # test with sapm cell temperature model
    weather['wind_speed'] = 5
    weather['temp_air'] = 10
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    mc.temperature_model = 'sapm'
    m_sapm = mocker.spy(sapm_dc_snl_ac_system, 'sapm_celltemp')
    mc.run_model(weather)
    assert m_sapm.call_count == 1
    # assert_called_once_with cannot be used with series, so need to use
    # assert_series_equal on call_args
    assert_series_equal(m_sapm.call_args[0][1], weather['temp_air'])  # temp
    assert_series_equal(m_sapm.call_args[0][2], weather['wind_speed'])  # wind
    assert not mc.ac.empty
示例#42
0
def setup_modelchain(pv_system, location):

    mc = ModelChain(system=pv_system,
                    location=location,
                    aoi_model='no_loss',
                    spectral_model='no_loss')
    return mc
示例#43
0
def test_infer_aoi_model_invalid(location, system_no_aoi):
    exc_text = 'could not infer AOI model'
    with pytest.raises(ValueError, match=exc_text):
        ModelChain(system_no_aoi,
                   location,
                   orientation_strategy='None',
                   spectral_model='no_loss')
示例#44
0
def test_deprecated_clearsky_07():
    # explicit system creation call because fail_on_pvlib_version
    # does not support decorators.
    system = PVSystem(module_parameters={'pdc0': 1, 'gamma_pdc': -0.003})
    location = Location(32.2, -110.9)
    mc = ModelChain(system,
                    location,
                    dc_model='pvwatts',
                    ac_model='pvwatts',
                    aoi_model='no_loss',
                    spectral_model='no_loss')
    times = pd.date_range(start='20160101 1200-0700',
                          end='20160101 1800-0700',
                          freq='6H')
    with pytest.warns(pvlibDeprecationWarning):
        mc.prepare_inputs(times=times)
def test_run_model_with_weather_faiman_temp(sapm_dc_snl_ac_system, location,
                                            weather, mocker):
    # test with faiman cell temperature model
    weather['wind_speed'] = 5
    weather['temp_air'] = 10
    sapm_dc_snl_ac_system.temperature_model_parameters = {
        'u0': 25.0, 'u1': 6.84
    }
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    mc.temperature_model = 'faiman'
    m_faiman = mocker.spy(sapm_dc_snl_ac_system, 'faiman_celltemp')
    mc.run_model(weather)
    assert m_faiman.call_count == 1
    assert_series_equal(m_faiman.call_args[0][1], weather['temp_air'])
    assert_series_equal(m_faiman.call_args[0][2], weather['wind_speed'])
    assert not mc.ac.empty
def test_infer_aoi_model(location, system_no_aoi, aoi_model):
    for k in iam._IAM_MODEL_PARAMS[aoi_model]:
        system_no_aoi.module_parameters.update({k: 1.0})
    mc = ModelChain(system_no_aoi, location,
                    orientation_strategy='None',
                    spectral_model='no_loss')
    assert isinstance(mc, ModelChain)
示例#47
0
def test_ac_models(system, cec_dc_adr_ac_system, pvwatts_dc_pvwatts_ac_system,
                   location, ac_model, expected):

    ac_systems = {'snlinverter': system, 'adrinverter': cec_dc_adr_ac_system,
                  'pvwatts': pvwatts_dc_pvwatts_ac_system,
                  acdc: pvwatts_dc_pvwatts_ac_system}

    system = ac_systems[ac_model]

    mc = ModelChain(system, location, ac_model=ac_model,
                    aoi_model='no_loss', spectral_model='no_loss')
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array(expected), index=times)
    assert_series_equal(ac, expected, check_less_precise=2)
示例#48
0
def test_ac_models(system, cec_dc_adr_ac_system, pvwatts_dc_pvwatts_ac_system,
                   location, ac_model, expected):

    ac_systems = {'snlinverter': system, 'adrinverter': cec_dc_adr_ac_system,
                  'pvwatts': pvwatts_dc_pvwatts_ac_system,
                  acdc: pvwatts_dc_pvwatts_ac_system}

    system = ac_systems[ac_model]

    mc = ModelChain(system, location, ac_model=ac_model,
                    aoi_model='no_loss', spectral_model='no_loss')
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array(expected), index=times)
    assert_series_equal(ac, expected, check_less_precise=2)
示例#49
0
def test_run_model_tracker(system, location):
    system = SingleAxisTracker(module_parameters=system.module_parameters,
                               inverter_parameters=system.inverter_parameters)
    mc = ModelChain(system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array([119.067713606, nan]), index=times)
    assert_series_equal(ac, expected, check_less_precise=2)

    expected = pd.DataFrame(
        np.array([[54.82513187, 90., 11.0039221, 11.0039221],
                  [nan, 0., 0., nan]]),
        columns=['aoi', 'surface_azimuth', 'surface_tilt', 'tracker_theta'],
        index=times)
    assert_frame_equal(mc.tracking, expected, check_less_precise=2)
示例#50
0
def test_ac_models(system, cec_dc_adr_ac_system, pvwatts_dc_pvwatts_ac_system,
                   location, ac_model, weather, mocker):
    ac_systems = {'snlinverter': system, 'adrinverter': cec_dc_adr_ac_system,
                  'pvwatts': pvwatts_dc_pvwatts_ac_system}
    system = ac_systems[ac_model]

    mc = ModelChain(system, location, ac_model=ac_model,
                    aoi_model='no_loss', spectral_model='no_loss')
    if ac_model == 'pvwatts':
        ac_model += '_ac'
    m = mocker.spy(system, ac_model)
    mc.run_model(weather.index, weather=weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, pd.Series)
    assert not mc.ac.empty
    assert mc.ac[1] < 1
示例#51
0
def test_invalid_models(model, system, location):
    kwargs = {'dc_model': 'pvwatts', 'ac_model': 'pvwatts',
              'aoi_model': 'no_loss', 'spectral_model': 'no_loss',
              'temperature_model': 'sapm', 'losses_model': 'no_loss'}
    kwargs[model] = 'invalid'
    with pytest.raises(ValueError):
        ModelChain(system, location, **kwargs)
示例#52
0
def test_run_model_with_weather_pvsyst_temp(sapm_dc_snl_ac_system, location,
                                            weather, mocker):
    # test with pvsyst cell temperature model
    weather['wind_speed'] = 5
    weather['temp_air'] = 10
    sapm_dc_snl_ac_system.racking_model = 'freestanding'
    sapm_dc_snl_ac_system.temperature_model_parameters = \
        temperature._temperature_model_params('pvsyst', 'freestanding')
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    mc.temperature_model = 'pvsyst'
    m_pvsyst = mocker.spy(sapm_dc_snl_ac_system, 'pvsyst_celltemp')
    mc.run_model(weather)
    assert m_pvsyst.call_count == 1
    assert_series_equal(m_pvsyst.call_args[0][1], weather['temp_air'])
    assert_series_equal(m_pvsyst.call_args[0][2], weather['wind_speed'])
    assert not mc.ac.empty
示例#53
0
def test_ac_models(system, cec_dc_adr_ac_system, pvwatts_dc_pvwatts_ac_system,
                   location, ac_model, weather, mocker):
    ac_systems = {'snlinverter': system, 'adrinverter': cec_dc_adr_ac_system,
                  'pvwatts': pvwatts_dc_pvwatts_ac_system}
    system = ac_systems[ac_model]

    mc = ModelChain(system, location, ac_model=ac_model,
                    aoi_model='no_loss', spectral_model='no_loss')
    if ac_model == 'pvwatts':
        ac_model += '_ac'
    m = mocker.spy(system, ac_model)
    mc.run_model(weather)
    assert m.call_count == 1
    assert isinstance(mc.ac, pd.Series)
    assert not mc.ac.empty
    assert mc.ac[1] < 1
示例#54
0
def test_run_model_tracker(system, location):
    system = SingleAxisTracker(module_parameters=system.module_parameters,
                               inverter_parameters=system.inverter_parameters)
    mc = ModelChain(system, location)
    times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
    ac = mc.run_model(times).ac

    expected = pd.Series(np.array([  121.421719,  -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected, check_less_precise=2)

    expected = pd.DataFrame(np.
        array([[ 54.82513187,  90.        ,  11.0039221 ,  11.0039221 ],
               [         nan,   0.        ,   0.        ,          nan]]),
        columns=['aoi', 'surface_azimuth', 'surface_tilt', 'tracker_theta'],
        index=times)
    assert_frame_equal(mc.tracking, expected, check_less_precise=2)
示例#55
0
def test_ModelChain___repr__(system, location, strategy, strategy_str):

    mc = ModelChain(system, location, orientation_strategy=strategy,
                    name='my mc')

    expected = '\n'.join([
        'ModelChain: ',
        '  name: my mc',
        '  orientation_strategy: ' + strategy_str,
        '  clearsky_model: ineichen',
        '  transposition_model: haydavies',
        '  solar_position_method: nrel_numpy',
        '  airmass_model: kastenyoung1989',
        '  dc_model: sapm',
        '  ac_model: snlinverter',
        '  aoi_model: sapm_aoi_loss',
        '  spectral_model: sapm_spectral_loss',
        '  temp_model: sapm_temp',
        '  losses_model: no_extra_losses'
    ])

    assert mc.__repr__() == expected
示例#56
0
def test_complete_irradiance(system, location):
    """Check calculations"""
    mc = ModelChain(system, location)
    times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
    i = pd.DataFrame({'dni': [30.354455, 77.22822],
                      'dhi': [372.103976116, 497.087579068],
                      'ghi': [356.543700, 465.44400]}, index=times)

    mc.complete_irradiance(times, weather=i[['ghi', 'dni']])
    assert_series_equal(mc.weather['dhi'],
                        pd.Series([372.103976116, 497.087579068],
                                  index=times, name='dhi'))

    mc.complete_irradiance(times, weather=i[['dhi', 'dni']])
    assert_series_equal(mc.weather['ghi'],
                        pd.Series([356.543700, 465.44400],
                                  index=times, name='ghi'))

    mc.complete_irradiance(times, weather=i[['dhi', 'ghi']])
    assert_series_equal(mc.weather['dni'],
                        pd.Series([30.354455, 77.22822],
                                  index=times, name='dni'))
示例#57
0
    }

# own location parameter
wittenberg = {
    'altitude': 34,
    'name': 'Wittenberg',
    'latitude': my_weather.latitude,
    'longitude': my_weather.longitude,
    }

# the following has been implemented in the pvlib ModelChain in the
# complete_irradiance method (pvlib version > v0.4.5)
if w.get('dni') is None:
    w['dni'] = (w.ghi - w.dhi) / cosd(
        Location(**wittenberg).get_solarposition(times).zenith)

# pvlib's ModelChain
mc = ModelChain(PVSystem(**yingli210),
                Location(**wittenberg),
                orientation_strategy='south_at_latitude_tilt')

mc.run_model(times, weather=w)

if plt:
    mc.dc.p_mp.fillna(0).plot()
    plt.show()
else:
    logging.warning("No plots shown. Install matplotlib to see the plots.")

logging.info('Done!')