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
100 lines (78 loc) · 2.52 KB
/
test_transformer.py
File metadata and controls
100 lines (78 loc) · 2.52 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
97
98
99
100
import pandas as pd
from numpy.testing import assert_allclose
from pvlib import transformer
import numpy as np
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,
)
def test_simple_efficiency_numpy_array_inputs():
input_power = np.array([100.0, 500.0, 1000.0])
no_load_loss = np.array([0.005, 0.005, 0.005])
load_loss = np.array([0.01, 0.01, 0.01])
rating = 1000.0
output_power = transformer.simple_efficiency(
input_power=input_power,
no_load_loss=no_load_loss,
load_loss=load_loss,
transformer_rating=rating
)
assert isinstance(output_power, np.ndarray)
assert output_power.shape == input_power.shape
def test_simple_efficiency_vector_equals_scalar():
input_power = np.array([200.0, 600.0, 900.0])
no_load_loss = 0.005
load_loss = 0.01
rating = 1000.0
vector_result = transformer.simple_efficiency(
input_power=input_power,
no_load_loss=no_load_loss,
load_loss=load_loss,
transformer_rating=rating
)
scalar_result = np.array([
transformer.simple_efficiency(p, no_load_loss, load_loss, rating)
for p in input_power
])
assert_allclose(vector_result, scalar_result)