electrocute 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: electrocute
3
+ Version: 0.1.0
4
+ Summary: A Python library for electronic formulas and signal processing
5
+ Home-page: https://github.com/madhurthareja/electrocute
6
+ Author: Madhur Thareja
7
+ Author-email: madhurthareja1105@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: numpy>=1.21.0
14
+ Requires-Dist: scipy>=1.7.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # Electrocute
26
+
27
+ **Electrocute** is a Python library designed for electronic formulas and signal processing. It provides easy-to-use functions for calculations like Ohm's Law, power, FFT, DFT, and filters, making it ideal for engineers, students, and hobbyists.
28
+
29
+ ---
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install electrocute
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ from electrocute import Electrocute
41
+
42
+ # Calculate voltage using Ohm's Law
43
+ voltage = Electrocute.ohms_law(current=2, resistance=5)
44
+ print(f"Voltage: {voltage} V") # Output: 10 V
45
+
46
+ import numpy as np
47
+ from electrocute import Electrocute
48
+
49
+ t = np.linspace(0, 1, 1000, endpoint=False)
50
+ signal = np.sin(2 * np.pi * 10 * t)
51
+ freqs, amps = Electrocute.frequency_spectrum(signal, sampling_rate=1000)
52
+ ```
53
+
54
+ ## Features
55
+
56
+ - Electronic formulas (Ohm's Law, power calculations, etc.)
57
+ - Signal processing (FFT, DFT, frequency spectrum, filters)
58
+ - Extensible and well-documented API
59
+
60
+ ## Contributing
61
+
62
+ Contributions are welcome! Please submit a pull request or open an issue on GitHub.
63
+
64
+ ### Maintainers:
65
+ This library is under development and is actively maintained by Madhur Thareja.
66
+
67
+ ## License
68
+
69
+ MIT License
@@ -0,0 +1,45 @@
1
+ # Electrocute
2
+
3
+ **Electrocute** is a Python library designed for electronic formulas and signal processing. It provides easy-to-use functions for calculations like Ohm's Law, power, FFT, DFT, and filters, making it ideal for engineers, students, and hobbyists.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install electrocute
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ from electrocute import Electrocute
17
+
18
+ # Calculate voltage using Ohm's Law
19
+ voltage = Electrocute.ohms_law(current=2, resistance=5)
20
+ print(f"Voltage: {voltage} V") # Output: 10 V
21
+
22
+ import numpy as np
23
+ from electrocute import Electrocute
24
+
25
+ t = np.linspace(0, 1, 1000, endpoint=False)
26
+ signal = np.sin(2 * np.pi * 10 * t)
27
+ freqs, amps = Electrocute.frequency_spectrum(signal, sampling_rate=1000)
28
+ ```
29
+
30
+ ## Features
31
+
32
+ - Electronic formulas (Ohm's Law, power calculations, etc.)
33
+ - Signal processing (FFT, DFT, frequency spectrum, filters)
34
+ - Extensible and well-documented API
35
+
36
+ ## Contributing
37
+
38
+ Contributions are welcome! Please submit a pull request or open an issue on GitHub.
39
+
40
+ ### Maintainers:
41
+ This library is under development and is actively maintained by Madhur Thareja.
42
+
43
+ ## License
44
+
45
+ MIT License
@@ -0,0 +1,3 @@
1
+ from .formulas.basic import BasicFormulas
2
+ from .signal_processing.filters import Filters
3
+ from .signal_processing.transforms import Transforms
@@ -0,0 +1 @@
1
+ from .basic import *
@@ -0,0 +1,21 @@
1
+ class BasicFormulas:
2
+ @staticmethod
3
+ def ohms_law(voltage: float = None, current: float = None, resistance: float = None) -> float:
4
+ """
5
+ Calculate the missing parameter in Ohm's Law (V = I * R).
6
+ """
7
+ if voltage is None and current and resistance:
8
+ return current * resistance
9
+ elif current is None and voltage and resistance:
10
+ return voltage / resistance
11
+ elif resistance is None and voltage and current:
12
+ return voltage / current
13
+ else:
14
+ raise ValueError("Provide exactly two parameters: voltage, current, or resistance.")
15
+
16
+ @staticmethod
17
+ def power(voltage: float, current: float) -> float:
18
+ """
19
+ Calculate electrical power (P = V * I).
20
+ """
21
+ return voltage * current
@@ -0,0 +1,2 @@
1
+ from .filters import *
2
+ from .transforms import *
@@ -0,0 +1,45 @@
1
+ import numpy as np
2
+ from scipy import signal
3
+
4
+ class Filters:
5
+ @staticmethod
6
+ def low_pass_filter(signal_input: np.ndarray, cutoff: float, sampling_rate: float, order: int = 5) -> np.ndarray:
7
+ """
8
+ Apply a low-pass Butterworth filter to the input signal.
9
+ """
10
+ nyquist = 0.5 * sampling_rate
11
+ normal_cutoff = cutoff / nyquist
12
+ b, a = signal.butter(order, normal_cutoff, btype='low', analog=False)
13
+ return signal.filtfilt(b, a, signal_input)
14
+
15
+ @staticmethod
16
+ def high_pass_filter(signal_input: np.ndarray, cutoff: float, sampling_rate: float, order: int = 5) -> np.ndarray:
17
+ """
18
+ Apply a high-pass Butterworth filter to the input signal.
19
+ """
20
+ nyquist = 0.5 * sampling_rate
21
+ normal_cutoff = cutoff / nyquist
22
+ b, a = signal.butter(order, normal_cutoff, btype='high', analog=False)
23
+ return signal.filtfilt(b, a, signal_input)
24
+
25
+ @staticmethod
26
+ def band_pass_filter(signal_input: np.ndarray, lowcut: float, highcut: float, sampling_rate: float, order: int = 5) -> np.ndarray:
27
+ """
28
+ Apply a band-pass Butterworth filter to the input signal.
29
+ """
30
+ nyquist = 0.5 * sampling_rate
31
+ low = lowcut / nyquist
32
+ high = highcut / nyquist
33
+ b, a = signal.butter(order, [low, high], btype='band', analog=False)
34
+ return signal.filtfilt(b, a, signal_input)
35
+
36
+ @staticmethod
37
+ def band_stop_filter(signal_input: np.ndarray, lowcut: float, highcut: float, sampling_rate: float, order: int = 5) -> np.ndarray:
38
+ """
39
+ Apply a band-stop Butterworth filter to the input signal.
40
+ """
41
+ nyquist = 0.5 * sampling_rate
42
+ low = lowcut / nyquist
43
+ high = highcut / nyquist
44
+ b, a = signal.butter(order, [low, high], btype='bandstop', analog=False)
45
+ return signal.filtfilt(b, a, signal_input)
@@ -0,0 +1,32 @@
1
+ import numpy as np
2
+ from typing import Tuple
3
+
4
+ class Transforms:
5
+ @staticmethod
6
+ def dft(signal_input: np.ndarray) -> np.ndarray:
7
+ """
8
+ Compute the Discrete Fourier Transform of the input signal.
9
+ """
10
+ N = len(signal_input)
11
+ n = np.arange(N)
12
+ k = n.reshape((N, 1))
13
+ e = np.exp(-2j * np.pi * k * n / N)
14
+ return np.dot(e, signal_input)
15
+
16
+ @staticmethod
17
+ def fft(signal_input: np.ndarray) -> np.ndarray:
18
+ """
19
+ Compute the Fast Fourier Transform of the input signal using NumPy.
20
+ """
21
+ return np.fft.fft(signal_input)
22
+
23
+ @staticmethod
24
+ def frequency_spectrum(signal_input: np.ndarray, sampling_rate: float) -> Tuple[np.ndarray, np.ndarray]:
25
+ """
26
+ Compute the frequency spectrum of the input signal.
27
+ """
28
+ N = len(signal_input)
29
+ fft_result = np.fft.fft(signal_input)
30
+ frequencies = np.fft.fftfreq(N, 1 / sampling_rate)
31
+ amplitudes = np.abs(fft_result) / N
32
+ return frequencies[:N//2], amplitudes[:N//2]
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: electrocute
3
+ Version: 0.1.0
4
+ Summary: A Python library for electronic formulas and signal processing
5
+ Home-page: https://github.com/madhurthareja/electrocute
6
+ Author: Madhur Thareja
7
+ Author-email: madhurthareja1105@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: numpy>=1.21.0
14
+ Requires-Dist: scipy>=1.7.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # Electrocute
26
+
27
+ **Electrocute** is a Python library designed for electronic formulas and signal processing. It provides easy-to-use functions for calculations like Ohm's Law, power, FFT, DFT, and filters, making it ideal for engineers, students, and hobbyists.
28
+
29
+ ---
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install electrocute
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ from electrocute import Electrocute
41
+
42
+ # Calculate voltage using Ohm's Law
43
+ voltage = Electrocute.ohms_law(current=2, resistance=5)
44
+ print(f"Voltage: {voltage} V") # Output: 10 V
45
+
46
+ import numpy as np
47
+ from electrocute import Electrocute
48
+
49
+ t = np.linspace(0, 1, 1000, endpoint=False)
50
+ signal = np.sin(2 * np.pi * 10 * t)
51
+ freqs, amps = Electrocute.frequency_spectrum(signal, sampling_rate=1000)
52
+ ```
53
+
54
+ ## Features
55
+
56
+ - Electronic formulas (Ohm's Law, power calculations, etc.)
57
+ - Signal processing (FFT, DFT, frequency spectrum, filters)
58
+ - Extensible and well-documented API
59
+
60
+ ## Contributing
61
+
62
+ Contributions are welcome! Please submit a pull request or open an issue on GitHub.
63
+
64
+ ### Maintainers:
65
+ This library is under development and is actively maintained by Madhur Thareja.
66
+
67
+ ## License
68
+
69
+ MIT License
@@ -0,0 +1,15 @@
1
+ README.md
2
+ setup.py
3
+ electrocute/__init__.py
4
+ electrocute.egg-info/PKG-INFO
5
+ electrocute.egg-info/SOURCES.txt
6
+ electrocute.egg-info/dependency_links.txt
7
+ electrocute.egg-info/requires.txt
8
+ electrocute.egg-info/top_level.txt
9
+ electrocute/formulas/__init__.py
10
+ electrocute/formulas/basic.py
11
+ electrocute/image_processing/__init__.py
12
+ electrocute/signal_processing/__init__.py
13
+ electrocute/signal_processing/filters.py
14
+ electrocute/signal_processing/transforms.py
15
+ tests/test_electrocute.py
@@ -0,0 +1,2 @@
1
+ numpy>=1.21.0
2
+ scipy>=1.7.0
@@ -0,0 +1 @@
1
+ electrocute
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,23 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="electrocute",
5
+ version="0.1.0",
6
+ author="Madhur Thareja",
7
+ author_email="madhurthareja1105@gmail.com",
8
+ description="A Python library for electronic formulas and signal processing",
9
+ long_description=open("README.md").read(),
10
+ long_description_content_type="text/markdown",
11
+ url="https://github.com/madhurthareja/electrocute",
12
+ packages=find_packages(),
13
+ install_requires=[
14
+ "numpy>=1.21.0",
15
+ "scipy>=1.7.0",
16
+ ],
17
+ classifiers=[
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ ],
22
+ python_requires=">=3.7",
23
+ )
@@ -0,0 +1,51 @@
1
+ import pytest
2
+ import numpy as np
3
+ from electrocute.formulas.basic import BasicFormulas
4
+ from electrocute.signal_processing.filters import Filters
5
+ from electrocute.signal_processing.transforms import Transforms
6
+
7
+ def test_ohms_law():
8
+ assert BasicFormulas.ohms_law(current=2, resistance=5) == 10
9
+ assert BasicFormulas.ohms_law(voltage=10, resistance=5) == 2
10
+ assert BasicFormulas.ohms_law(voltage=10, current=2) == 5
11
+
12
+ def test_power():
13
+ assert BasicFormulas.power(voltage=10, current=2) == 20
14
+
15
+ def test_frequency_spectrum():
16
+ t = np.linspace(0, 1, 1000, endpoint=False)
17
+ signal = np.sin(2 * np.pi * 10 * t)
18
+ freqs, amps = Transforms.frequency_spectrum(signal, sampling_rate=1000)
19
+ assert len(freqs) == 500
20
+ assert len(amps) == 500
21
+
22
+ def test_low_pass_filter():
23
+ t = np.linspace(0, 1, 1000, endpoint=False)
24
+ signal = np.sin(2 * np.pi * 10 * t) + 0.5 * np.sin(2 * np.pi * 20 * t)
25
+ filtered_signal = Filters.low_pass_filter(signal, cutoff=15, sampling_rate=1000)
26
+ assert len(filtered_signal) == len(signal)
27
+ assert np.all(np.abs(filtered_signal) <= 1.5)
28
+
29
+ def test_high_pass_filter():
30
+ t = np.linspace(0, 1, 1000, endpoint=False)
31
+ signal = np.sin(2 * np.pi * 10 * t) + 0.5 * np.sin(2 * np.pi * 20 * t)
32
+ filtered_signal = Filters.high_pass_filter(signal, cutoff=15, sampling_rate=1000)
33
+ assert len(filtered_signal) == len(signal)
34
+ assert np.all(np.abs(filtered_signal) <= 1.5)
35
+
36
+ def test_band_pass_filter():
37
+ t = np.linspace(0, 1, 1000, endpoint=False)
38
+ signal = np.sin(2 * np.pi * 10 * t) + 0.5 * np.sin(2 * np.pi * 20 * t)
39
+ filtered_signal = Filters.band_pass_filter(signal, lowcut=5, highcut=15, sampling_rate=1000)
40
+ assert len(filtered_signal) == len(signal)
41
+ assert np.all(np.abs(filtered_signal) <= 1.5)
42
+
43
+ def test_band_stop_filter():
44
+ t = np.linspace(0, 1, 1000, endpoint=False)
45
+ signal = np.sin(2 * np.pi * 10 * t) + 0.5 * np.sin(2 * np.pi * 20 * t)
46
+ filtered_signal = Filters.band_stop_filter(signal, lowcut=5, highcut=15, sampling_rate=1000)
47
+ assert len(filtered_signal) == len(signal)
48
+ assert np.all(np.abs(filtered_signal) <= 1.5)
49
+
50
+ if __name__ == "__main__":
51
+ pytest.main()