Ejemplo n.º 1
0
def test_detect_clearsky_defaults(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(expected['GHI'], cs['ghi'])
    assert_series_equal(expected['Clear or not'],
                        clear_samples,
                        check_dtype=False,
                        check_names=False)
Ejemplo n.º 2
0
def test_adr_vtol(adr_inverter_parameters):
    vdcs = pd.Series([135, 154, 390, 420, 551])
    pdcs = pd.Series([135, 1232, 1170, 420, 551])

    pacs = inverter.adr(vdcs, pdcs, adr_inverter_parameters, vtol=0.20)
    assert_series_equal(pacs, pd.Series([104.8223, 1161.5745, 1116.4459,
                                         382.6679, 513.3385]))
Ejemplo n.º 3
0
def test_adr(adr_inverter_parameters):
    vdcs = pd.Series([135, 154, 390, 420, 551])
    pdcs = pd.Series([135, 1232, 1170, 420, 551])

    pacs = inverter.adr(vdcs, pdcs, adr_inverter_parameters)
    assert_series_equal(pacs, pd.Series([np.nan, 1161.5745, 1116.4459,
                                         382.6679, np.nan]))
Ejemplo n.º 4
0
def test_sandia_Pnt_micro():
    """
    Test for issue #140, where some microinverters were giving a positive AC
    power output when the DC power was 0.
    """
    inverter_parameters = {
        'Name': 'Enphase Energy: M250-60-2LL-S2x (-ZC) (-NA) 208V [CEC 2013]',
        'Vac': 208.0,
        'Paco': 240.0,
        'Pdco': 250.5311318,
        'Vdco': 32.06160667,
        'Pso': 1.12048857,
        'C0': -5.76E-05,
        'C1': -6.24E-04,
        'C2': 8.09E-02,
        'C3': -0.111781106,
        'Pnt': 0.043,
        'Vdcmax': 48.0,
        'Idcmax': 9.8,
        'Mppt_low': 27.0,
        'Mppt_high': 39.0,
    }
    vdcs = pd.Series(np.linspace(0, 50, 3))
    idcs = pd.Series(np.linspace(0, 11, 3))
    pdcs = idcs * vdcs

    pacs = inverter.sandia(vdcs, pdcs, inverter_parameters)
    assert_series_equal(pacs, pd.Series([-0.043, 132.545914746, 240.0]))
Ejemplo n.º 5
0
def test_sandia(cec_inverter_parameters):
    vdcs = pd.Series(np.linspace(0, 50, 3))
    idcs = pd.Series(np.linspace(0, 11, 3))
    pdcs = idcs * vdcs

    pacs = inverter.sandia(vdcs, pdcs, cec_inverter_parameters)
    assert_series_equal(pacs, pd.Series([-0.020000, 132.004308, 250.000000]))
Ejemplo n.º 6
0
def test_basic_chain_altitude_pressure(sam_data, cec_inverter_parameters,
                                       sapm_temperature_cs5p_220m):
    times = pd.date_range(start='20160101 1200-0700',
                          end='20160101 1800-0700', freq='6H')
    latitude = 32.2
    longitude = -111
    altitude = 700
    surface_tilt = 0
    surface_azimuth = 0
    modules = sam_data['sandiamod']
    module_parameters = modules['Canadian_Solar_CS5P_220M___2009_']
    temp_model_params = sapm_temperature_cs5p_220m.copy()
    dc, ac = modelchain.basic_chain(times, latitude, longitude,
                                    module_parameters, temp_model_params,
                                    cec_inverter_parameters,
                                    surface_tilt=surface_tilt,
                                    surface_azimuth=surface_azimuth,
                                    pressure=93194)

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

    dc, ac = modelchain.basic_chain(times, latitude, longitude,
                                    module_parameters, temp_model_params,
                                    cec_inverter_parameters,
                                    surface_tilt=surface_tilt,
                                    surface_azimuth=surface_azimuth,
                                    altitude=altitude)

    expected = pd.Series(np.array([113.189814, -2.00000000e-02]),
                         index=times)
    assert_series_equal(ac, expected)
Ejemplo n.º 7
0
def test_fuentes(filename, inoct):
    # Test against data exported from pvwatts.nrel.gov
    data = _read_pvwatts_8760(DATA_DIR / filename)
    data = data.iloc[:24 * 7, :]  # just use one week
    inputs = {
        'poa_global': data['Plane of Array Irradiance (W/m^2)'],
        'temp_air': data['Ambient Temperature (C)'],
        'wind_speed': data['Wind Speed (m/s)'],
        'noct_installed': inoct,
    }
    expected_tcell = data['Cell Temperature (C)']
    expected_tcell.name = 'tmod'
    actual_tcell = temperature.fuentes(**inputs)
    # the SSC implementation of PVWatts diverges from the Fuentes model at
    # at night by setting Tcell=Tamb when POA=0. This not only means that
    # nighttime values are slightly different (Fuentes models cooling to sky
    # at night), but because of the thermal inertia, there is a transient
    # error after dawn as well. Test each case separately:
    is_night = inputs['poa_global'] == 0
    is_dawn = is_night.shift(1) & ~is_night
    is_daytime = (inputs['poa_global'] > 0) & ~is_dawn
    # the accuracy is probably higher than 3 digits here, but the PVWatts
    # export data has low precision so can only test up to 3 digits
    assert_series_equal(expected_tcell[is_daytime].round(3),
                        actual_tcell[is_daytime].round(3))
    # use lower precision for dawn times to accommodate the dawn transient
    error = actual_tcell[is_dawn] - expected_tcell[is_dawn]
    assert (error.abs() < 0.1).all()
    # sanity check on night values -- Fuentes not much lower than PVWatts
    night_difference = expected_tcell[is_night] - actual_tcell[is_night]
    assert night_difference.max() < 6
    assert night_difference.min() > 0
Ejemplo n.º 8
0
def test_run_model_from_poa(sapm_dc_snl_ac_system, location, total_irrad):
    mc = ModelChain(sapm_dc_snl_ac_system, location, aoi_model='no_loss',
                    spectral_model='no_loss')
    ac = mc.run_model_from_poa(total_irrad).ac
    expected = pd.Series(np.array([149.280238, 96.678385]),
                         index=total_irrad.index)
    assert_series_equal(ac, expected)
Ejemplo n.º 9
0
def test__assign_total_irrad(sapm_dc_snl_ac_system, location, weather,
                             total_irrad):
    weather[['poa_global', 'poa_diffuse', 'poa_direct']] = total_irrad
    mc = ModelChain(sapm_dc_snl_ac_system, location)
    mc._assign_total_irrad(weather)
    for k in modelchain.POA_DATA_KEYS:
        assert_series_equal(mc.total_irrad[k], total_irrad[k])
Ejemplo n.º 10
0
def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass):
    dni = irrad_data['dni'].copy()
    dni.iloc[2] = np.nan
    out = irradiance.perez(40,
                           180,
                           irrad_data['dhi'],
                           dni,
                           dni_et,
                           ephem_data['apparent_zenith'],
                           ephem_data['azimuth'],
                           relative_airmass,
                           return_components=True)
    expected = pd.DataFrame(
        np.array([[0., 31.46046871, np.nan, 45.45539877],
                  [0., 26.84138589, np.nan, 31.72696071],
                  [0., 0., np.nan, 4.47966439],
                  [0., 4.62212181, np.nan, 9.25316454]]).T,
        columns=['sky_diffuse', 'isotropic', 'circumsolar', 'horizon'],
        index=irrad_data.index)
    expected_for_sum = expected['sky_diffuse'].copy()
    expected_for_sum.iloc[2] = 0
    sum_components = out.iloc[:, 1:].sum(axis=1)
    sum_components.name = 'sky_diffuse'

    assert_frame_equal(out, expected, check_less_precise=2)
    assert_series_equal(sum_components, expected_for_sum, check_less_precise=2)
