Skip to content

Commit 70076dc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 43f2596 commit 70076dc

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

‎electronics/shunt_capacitor_power_factor_correction.py‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66

77
def shunt_capacitor_power_factor_correction(
8-
voltage: float, frequency: float, real_power: float, current_power_factor: float , expected_power_factor:float
9-
)->float:
10-
8+
voltage: float,
9+
frequency: float,
10+
real_power: float,
11+
current_power_factor: float,
12+
expected_power_factor: float,
13+
) -> float:
1114
"""
1215
Calculate shunt capacitor that will be added in order to achieve the expected power factor from the current power factor
13-
16+
1417
Examples:
1518
>>> shunt_capacitor_power_factor_correction(120,60,4000,0.8,0.95)
1619
0.00031043753362948597
17-
>>> shunt_capacitor_power_factor_correction(150,50,2000,0.6,0.87)
20+
>>> shunt_capacitor_power_factor_correction(150,50,2000,0.6,0.87)
1821
0.00021690547192207782
1922
>>> shunt_capacitor_power_factor_correction(115,0,800,0.6,0.87)
2023
Traceback (most recent call last):
@@ -26,45 +29,39 @@ def shunt_capacitor_power_factor_correction(
2629
ValueError: voltage is zero no excitation
2730
"""
2831
if (
29-
not isinstance(current_power_factor, (int, float))
32+
not isinstance(current_power_factor, (int, float))
3033
or not isinstance(expected_power_factor, (int, float))
31-
or current_power_factor < -1
32-
or current_power_factor > 1
34+
or current_power_factor < -1
35+
or current_power_factor > 1
3336
or expected_power_factor < -1
34-
or expected_power_factor > 1
37+
or expected_power_factor > 1
3538
):
3639
raise ValueError("power_factor must be a valid float value between -1 and 1.")
37-
38-
if (
39-
frequency == 0
40-
):
40+
41+
if frequency == 0:
4142
raise ValueError("frequency is zero dc circuit")
4243

43-
if (
44-
voltage == 0
45-
):
44+
if voltage == 0:
4645
raise ValueError("voltage is zero no excitation")
4746

4847
current_theta = math.acos(current_power_factor)
49-
expected_theta= math.acos(expected_power_factor)
50-
48+
expected_theta = math.acos(expected_power_factor)
49+
5150
current_apparent_power = real_power / current_power_factor
5251
current_reactive_power = current_apparent_power * math.sin(current_theta)
53-
expected_apparent_power= real_power / expected_power_factor
54-
expected_reactive_power= expected_apparent_power * math.sin(expected_theta)
52+
expected_apparent_power = real_power / expected_power_factor
53+
expected_reactive_power = expected_apparent_power * math.sin(expected_theta)
5554

5655
"""
5756
The difference between the new and old reactive powers is due to the
5857
parallel addition of the capacitor to the load
5958
"""
6059
change_reactive_power = current_reactive_power - expected_reactive_power
6160

62-
return change_reactive_power/( 2* math.pi * frequency * (voltage**2))
61+
return change_reactive_power / (2 * math.pi * frequency * (voltage**2))
6362
pass
6463

6564

66-
67-
6865
if __name__ == "__main__":
6966
import doctest
7067

0 commit comments

Comments
 (0)