forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_transformer.py
More file actions
96 lines (76 loc) · 2.32 KB
/
test_transformer.py
File metadata and controls
96 lines (76 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pandas as pd
import numpy as np
import pytest
from numpy.testing import assert_allclose
from pvlib.transformer import simple_efficiency
from pvlib import transformer
def test_simple_efficiency():
# define test inputs
input_power = pd.Series([
-800.0,
436016.609823837,
1511820.16603752,
1580687.44677249,
1616441.79660171
])
no_load_loss = 0.002
load_loss = 0.007
transformer_rating = 2750000
# define expected test results
expected_output_power = pd.Series([
-6300.10103234071,
430045.854892526,
1500588.39919874,
1568921.77089526,
1604389.62839879
])
# run test function with test inputs
calculated_output_power = transformer.simple_efficiency(
input_power=input_power,
no_load_loss=no_load_loss,
load_loss=load_loss,
transformer_rating=transformer_rating
)
# determine if expected results are obtained
assert_allclose(calculated_output_power, expected_output_power)
def test_simple_efficiency_known_values():
no_load_loss = 0.005
load_loss = 0.01
rating = 1000
args = (no_load_loss, load_loss, rating)
# verify correct behavior at no-load condition
assert_allclose(
transformer.simple_efficiency(no_load_loss * rating, *args),
0.0
)
# verify correct behavior at rated condition
assert_allclose(
transformer.simple_efficiency(
rating * (1 + no_load_loss + load_loss),
*args
),
rating,
)
# =========================
# NEW TESTS (Issue #2649)
# =========================
def test_simple_efficiency_numpy_input_power():
input_power = np.array([500, 1000, 1500])
no_load_loss = 0.01
load_loss = 0.02
transformer_rating = 2000
output = simple_efficiency(
input_power, no_load_loss, load_loss, transformer_rating
)
assert isinstance(output, np.ndarray)
assert output.shape == input_power.shape
def test_simple_efficiency_zero_load_loss():
input_power = np.array([500, 1000])
no_load_loss = 0.01
load_loss = 0.0
transformer_rating = 2000
with pytest.warns(RuntimeWarning):
output = simple_efficiency(
input_power, no_load_loss, load_loss, transformer_rating
)
assert np.all(np.isnan(output))