Ejemplo n.º 11
0
def test_clearness_index_zenith_independent(airmass_kt):
    clearness_index = np.array([-1, 0, .1, 1])
    clearness_index, airmass_kt = np.meshgrid(clearness_index, airmass_kt)
    out = irradiance.clearness_index_zenith_independent(
        clearness_index, airmass_kt)
    expected = np.array([[0., 0., 0.1, 1.], [0., 0., 0.138, 1.383],
                         [0., 0., 0.182, 1.822], [0., 0., 0.212, 2.]])
    assert_allclose(out, expected, atol=0.001)
    # test max_clearness_index
    out = irradiance.clearness_index_zenith_independent(
        clearness_index, airmass_kt, max_clearness_index=0.82)
    expected = np.array([[0., 0., 0.1, 0.82], [0., 0., 0.138, 0.82],
                         [0., 0., 0.182, 0.82], [0., 0., 0.212, 0.82]])
    assert_allclose(out, expected, atol=0.001)
    # scalars
    out = irradiance.clearness_index_zenith_independent(.4, 2)
    expected = 0.443
    assert_allclose(out, expected, atol=0.001)
    # series
    times = pd.date_range(start='20180601', periods=2, freq='12H')
    clearness_index = pd.Series([0, .5], index=times)
    airmass = pd.Series([np.nan, 2], index=times)
    out = irradiance.clearness_index_zenith_independent(
        clearness_index, airmass)
    expected = pd.Series([np.nan, 0.553744437562], index=times)
    assert_series_equal(out, expected)
