Skip to content

Commit 1e55ffe

Browse files
committed
statsmodels decorator
1 parent 3e07d9b commit 1e55ffe

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

pvlib/inverter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import pandas as pd
1515
from numpy.polynomial.polynomial import polyfit # different than np.polyfit
1616
from scipy.optimize import minimize
17-
import statsmodels.api as sm
1817
from pvlib._deprecation import deprecated
1918

2019

@@ -584,6 +583,11 @@ def _fit_sandia_field_a(pac, pdc, vdc, pac0, vdc0):
584583
dict
585584
Parameters Pdco, Pso and C0 for the Sandia inverter model.
586585
'''
586+
try:
587+
import statsmodels.api as sm
588+
except ImportError:
589+
raise ImportError(
590+
'Parameter fitting requires statsmodels')
587591
# select data. Avoid very low power, clipping and DC voltage far from
588592
# nominal
589593
u = (pac > 0.05*pac0) & (pac < pac0) & (np.abs(vdc - vdc0)/vdc0 < 0.05)

tests/test_inverter.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import numpy as np
22
import pandas as pd
3-
4-
from .conftest import assert_series_equal
53
from numpy.testing import assert_allclose
64

5+
from .conftest import assert_series_equal
76
from .conftest import TESTS_DATA_DIR
7+
from .conftest import requires_statsmodels
8+
89
import pytest
910

1011
from pvlib import inverter
@@ -202,17 +203,18 @@ def test_pvwatts_multi():
202203
'Pso': 10., 'C0': 1e-6, 'C1': 1e-4, 'C2': 1e-2,
203204
'C3': 1e-3, 'Pnt': 1.}),
204205
])
205-
def test_fit_sandia(infilen, expected):
206+
def test_fit_sandia_lab(infilen, expected):
206207
curves = pd.read_csv(infilen)
207208
dc_power = curves['ac_power'] / curves['efficiency']
208-
result = inverter.fit_sandia(ac_power=curves['ac_power'],
209-
dc_power=dc_power,
210-
dc_voltage=curves['dc_voltage'],
211-
dc_voltage_level=curves['dc_voltage_level'],
212-
p_ac_0=expected['Paco'], p_nt=expected['Pnt'])
209+
result = inverter.fit_sandia_lab(
210+
ac_power=curves['ac_power'], dc_power=dc_power,
211+
dc_voltage=curves['dc_voltage'],
212+
dc_voltage_level=curves['dc_voltage_level'],
213+
p_ac_0=expected['Paco'], p_nt=expected['Pnt'])
213214
assert expected == pytest.approx(result, rel=1e-3)
214215

215216

217+
@requires_statsmodels
216218
def test_fit_sandia_field():
217219
pdc = np.arange(start=100., stop=1300., step=100.)
218220
vdc = np.array([550., 600., 650, 550., 600., 650, 550., 600., 650,

0 commit comments

Comments
 (0)