pyPRB 1.0.0__py3-none-any.whl
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.
- pyPRB/__init__.py +69 -0
- pyPRB/__version__.py +5 -0
- pyPRB/core.py +486 -0
- pyPRB/processing/__init__.py +32 -0
- pyPRB/processing/_vibration_extractor.py +339 -0
- pyPRB/processing/fft_extraction.py +230 -0
- pyPRB/processing/iq_demodulation.py +263 -0
- pyPRB/processing/least_squares_fit.py +210 -0
- pyPRB/processing/synchronous_averaging.py +321 -0
- pyprb-1.0.0.dist-info/METADATA +215 -0
- pyprb-1.0.0.dist-info/RECORD +13 -0
- pyprb-1.0.0.dist-info/WHEEL +4 -0
- pyprb-1.0.0.dist-info/licenses/License +21 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""Synchronous averaging extraction method.
|
|
2
|
+
|
|
3
|
+
Extracts the fundamental (once-per-revolution) vibration component by
|
|
4
|
+
averaging revolution-locked signal segments.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
from ._vibration_extractor import _rfft
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SynchronousAveraging:
|
|
15
|
+
"""Extracts the fundamental vibration component via synchronous averaging.
|
|
16
|
+
|
|
17
|
+
The trigger signal (e.g. from a photoelectric probe) is used to
|
|
18
|
+
segment the response signal into individual revolutions. These
|
|
19
|
+
segments are resampled to a common length and averaged, suppressing
|
|
20
|
+
noise that is not synchronous with the rotation. The fundamental
|
|
21
|
+
component is then extracted from FFT bin 1 of the averaged waveform.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
edge : str
|
|
26
|
+
Trigger edge used to define revolution boundaries:
|
|
27
|
+
``'rising'`` (default) or ``'falling'``.
|
|
28
|
+
period_tolerance : float
|
|
29
|
+
Relative tolerance for rejecting segments whose length deviates
|
|
30
|
+
from the expected rotation period. Default is 0.1 (±10 %).
|
|
31
|
+
plotting : bool
|
|
32
|
+
If ``True``, show diagnostic plots (trigger crossings and
|
|
33
|
+
synchronous average) during each call to :meth:`extract`.
|
|
34
|
+
Requires matplotlib (install with ``pip install pyPRB[plot]``).
|
|
35
|
+
|
|
36
|
+
Attributes
|
|
37
|
+
----------
|
|
38
|
+
segments_ : list of np.ndarray
|
|
39
|
+
Individual resampled revolution segments from the last call to
|
|
40
|
+
:meth:`extract`.
|
|
41
|
+
averaged_ : np.ndarray
|
|
42
|
+
Synchronously averaged waveform from the last call to
|
|
43
|
+
:meth:`extract`.
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
>>> from pyPRB.processing import SynchronousAveraging, VibrationExtractor
|
|
48
|
+
>>> method = SynchronousAveraging(edge='rising', period_tolerance=0.3,
|
|
49
|
+
... plotting=True)
|
|
50
|
+
>>> extractor = VibrationExtractor(sample_rate=10000, rotation_freq=25.0,
|
|
51
|
+
... method=method)
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
edge: str = "rising",
|
|
57
|
+
period_tolerance: float = 0.1,
|
|
58
|
+
plotting: bool = False,
|
|
59
|
+
):
|
|
60
|
+
if edge not in ("rising", "falling"):
|
|
61
|
+
raise ValueError(f"edge must be 'rising' or 'falling', got '{edge}'.")
|
|
62
|
+
if not 0 < period_tolerance < 1:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"period_tolerance must be between 0 and 1, got {period_tolerance}."
|
|
65
|
+
)
|
|
66
|
+
self.edge = edge
|
|
67
|
+
self.period_tolerance = period_tolerance
|
|
68
|
+
self.plotting = plotting
|
|
69
|
+
self.segments_: list[np.ndarray] = []
|
|
70
|
+
self.averaged_: np.ndarray | None = None
|
|
71
|
+
|
|
72
|
+
def extract(
|
|
73
|
+
self,
|
|
74
|
+
signal: np.ndarray,
|
|
75
|
+
trigger: np.ndarray,
|
|
76
|
+
sample_rate: float,
|
|
77
|
+
rotation_freq: float,
|
|
78
|
+
) -> tuple[float, float]:
|
|
79
|
+
"""Extract the fundamental amplitude and phase.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
signal : np.ndarray
|
|
84
|
+
Response signal (acceleration, velocity, …).
|
|
85
|
+
trigger : np.ndarray
|
|
86
|
+
Trigger signal from a photoelectric probe.
|
|
87
|
+
sample_rate : float
|
|
88
|
+
Sampling rate in Hz.
|
|
89
|
+
rotation_freq : float
|
|
90
|
+
Rotation frequency in Hz.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
amplitude : float
|
|
95
|
+
Peak amplitude of the fundamental component.
|
|
96
|
+
phase_deg : float
|
|
97
|
+
Phase of the fundamental component in degrees.
|
|
98
|
+
"""
|
|
99
|
+
crossings = self._find_trigger_crossings(trigger)
|
|
100
|
+
|
|
101
|
+
expected_period = sample_rate / rotation_freq
|
|
102
|
+
self.averaged_, self.segments_ = self._synchronous_average(
|
|
103
|
+
signal, crossings, expected_period,
|
|
104
|
+
)
|
|
105
|
+
amplitude, phase_deg = self._extract_fundamental(self.averaged_)
|
|
106
|
+
|
|
107
|
+
if self.plotting:
|
|
108
|
+
time = np.arange(len(trigger)) / sample_rate
|
|
109
|
+
n_total = len(crossings) - 1
|
|
110
|
+
n_rejected = n_total - len(self.segments_)
|
|
111
|
+
self._plot_extraction(
|
|
112
|
+
time, trigger, crossings, rotation_freq,
|
|
113
|
+
self.segments_, self.averaged_, amplitude, phase_deg,
|
|
114
|
+
expected_period=expected_period,
|
|
115
|
+
n_total=n_total,
|
|
116
|
+
n_rejected=n_rejected,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
return amplitude, phase_deg
|
|
120
|
+
|
|
121
|
+
def _find_trigger_crossings(self, trigger: np.ndarray) -> np.ndarray:
|
|
122
|
+
"""Return sample indices where the trigger signal crosses its mean.
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
trigger : np.ndarray
|
|
127
|
+
Trigger signal (e.g. from a photoelectric probe).
|
|
128
|
+
|
|
129
|
+
Returns
|
|
130
|
+
-------
|
|
131
|
+
np.ndarray
|
|
132
|
+
Integer sample indices of detected crossings.
|
|
133
|
+
|
|
134
|
+
Raises
|
|
135
|
+
------
|
|
136
|
+
ValueError
|
|
137
|
+
If no crossings are found.
|
|
138
|
+
"""
|
|
139
|
+
threshold = np.mean(trigger)
|
|
140
|
+
trigger_bool = trigger > threshold
|
|
141
|
+
diff = np.diff(trigger_bool.astype(np.int8))
|
|
142
|
+
|
|
143
|
+
if self.edge == "rising":
|
|
144
|
+
crossings = np.where(diff > 0)[0]
|
|
145
|
+
else:
|
|
146
|
+
crossings = np.where(diff < 0)[0]
|
|
147
|
+
|
|
148
|
+
if len(crossings) == 0:
|
|
149
|
+
raise ValueError(
|
|
150
|
+
f"No {self.edge} crossings found in the trigger signal. "
|
|
151
|
+
"Check that the trigger channel contains a periodic pulse."
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
return crossings
|
|
155
|
+
|
|
156
|
+
def _synchronous_average(
|
|
157
|
+
self,
|
|
158
|
+
signal: np.ndarray,
|
|
159
|
+
crossings: np.ndarray,
|
|
160
|
+
expected_period: float,
|
|
161
|
+
) -> tuple[np.ndarray, list[np.ndarray]]:
|
|
162
|
+
"""Average one-revolution segments of *signal* locked to *crossings*.
|
|
163
|
+
|
|
164
|
+
Each segment between consecutive trigger crossings is resampled to a
|
|
165
|
+
common length (median valid period) and then averaged. Segments whose
|
|
166
|
+
length deviates more than ``self.period_tolerance`` from
|
|
167
|
+
*expected_period* are rejected.
|
|
168
|
+
|
|
169
|
+
Parameters
|
|
170
|
+
----------
|
|
171
|
+
signal : np.ndarray
|
|
172
|
+
Response signal.
|
|
173
|
+
crossings : np.ndarray
|
|
174
|
+
Sample indices of trigger crossings.
|
|
175
|
+
expected_period : float
|
|
176
|
+
Expected period in samples (``sample_rate / rotation_freq``).
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
averaged : np.ndarray
|
|
181
|
+
Averaged waveform of length equal to the median valid period.
|
|
182
|
+
segments : list of np.ndarray
|
|
183
|
+
Individual resampled segments.
|
|
184
|
+
|
|
185
|
+
Raises
|
|
186
|
+
------
|
|
187
|
+
ValueError
|
|
188
|
+
If fewer than 2 valid segments remain after rejection.
|
|
189
|
+
"""
|
|
190
|
+
periods = np.diff(crossings)
|
|
191
|
+
|
|
192
|
+
lo = (1 - self.period_tolerance) * expected_period
|
|
193
|
+
hi = (1 + self.period_tolerance) * expected_period
|
|
194
|
+
valid_mask = (periods >= lo) & (periods <= hi)
|
|
195
|
+
|
|
196
|
+
if np.sum(valid_mask) < 2:
|
|
197
|
+
raise ValueError(
|
|
198
|
+
f"Only {int(np.sum(valid_mask))} valid segment(s) found "
|
|
199
|
+
f"(expected period ≈ {expected_period:.0f} samples, "
|
|
200
|
+
f"tolerance ±{self.period_tolerance*100:.0f}%). "
|
|
201
|
+
"Check rotation frequency and trigger signal."
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
median_period = np.median(periods[valid_mask])
|
|
205
|
+
target_samples = int(np.round(median_period))
|
|
206
|
+
|
|
207
|
+
segments = []
|
|
208
|
+
for i in range(len(crossings) - 1):
|
|
209
|
+
if not valid_mask[i]:
|
|
210
|
+
continue
|
|
211
|
+
start = crossings[i]
|
|
212
|
+
end = crossings[i + 1]
|
|
213
|
+
if start < 0 or end > len(signal):
|
|
214
|
+
continue
|
|
215
|
+
segment = signal[start:end]
|
|
216
|
+
x_old = np.linspace(0, 1, len(segment))
|
|
217
|
+
x_new = np.linspace(0, 1, target_samples)
|
|
218
|
+
resampled = np.interp(x_new, x_old, segment)
|
|
219
|
+
segments.append(resampled)
|
|
220
|
+
|
|
221
|
+
averaged = np.mean(np.array(segments), axis=0)
|
|
222
|
+
return averaged, segments
|
|
223
|
+
|
|
224
|
+
@staticmethod
|
|
225
|
+
def _extract_fundamental(averaged: np.ndarray) -> tuple[float, float]:
|
|
226
|
+
"""Extract the fundamental amplitude and phase from an averaged waveform.
|
|
227
|
+
|
|
228
|
+
The averaged waveform spans exactly one revolution, so FFT bin 1
|
|
229
|
+
corresponds to the fundamental (once-per-revolution) component.
|
|
230
|
+
|
|
231
|
+
Parameters
|
|
232
|
+
----------
|
|
233
|
+
averaged : np.ndarray
|
|
234
|
+
One-revolution averaged waveform.
|
|
235
|
+
|
|
236
|
+
Returns
|
|
237
|
+
-------
|
|
238
|
+
amplitude : float
|
|
239
|
+
Peak amplitude of the fundamental component.
|
|
240
|
+
phase_deg : float
|
|
241
|
+
Phase of the fundamental component in degrees.
|
|
242
|
+
"""
|
|
243
|
+
_, H = _rfft(averaged, sample_rate=len(averaged))
|
|
244
|
+
amplitude = float(np.abs(H[1]))
|
|
245
|
+
phase_deg = float(np.degrees(np.angle(H[1])))
|
|
246
|
+
return amplitude, phase_deg
|
|
247
|
+
|
|
248
|
+
# ------------------------------------------------------------------
|
|
249
|
+
# Plotting
|
|
250
|
+
# ------------------------------------------------------------------
|
|
251
|
+
|
|
252
|
+
def _plot_extraction(
|
|
253
|
+
self,
|
|
254
|
+
time: np.ndarray,
|
|
255
|
+
trigger: np.ndarray,
|
|
256
|
+
crossings: np.ndarray,
|
|
257
|
+
rotation_freq: float,
|
|
258
|
+
segments: list[np.ndarray],
|
|
259
|
+
averaged: np.ndarray,
|
|
260
|
+
amplitude: float,
|
|
261
|
+
phase_deg: float,
|
|
262
|
+
expected_period: float,
|
|
263
|
+
n_total: int,
|
|
264
|
+
n_rejected: int,
|
|
265
|
+
n_periods: int = 5,
|
|
266
|
+
) -> None:
|
|
267
|
+
"""Plot trigger crossings and synchronous average in one figure."""
|
|
268
|
+
from ._vibration_extractor import _import_matplotlib
|
|
269
|
+
plt = _import_matplotlib()
|
|
270
|
+
|
|
271
|
+
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8))
|
|
272
|
+
|
|
273
|
+
# -- Trigger crossings --
|
|
274
|
+
t_end = n_periods / rotation_freq
|
|
275
|
+
mask = time <= t_end
|
|
276
|
+
|
|
277
|
+
ax1.plot(time[mask], trigger[mask], color="steelblue", label="Trigger")
|
|
278
|
+
ax1.axhline(np.mean(trigger), color="gray", linestyle="--",
|
|
279
|
+
linewidth=0.8, label="Threshold")
|
|
280
|
+
|
|
281
|
+
crossings_in_window = crossings[crossings < np.sum(mask)]
|
|
282
|
+
ax1.scatter(time[crossings_in_window], trigger[crossings_in_window],
|
|
283
|
+
color="red", zorder=5, s=30, label="Crossings")
|
|
284
|
+
ax1.set_xlabel("Time (s)")
|
|
285
|
+
ax1.set_ylabel("Amplitude")
|
|
286
|
+
ax1.set_title(f"Trigger crossings ({len(crossings)} total, "
|
|
287
|
+
f"first {n_periods} periods shown)")
|
|
288
|
+
ax1.legend()
|
|
289
|
+
|
|
290
|
+
# -- Synchronous average --
|
|
291
|
+
target_samples = len(averaged)
|
|
292
|
+
angle = np.linspace(0, 360, target_samples, endpoint=False)
|
|
293
|
+
angle_rad = np.linspace(0, 2 * np.pi, target_samples, endpoint=False)
|
|
294
|
+
cosine_fit = amplitude * np.cos(angle_rad + np.deg2rad(phase_deg))
|
|
295
|
+
|
|
296
|
+
lo = (1 - self.period_tolerance) * expected_period
|
|
297
|
+
hi = (1 + self.period_tolerance) * expected_period
|
|
298
|
+
|
|
299
|
+
for seg in segments:
|
|
300
|
+
ax2.plot(angle, seg, color="gray", alpha=0.1)
|
|
301
|
+
ax2.plot(angle, averaged, color="red", linewidth=2, label="Average")
|
|
302
|
+
ax2.plot(angle, cosine_fit, color="blue", linestyle="--",
|
|
303
|
+
label=f"Fundamental: {amplitude:.4g} @ {phase_deg:.1f}\u00b0")
|
|
304
|
+
ax2.set_xlabel("Angle (\u00b0)")
|
|
305
|
+
ax2.set_ylabel("Amplitude")
|
|
306
|
+
ax2.set_xlim(0, 360)
|
|
307
|
+
ax2.set_xticks(np.arange(0, 361, 45))
|
|
308
|
+
ax2.axhline(0, color="black", linewidth=0.5, linestyle="--")
|
|
309
|
+
ax2.set_title(
|
|
310
|
+
f"Synchronous average \u2014 "
|
|
311
|
+
f"{len(segments)}/{n_total} segments "
|
|
312
|
+
f"({n_rejected} rejected, "
|
|
313
|
+
f"tolerance \u00b1{self.period_tolerance*100:.0f}%)\n"
|
|
314
|
+
f"Expected period: {expected_period:.0f} samples, "
|
|
315
|
+
f"bounds: [{lo:.0f}, {hi:.0f}], "
|
|
316
|
+
f"median period: {target_samples} samples"
|
|
317
|
+
)
|
|
318
|
+
ax2.legend()
|
|
319
|
+
|
|
320
|
+
plt.tight_layout()
|
|
321
|
+
plt.show(block=True)
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyPRB
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Static and dynamic rotor balancing using portable measurement equipment calculations based on Brüel & Kjær guide.
|
|
5
|
+
Project-URL: homepage, https://github.com/ladisk/pyPRB
|
|
6
|
+
Project-URL: documentation, https://github.com/ladisk/pyPRB
|
|
7
|
+
Project-URL: source, https://github.com/ladisk/pyPRB
|
|
8
|
+
Author-email: Gašper Krivic <gasper.krivic@fs.uni-lj.si>
|
|
9
|
+
Maintainer-email: Gašper Krivic <gasper.krivic@fs.uni-lj.si>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: License
|
|
12
|
+
Keywords: balancing,dynamics,mechanical-engineering,rotor,vibration
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Requires-Dist: numpy>=1.20.0
|
|
26
|
+
Requires-Dist: tabulate>=0.8.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build; extra == 'dev'
|
|
29
|
+
Requires-Dist: matplotlib>=3.5.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
31
|
+
Requires-Dist: sphinx; extra == 'dev'
|
|
32
|
+
Requires-Dist: sphinx-book-theme; extra == 'dev'
|
|
33
|
+
Requires-Dist: sphinx-copybutton>=0.5.2; extra == 'dev'
|
|
34
|
+
Requires-Dist: twine; extra == 'dev'
|
|
35
|
+
Requires-Dist: wheel; extra == 'dev'
|
|
36
|
+
Provides-Extra: plot
|
|
37
|
+
Requires-Dist: matplotlib>=3.5.0; extra == 'plot'
|
|
38
|
+
Description-Content-Type: text/x-rst
|
|
39
|
+
|
|
40
|
+
Rotor Balancing
|
|
41
|
+
===============
|
|
42
|
+
|
|
43
|
+
A Python package for static and dynamic rotor balancing calculations based on the methodology described in "Static and Dynamic Balancing using portable measuring equipment" by John Vaughan (Brüel & Kjær Application Note).
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
Features
|
|
47
|
+
--------
|
|
48
|
+
|
|
49
|
+
* **VibrationVector**: Represents unbalance by means of a vector
|
|
50
|
+
* **MassVector**: Represents a mass placed at an angular position on a rotor
|
|
51
|
+
* **StaticBalancing**: Single-plane balancing for rotors
|
|
52
|
+
* **DynamicBalancing**: Two-plane balancing for rotors
|
|
53
|
+
* **VibrationExtractor**: Extracts vibration vectors from time-domain signals
|
|
54
|
+
* **detect_rotation_freq**: Detects rotation frequency from a trigger signal
|
|
55
|
+
* Four pluggable extraction methods: **IQDemodulation** (default),
|
|
56
|
+
**LeastSquaresFit**, **SynchronousAveraging**, **FFTExtraction**
|
|
57
|
+
|
|
58
|
+
Installation
|
|
59
|
+
------------
|
|
60
|
+
|
|
61
|
+
Install from PyPI:
|
|
62
|
+
|
|
63
|
+
.. code-block:: bash
|
|
64
|
+
|
|
65
|
+
pip install pyPRB
|
|
66
|
+
|
|
67
|
+
Or install from source:
|
|
68
|
+
|
|
69
|
+
.. code-block:: bash
|
|
70
|
+
|
|
71
|
+
git clone https://github.com/ladisk/pyPRB.git
|
|
72
|
+
cd pyPRB
|
|
73
|
+
pip install .
|
|
74
|
+
|
|
75
|
+
For development installation:
|
|
76
|
+
|
|
77
|
+
.. code-block:: bash
|
|
78
|
+
|
|
79
|
+
pip install -e .[dev]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
Quick Start
|
|
83
|
+
-----------
|
|
84
|
+
|
|
85
|
+
Static Balancing Example
|
|
86
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
87
|
+
|
|
88
|
+
.. code-block:: python
|
|
89
|
+
|
|
90
|
+
from pyPRB import VibrationVector, MassVector, StaticBalancing
|
|
91
|
+
|
|
92
|
+
# Initial measurements
|
|
93
|
+
V_0 = VibrationVector(amplitude=3.4, phase=116) # No trial mass
|
|
94
|
+
V_1 = VibrationVector(amplitude=1.8, phase=42) # With trial mass
|
|
95
|
+
|
|
96
|
+
# Trial mass: 2.0 g mounted at 0° on the rotor
|
|
97
|
+
trial_mass = MassVector(2.0, 0.0)
|
|
98
|
+
|
|
99
|
+
# Create balancer
|
|
100
|
+
balancer = StaticBalancing(V_0, V_1, trial_mass=trial_mass)
|
|
101
|
+
|
|
102
|
+
# Display measurement table
|
|
103
|
+
print(balancer)
|
|
104
|
+
|
|
105
|
+
# Compute compensation
|
|
106
|
+
comp_mass = balancer.compute_compensation()
|
|
107
|
+
# Output: Compensation mass: 2.01 g at position -30.8° on the rotor.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
Dynamic Balancing Example
|
|
111
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
112
|
+
|
|
113
|
+
.. code-block:: python
|
|
114
|
+
|
|
115
|
+
from pyPRB import VibrationVector, MassVector, DynamicBalancing
|
|
116
|
+
|
|
117
|
+
# Initial measurements (no trial masses)
|
|
118
|
+
V_1_0 = VibrationVector(7.2, 238) # Plane 1
|
|
119
|
+
V_2_0 = VibrationVector(13.5, 296) # Plane 2
|
|
120
|
+
|
|
121
|
+
# With trial mass in Plane 1
|
|
122
|
+
V_1_1 = VibrationVector(4.9, 114) # Plane 1
|
|
123
|
+
V_2_1 = VibrationVector(9.2, 347) # Plane 2
|
|
124
|
+
|
|
125
|
+
# With trial mass in Plane 2
|
|
126
|
+
V_1_2 = VibrationVector(4.0, 79) # Plane 1
|
|
127
|
+
V_2_2 = VibrationVector(12.0, 292) # Plane 2
|
|
128
|
+
|
|
129
|
+
# Trial masses: 2.5 g each, mounted at 0° on their respective planes
|
|
130
|
+
trial_mass_1 = MassVector(2.5, 0.0)
|
|
131
|
+
trial_mass_2 = MassVector(2.5, 0.0)
|
|
132
|
+
|
|
133
|
+
# Create balancer
|
|
134
|
+
balancer = DynamicBalancing(
|
|
135
|
+
V_1_0, V_2_0, V_1_1, V_2_1, V_1_2, V_2_2,
|
|
136
|
+
trial_mass_1=trial_mass_1, trial_mass_2=trial_mass_2
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Display measurement table
|
|
140
|
+
print(balancer)
|
|
141
|
+
|
|
142
|
+
# Compute compensations for both planes
|
|
143
|
+
comp_mass_1, comp_mass_2 = balancer.compute_compensation()
|
|
144
|
+
# Output:
|
|
145
|
+
# +---------+---------------------+------------+
|
|
146
|
+
# | Plane | Compensation Mass | Position |
|
|
147
|
+
# +=========+=====================+============+
|
|
148
|
+
# | 1 | 2.95 g | 50.2° |
|
|
149
|
+
# +---------+---------------------+------------+
|
|
150
|
+
# | 2 | 2.84 g | -81.9° |
|
|
151
|
+
# +---------+---------------------+------------+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
Extracting Vibration Vectors from Measurements
|
|
155
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
156
|
+
|
|
157
|
+
.. code-block:: python
|
|
158
|
+
|
|
159
|
+
import numpy as np
|
|
160
|
+
from pyPRB import (
|
|
161
|
+
VibrationExtractor, detect_rotation_freq,
|
|
162
|
+
MassVector, StaticBalancing,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# Synthetic signals (B&K Example 2)
|
|
166
|
+
sample_rate = 10000 # Hz
|
|
167
|
+
f0_true = 25.0 # rotation frequency (Hz)
|
|
168
|
+
duration = 5.0 # s
|
|
169
|
+
t = np.arange(0, duration, 1 / sample_rate)
|
|
170
|
+
rng = np.random.default_rng(0)
|
|
171
|
+
|
|
172
|
+
trigger = np.sign(np.sin(2 * np.pi * f0_true * t))
|
|
173
|
+
signal_run0 = (3.4 * np.cos(2 * np.pi * f0_true * t + np.deg2rad(116))
|
|
174
|
+
+ 0.05 * rng.standard_normal(len(t)))
|
|
175
|
+
signal_run1 = (1.8 * np.cos(2 * np.pi * f0_true * t + np.deg2rad(42))
|
|
176
|
+
+ 0.05 * rng.standard_normal(len(t)))
|
|
177
|
+
|
|
178
|
+
# 1. Detect rotation frequency from the trigger signal
|
|
179
|
+
f0 = detect_rotation_freq(trigger, sample_rate=sample_rate, max_freq=50.0)
|
|
180
|
+
|
|
181
|
+
# 2. Create extractor (default method: IQ demodulation)
|
|
182
|
+
extractor = VibrationExtractor(sample_rate=sample_rate, rotation_freq=f0)
|
|
183
|
+
|
|
184
|
+
# 3. Extract vibration vectors for each measurement run
|
|
185
|
+
V_0 = extractor.get_vibration_vector(signal_run0, trigger)
|
|
186
|
+
V_1 = extractor.get_vibration_vector(signal_run1, trigger)
|
|
187
|
+
|
|
188
|
+
# 4. Use the vectors for balancing
|
|
189
|
+
trial_mass = MassVector(2.0, 0.0)
|
|
190
|
+
balancer = StaticBalancing(V_0, V_1, trial_mass=trial_mass)
|
|
191
|
+
comp_mass = balancer.compute_compensation()
|
|
192
|
+
# Output: Compensation mass: 2.01 g at position -30.8° on the rotor.
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
Balancing procedure
|
|
196
|
+
-------------------
|
|
197
|
+
|
|
198
|
+
Static Balancing
|
|
199
|
+
~~~~~~~~~~~~~~~~
|
|
200
|
+
|
|
201
|
+
For a rotor with unbalance in a single plane:
|
|
202
|
+
|
|
203
|
+
1. Measure initial vibration vector **V₀**
|
|
204
|
+
2. Add known trial mass **m** and measure resulting vibration **V₁**
|
|
205
|
+
3. Compute compensation mass with `StaticBalancing`
|
|
206
|
+
|
|
207
|
+
Dynamic Balancing
|
|
208
|
+
~~~~~~~~~~~~~~~~~
|
|
209
|
+
|
|
210
|
+
For a rotor requiring two-plane balancing:
|
|
211
|
+
|
|
212
|
+
1. Measure initial vibration vectors in both planes: **V₁,₀** and **V₂,₀**
|
|
213
|
+
2. Add trial mass **m₁,₁** in plane 1, measure: **V₁,₁** and **V₂,₁**
|
|
214
|
+
3. Add trial mass **m₂,₂** in plane 2, measure: **V₁,₂** and **V₂,₂**
|
|
215
|
+
4. Compute compensation masses in both planes with `DynamicBalancing`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
pyPRB/__init__.py,sha256=ZZ7txiNRkP2D08updlbrMINpo2OiBkGZqHzJUVg4NfY,2292
|
|
2
|
+
pyPRB/__version__.py,sha256=HZH0pz5_uN82TsyQYT2XElxfADrhYTOqcXOuYtt-e-o,142
|
|
3
|
+
pyPRB/core.py,sha256=7XdlQ08FmRMamm8hGTYLHyB3_bKqgtSEo-R6GaRD_Qg,17733
|
|
4
|
+
pyPRB/processing/__init__.py,sha256=Z4S0P3R7mwlRWurEjzvUFvMNlm-xyKV2FZP6oL5UWp0,1219
|
|
5
|
+
pyPRB/processing/_vibration_extractor.py,sha256=jNpZGiqnwjyZcvA3ftRTspFtyWH2_3PQztjpCrJvpCk,10258
|
|
6
|
+
pyPRB/processing/fft_extraction.py,sha256=hagyDYOui93qG5Lgqh7QPVv5TUoHqISw-EK0FqGAXK4,8094
|
|
7
|
+
pyPRB/processing/iq_demodulation.py,sha256=o9eAAUyElh-i0Mj4D6Qx9K2GOjWOuXm4eeYS3bKwI4Q,9375
|
|
8
|
+
pyPRB/processing/least_squares_fit.py,sha256=3JNScG35HUmpUhb157X4ZwymT2q9T5ji14O3uSmO3fE,7273
|
|
9
|
+
pyPRB/processing/synchronous_averaging.py,sha256=GlpmcY54F6nZek2EDcvy_vHEN8BGjclWbcCyVtlKqXQ,11416
|
|
10
|
+
pyprb-1.0.0.dist-info/METADATA,sha256=3_ediBp4iqcTEfaCIRITRYosODm261pAyr0jjtuBZNs,7198
|
|
11
|
+
pyprb-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
12
|
+
pyprb-1.0.0.dist-info/licenses/License,sha256=cAmeVSRCFsLHARbJSzk3MUkKSz9k86pVhTF9Irlo3mc,1102
|
|
13
|
+
pyprb-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Gašper Krivic 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|