Ejemplo n.º 12
0
def test__max_diff_windowed(detect_clearsky_helper_data):
    x, samples_per_window, sample_interval, H = detect_clearsky_helper_data
    expected = {}
    expected['max_diff'] = pd.Series(
        data=[np.nan, 3., 5., 7., 9., 11., np.nan], index=x.index)
    result = clearsky._max_diff_windowed(x, H, samples_per_window)
    assert_series_equal(result, expected['max_diff'])
Ejemplo n.º 13
0
def test_dirint_min_cos_zenith_max_zenith():
    # map out behavior under difficult conditions with various
    # limiting kwargs settings
    # times don't have any physical relevance
    times = pd.DatetimeIndex(['2014-06-24T12-0700', '2014-06-24T18-0700'])
    ghi = pd.Series([0, 1], index=times)
    solar_zenith = pd.Series([90, 89.99], index=times)

    out = irradiance.dirint(ghi, solar_zenith, times)
    expected = pd.Series([0.0, 0.0], index=times, name='dni')
    assert_series_equal(out, expected)

    out = irradiance.dirint(ghi, solar_zenith, times, min_cos_zenith=0)
    expected = pd.Series([0.0, 0.0], index=times, name='dni')
    assert_series_equal(out, expected)

    out = irradiance.dirint(ghi, solar_zenith, times, max_zenith=90)
    expected = pd.Series([0.0, 0.0], index=times, name='dni')
    assert_series_equal(out, expected, check_less_precise=True)

    out = irradiance.dirint(ghi,
                            solar_zenith,
                            times,
                            min_cos_zenith=0,
                            max_zenith=90)
    expected = pd.Series([0.0, 144.264507], index=times, name='dni')
    assert_series_equal(out, expected, check_less_precise=True)

    out = irradiance.dirint(ghi,
                            solar_zenith,
                            times,
                            min_cos_zenith=0,
                            max_zenith=100)
    expected = pd.Series([0.0, 144.264507], index=times, name='dni')
    assert_series_equal(out, expected, check_less_precise=True)
Ejemplo n.º 14
0
def test_sapm_effective_irradiance(sapm_module_params, test_input, expected):
    test_input.append(sapm_module_params)
    out = pvsystem.sapm_effective_irradiance(*test_input)
    if isinstance(test_input, pd.Series):
        assert_series_equal(out, expected, check_less_precise=4)
    else:
        assert_allclose(out, expected, atol=1e-1)
Ejemplo n.º 15
0
def test_martin_ruiz():

    aoi = 45.
    a_r = 0.16
    expected = 0.98986965

    # will fail if default values change
    iam = _iam.martin_ruiz(aoi)
    assert_allclose(iam, expected)

    # will fail if parameter names change
    iam = _iam.martin_ruiz(aoi=aoi, a_r=a_r)
    assert_allclose(iam, expected)

    a_r = 0.18
    aoi = [-100, -60, 0, 60, 100, np.nan, np.inf]
    expected = [0.0, 0.9414631, 1.0, 0.9414631, 0.0, np.nan, 0.0]

    # check out of range of inputs as list
    iam = _iam.martin_ruiz(aoi, a_r)
    assert_allclose(iam, expected, equal_nan=True)

    # check out of range of inputs as array
    iam = _iam.martin_ruiz(np.array(aoi), a_r)
    assert_allclose(iam, expected, equal_nan=True)

    # check out of range of inputs as Series
    aoi = pd.Series(aoi)
    expected = pd.Series(expected)
    iam = _iam.martin_ruiz(aoi, a_r)
    assert_series_equal(iam, expected)
Ejemplo n.º 16
0
def test_fully_covered_nrel():
    dt = pd.date_range(start="2019-1-1 12:00:00", end="2019-1-1 18:00:00",
                       freq='1h')
    snowfall_data = pd.Series([1, 5, .6, 4, .23, -5, 19], index=dt)
    expected = pd.Series([False, True, False, True, False, False, True],
                         index=dt)
    fully_covered = snow.fully_covered_nrel(snowfall_data)
    assert_series_equal(expected, fully_covered)
Ejemplo n.º 17
0
def test_sapm_spectral_loss(sapm_module_params, airmass, expected):

    out = pvsystem.sapm_spectral_loss(airmass, sapm_module_params)

    if isinstance(airmass, pd.Series):
        assert_series_equal(out, expected, check_less_precise=4)
    else:
        assert_allclose(out, expected, atol=1e-4)
Ejemplo n.º 18
0
def test_sapm(sapm_module_params, aoi, expected):

    out = _iam.sapm(aoi, sapm_module_params)

    if isinstance(aoi, pd.Series):
        assert_series_equal(out, expected, check_less_precise=4)
    else:
        assert_allclose(out, expected, atol=1e-4)
