Exemplo n.º 1
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])
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
def test_invalid_models(model, system, location):
    kwargs = {
        'dc_model': 'pvwatts',
        'ac_model': 'pvwatts',
        'aoi_model': 'no_loss',
        'spectral_model': 'no_loss',
        'temp_model': 'sapm',
        'losses_model': 'no_loss'
    }
    kwargs[model] = 'invalid'
    with pytest.raises(ValueError):
        ModelChain(system, location, **kwargs)
Exemplo n.º 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
Exemplo n.º 6
0
def test_infer_dc_model(sapm_dc_snl_ac_system, cec_dc_snl_ac_system,
                        pvsyst_dc_snl_ac_system, pvwatts_dc_pvwatts_ac_system,
                        location, dc_model, weather, mocker):
    dc_systems = {
        'sapm': sapm_dc_snl_ac_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'
    }
    temp_model_function = {
        'sapm': 'sapm',
        'cec': 'sapm',
        'desoto': 'sapm',
        'pvsyst': 'pvsyst',
        'singlediode': 'sapm',
        'pvwatts_dc': 'sapm'
    }
    temp_model_params = {
        'sapm': {
            'a': -3.40641,
            'b': -0.0842075,
            'deltaT': 3
        },
        'pvsyst': {
            'u_c': 29.0,
            'u_v': 0
        }
    }
    system = dc_systems[dc_model]
    system.temperature_model_parameters = temp_model_params[
        temp_model_function[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',
                    temperature_model=temp_model_function[dc_model])
    mc.run_model(weather)
    assert m.call_count == 1
    assert isinstance(mc.dc, (pd.Series, pd.DataFrame))
Exemplo n.º 7
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
Exemplo n.º 8
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
Exemplo n.º 9
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))
Exemplo n.º 10
0
def test_infer_temp_model(location, sapm_dc_snl_ac_system,
                          pvwatts_dc_pvwatts_ac_pvsyst_temp_system,
                          pvwatts_dc_pvwatts_ac_faiman_temp_system,
                          temp_model):
    dc_systems = {'sapm_temp': sapm_dc_snl_ac_system,
                  'pvsyst_temp': pvwatts_dc_pvwatts_ac_pvsyst_temp_system,
                  'faiman_temp': pvwatts_dc_pvwatts_ac_faiman_temp_system}
    system = dc_systems[temp_model]
    mc = ModelChain(system, location,
                    orientation_strategy='None', aoi_model='physical',
                    spectral_model='no_loss')
    assert temp_model == mc.temperature_model.__name__
    assert isinstance(mc, ModelChain)
Exemplo n.º 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))
Exemplo n.º 12
0
def test_aoi_models(system, location, aoi_model, weather, mocker):
    mc = ModelChain(system,
                    location,
                    dc_model='sapm',
                    aoi_model=aoi_model,
                    spectral_model='no_loss')
    m = mocker.spy(system, 'get_iam')
    mc.run_model(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
Exemplo n.º 13
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)
    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
Exemplo n.º 14
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)
Exemplo n.º 15
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)
    assert m.call_count == 0
    assert mc.losses == 1
Exemplo n.º 16
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(irradiance).ac

    expected = pd.Series(np.array([187.80746494643176, -0.02]), index=times)
    assert_series_equal(ac, expected)
Exemplo n.º 17
0
def test_infer_spectral_model(location, system, cec_dc_snl_ac_system,
                              cec_dc_native_snl_ac_system, dc_model):
    dc_systems = {
        'sapm': system,
        'cec': cec_dc_snl_ac_system,
        'cec_native': cec_dc_native_snl_ac_system
    }
    system = dc_systems[dc_model]
    mc = ModelChain(system,
                    location,
                    orientation_strategy='None',
                    aoi_model='physical')
    assert isinstance(mc, ModelChain)
Exemplo n.º 18
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)
Exemplo n.º 19
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')
Exemplo n.º 20
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)
Exemplo n.º 21
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
Exemplo n.º 22
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'))
Exemplo n.º 23
0
def test_invalid_dc_model_params(system, cec_dc_snl_ac_system,
                                 pvwatts_dc_pvwatts_ac_system, location):
    kwargs = {
        'dc_model': 'sapm',
        'ac_model': 'snlinverter',
        'aoi_model': 'no_loss',
        'spectral_model': 'no_loss',
        'temperature_model': 'sapm',
        'losses_model': 'no_loss'
    }
    system.module_parameters.pop('A0')  # remove a parameter
    with pytest.raises(ValueError):
        ModelChain(system, location, **kwargs)

    kwargs['dc_model'] = 'singlediode'
    cec_dc_snl_ac_system.module_parameters.pop('a_ref')  # remove a parameter
    with pytest.raises(ValueError):
        ModelChain(cec_dc_snl_ac_system, location, **kwargs)

    kwargs['dc_model'] = 'pvwatts'
    kwargs['ac_model'] = 'pvwatts'
    pvwatts_dc_pvwatts_ac_system.module_parameters.pop('pdc0')
    with pytest.raises(ValueError):
        ModelChain(pvwatts_dc_pvwatts_ac_system, location, **kwargs)
Exemplo n.º 24
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
Exemplo n.º 25
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)
Exemplo n.º 26
0
def test_ac_models_deprecated(sapm_dc_snl_ac_system, cec_dc_adr_ac_system,
                              location, ac_model, weather):
    ac_systems = {
        'snlinverter': sapm_dc_snl_ac_system,
        'adrinverter': cec_dc_adr_ac_system
    }
    system = ac_systems[ac_model]
    warn_txt = "ac_model = '" + ac_model + "' is deprecated and will be" +\
               " removed in v0.9"
    with pytest.warns(pvlibDeprecationWarning, match=warn_txt):
        ModelChain(system,
                   location,
                   ac_model=ac_model,
                   aoi_model='no_loss',
                   spectral_model='no_loss')
Exemplo n.º 27
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)
Exemplo n.º 28
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)
Exemplo n.º 29
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
Exemplo n.º 30
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