Ejemplo n.º 19
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)
    assert m.call_count == 1
    assert_series_equal(mc.ac, mc.dc)
    assert not mc.ac.empty
Ejemplo n.º 20
0
def test_perez(irrad_data, ephem_data, dni_et, relative_airmass):
    dni = irrad_data['dni'].copy()
    dni.iloc[2] = np.nan
    out = irradiance.perez(40, 180, irrad_data['dhi'], dni, dni_et,
                           ephem_data['apparent_zenith'],
                           ephem_data['azimuth'], relative_airmass)
    expected = pd.Series(np.array([0., 31.46046871, np.nan, 45.45539877]),
                         index=irrad_data.index)
    assert_series_equal(out, expected, check_less_precise=2)
Ejemplo n.º 21
0
def test_pvsyst_cell_series():
    times = pd.date_range(start="2015-01-01", end="2015-01-02", freq="12H")
    temps = pd.Series([0, 10, 5], index=times)
    irrads = pd.Series([0, 500, 0], index=times)
    winds = pd.Series([10, 5, 0], index=times)

    result = temperature.pvsyst_cell(irrads, temps, wind_speed=winds)
    expected = pd.Series([0.0, 23.96551, 5.0], index=times)
    assert_series_equal(expected, result)
Ejemplo n.º 22
0
def test_detect_clearsky(detect_clearsky_data):
    expected, cs = detect_clearsky_data
    clear_samples = clearsky.detect_clearsky(expected['GHI'],
                                             cs['ghi'],
                                             times=cs.index,
                                             window_length=10)
    assert_series_equal(expected['Clear or not'],
                        clear_samples,
                        check_dtype=False,
                        check_names=False)
Ejemplo n.º 23
0
def test__line_length_windowed(detect_clearsky_helper_data):
    x, samples_per_window, sample_interval, H = detect_clearsky_helper_data
    # sqt is hand-calculated assuming window=3
    # line length between adjacent points
    sqt = pd.Series(np.sqrt(np.array([np.nan, 2., 10., 26., 50., 82, 122.])))
    expected = {}
    expected['line_length'] = sqt + sqt.shift(-1)
    result = clearsky._line_length_windowed(x, H, samples_per_window,
                                            sample_interval)
    assert_series_equal(result, expected['line_length'])
Ejemplo n.º 24
0
def test_fully_covered_nrel_irregular():
    # test when frequency is not specified and can't be inferred
    dt = pd.DatetimeIndex(["2019-1-1 11:00:00", "2019-1-1 14:30:00",
                           "2019-1-1 15:07:00", "2019-1-1 14:00:00"])
    snowfall_data = pd.Series([1, .5, .6, .4], index=dt)
    snow_coverage = snow.fully_covered_nrel(snowfall_data,
                                            threshold_snowfall=0.5)
    covered = np.array([False, False, True, False])
    expected = pd.Series(covered, index=dt)
    assert_series_equal(expected, snow_coverage)
Ejemplo n.º 25
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)
Ejemplo n.º 26
0
def test_lookup_linke_turbidity_months_leapyear():
    times = pd.date_range(start='2016-04-01',
                          end='2016-07-01',
                          freq='1M',
                          tz='America/Phoenix')
    expected = pd.Series(np.array(
        [2.89918032787, 2.97540983607, 3.19672131148]),
                         index=times)
    out = clearsky.lookup_linke_turbidity(times, 32.125, -110.875)
    assert_series_equal(expected, out)
Ejemplo n.º 27
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)
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
def test_ashrae():
    thetas = np.array(
        [-90., -67.5, -45., -22.5, 0., 22.5, 45., 67.5, 89., 90., np.nan])
    expected = np.array([
        0, 0.9193437, 0.97928932, 0.99588039, 1., 0.99588039, 0.97928932,
        0.9193437, 0, 0, np.nan
    ])
    iam = _iam.ashrae(thetas, .05)
    assert_allclose(iam, expected, equal_nan=True)
    iam_series = _iam.ashrae(pd.Series(thetas))
    assert_series_equal(iam_series, pd.Series(expected))
Ejemplo n.º 30
0
def test_airmass(model, expected, zeniths):
    out = atmosphere.get_relative_airmass(zeniths, model)
    expected = np.array(expected)
    assert_allclose(out, expected, equal_nan=True, atol=0.001)
    # test series in/out. index does not matter
    # hits the isinstance() block in get_relative_airmass
    times = pd.date_range(start='20180101', periods=len(zeniths), freq='1s')
    zeniths = pd.Series(zeniths, index=times)
    expected = pd.Series(expected, index=times)
    out = atmosphere.get_relative_airmass(zeniths, model)
    assert_series_equal(out, expected, check_less_precise=True)