Skip to content

Commit f6dd902

Browse files
committed
whenxuan: black init for the repo
1 parent 36cd698 commit f6dd902

72 files changed

Lines changed: 415 additions & 251 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/ipynb_to_gallery.py‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ def _convert_table(lines: list[str]) -> str:
200200
def _convert_blockquote(lines: list[str]) -> str:
201201
body = [re.sub(r"^\s*>\s?", "", line) for line in lines]
202202
converted = _convert_inline("\n".join(body)).strip()
203-
indented = [" " + line if line.strip() else "" for line in converted.splitlines()]
203+
indented = [
204+
" " + line if line.strip() else "" for line in converted.splitlines()
205+
]
204206
return "\n\n.. epigraph::\n\n" + "\n".join(indented) + "\n"
205207

206208

@@ -256,12 +258,18 @@ def _stash_display(match: re.Match[str]) -> str:
256258
out.append("")
257259
continue
258260

259-
if stripped.startswith("|") and i + 1 < n and (
260-
TABLE_SEP_RE.match(lines[i + 1]) or lines[i + 1].strip().startswith("|")
261+
if (
262+
stripped.startswith("|")
263+
and i + 1 < n
264+
and (
265+
TABLE_SEP_RE.match(lines[i + 1]) or lines[i + 1].strip().startswith("|")
266+
)
261267
):
262268
table_lines = [line]
263269
i += 1
264-
while i < n and (lines[i].strip().startswith("|") or TABLE_SEP_RE.match(lines[i])):
270+
while i < n and (
271+
lines[i].strip().startswith("|") or TABLE_SEP_RE.match(lines[i])
272+
):
265273
table_lines.append(lines[i])
266274
i += 1
267275
out.append(_convert_table(table_lines))
@@ -312,7 +320,9 @@ def _stash_display(match: re.Match[str]) -> str:
312320

313321
text = "\n".join(out)
314322
for idx, body in enumerate(display_blocks):
315-
text = text.replace(f"@@DISPLAYMATH{idx}@@", _rst_display_math(body).strip("\n"))
323+
text = text.replace(
324+
f"@@DISPLAYMATH{idx}@@", _rst_display_math(body).strip("\n")
325+
)
316326
text = re.sub(r"\n{3,}", "\n\n", text)
317327
return text.strip() + "\n"
318328

@@ -336,11 +346,19 @@ def strip_boilerplate(code: str) -> str:
336346
code = BOILERPLATE_RE.sub("", code)
337347
code = PYSDKIT_PATH_PRINT_RE.sub("", code)
338348
leftover = code
339-
if "sys." not in leftover and not re.search(r"\bsys\b", leftover.replace("import sys", "")):
340-
leftover = re.sub(r"^import sys\s*\n", "", leftover, count=1, flags=re.MULTILINE)
341-
uses_path = bool(re.search(r"\bPath\b", leftover.replace("from pathlib import Path", "")))
349+
if "sys." not in leftover and not re.search(
350+
r"\bsys\b", leftover.replace("import sys", "")
351+
):
352+
leftover = re.sub(
353+
r"^import sys\s*\n", "", leftover, count=1, flags=re.MULTILINE
354+
)
355+
uses_path = bool(
356+
re.search(r"\bPath\b", leftover.replace("from pathlib import Path", ""))
357+
)
342358
if not uses_path:
343-
leftover = re.sub(r"^from pathlib import Path\s*\n", "", leftover, count=1, flags=re.MULTILINE)
359+
leftover = re.sub(
360+
r"^from pathlib import Path\s*\n", "", leftover, count=1, flags=re.MULTILINE
361+
)
344362
leftover = re.sub(r"\n{3,}", "\n\n", leftover)
345363
return leftover.strip() + ("\n" if leftover.strip() else "")
346364

@@ -403,7 +421,9 @@ def convert_notebook(ipynb_path: Path) -> str:
403421

404422
def write_gallery_header(path: Path, title: str, body: str) -> None:
405423
underline = "=" * len(title)
406-
path.write_text(f"{title}\n{underline}\n\n{body.rstrip()}\n", encoding="utf-8", newline="\n")
424+
path.write_text(
425+
f"{title}\n{underline}\n\n{body.rstrip()}\n", encoding="utf-8", newline="\n"
426+
)
407427

408428

409429
def convert_all(*, delete_ipynb: bool = True) -> list[Path]:

‎docs/source/about/index.rst‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ Cite **two things** when a result depends on this library.
4747
Replace ``X.Y.Z`` with the installed version. If a software paper
4848
(for example JOSS) appears later, prefer that citation.
4949

50-
People
51-
------
50+
Developers
51+
----------
5252

5353
PySDKit is an open-source project started in April 2024. Releases,
54-
review, and the documentation are handled by the maintainers; algorithms
55-
and fixes come from a wider set of contributors.
54+
review, and the documentation are handled by the maintainers; academic
55+
guidance is listed as project **Support**. Algorithms and fixes come
56+
from a wider set of contributors.
5657

5758
.. list-table::
5859
:header-rows: 1
@@ -66,7 +67,10 @@ and fixes come from a wider set of contributors.
6667
- wwhenxuan@gmail.com
6768
* - `RuiZhe Wang <https://github.com/changewam>`_
6869
- Maintainer
69-
- 3133986068@qq.com
70+
- changewam6@gmail.com
71+
* - `Dan Wang <https://web.xidian.edu.cn/danwang/>`_
72+
- Support
73+
- danwang@xidian.edu.cn
7074

7175
Package metadata also lists Rongkun Zhu, Kai Wu, Lei Wang, josefinez,
7276
Deeksha Manjunath, Yuan Feng, WenTong Zhao, and JacktheFowler. The

‎docs/source/index.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Quick links
5656
:link: about/index
5757
:link-type: doc
5858

59-
License, how to cite, maintainers, and related projects.
59+
License, how to cite, people, and related projects.
6060

6161
.. toctree::
6262
:hidden:

‎examples/acmd/acmd.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
1616
.. epigraph::
1717
18-
S. Chen, Y. Yang, Z. Peng, *et al.*
19-
*Detection of Rub-Impact Fault for Rotor-Stator Systems: A Novel Method Based on Adaptive Chirp Mode Decomposition.*
18+
S. Chen, Y. Yang, Z. Peng, *et al.*
19+
*Detection of Rub-Impact Fault for Rotor-Stator Systems: A Novel Method Based on Adaptive Chirp Mode Decomposition.*
2020
Journal of Sound and Vibration, 2018.
2121
2222
MATLAB code: `File Exchange 69128 <https://www.mathworks.com/matlabcentral/fileexchange/69128-adaptive-chirp-mode-decomposition>`_.

‎examples/acmd/ba_acmd.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
1818
.. epigraph::
1919
20-
S. Chen, L. Guo, J. Fan, C. Yi, K. Wang, W. Zhai.
21-
*Bandwidth-aware adaptive chirp mode decomposition for railway bearing fault diagnosis.*
22-
Structural Health Monitoring, 23(2):876–902, 2024.
20+
S. Chen, L. Guo, J. Fan, C. Yi, K. Wang, W. Zhai.
21+
*Bandwidth-aware adaptive chirp mode decomposition for railway bearing fault diagnosis.*
22+
Structural Health Monitoring, 23(2):876–902, 2024.
2323
DOI: `10.1177/14759217231174699 <https://doi.org/10.1177/14759217231174699>`_
2424
2525
MATLAB code: `File Exchange 132792 <https://www.mathworks.com/matlabcentral/fileexchange/132792>`_.

‎examples/acmd/dd_acmd.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
1111
.. epigraph::
1212
13-
H. Wang, S. Chen, W. Zhai.
14-
*Data-driven adaptive chirp mode decomposition with application to machine fault diagnosis under non-stationary conditions.*
15-
Mechanical Systems and Signal Processing, 2023.
13+
H. Wang, S. Chen, W. Zhai.
14+
*Data-driven adaptive chirp mode decomposition with application to machine fault diagnosis under non-stationary conditions.*
15+
Mechanical Systems and Signal Processing, 2023.
1616
DOI / MSSP: `S0888327022010652 <https://www.sciencedirect.com/science/article/abs/pii/S0888327022010652>`_
1717
1818
MATLAB code: `File Exchange 121373 <https://www.mathworks.com/matlabcentral/fileexchange/121373>`_.
@@ -25,7 +25,7 @@
2525
# .. list-table::
2626
# :header-rows: 1
2727
#
28-
# * -
28+
# * -
2929
# - **ACMD**
3030
# - **DD-ACMD**
3131
# * - Role
@@ -314,6 +314,7 @@
314314
imfs3, ini3, eif3, eia3 = dd3.fit_transform(sig3, return_all=True)
315315
print(f"Extracted K = {imfs3.shape[0]} modes")
316316

317+
317318
# Match each true chirp to the nearest estimated IF (skip near-zero trend if present)
318319
def _match_mode(true_if, eifs):
319320
errs = [
@@ -322,6 +323,7 @@ def _match_mode(true_if, eifs):
322323
]
323324
return int(np.argmin(errs))
324325

326+
325327
fig, ax = plt.subplots(figsize=(8, 4))
326328
colors = ["C0", "C1", "C2"]
327329
for k, (true_if, true_m) in enumerate(zip(ifs3_true, modes3)):

‎examples/deconvolution/acycbd.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
.. list-table::
3434
:header-rows: 1
3535
36-
* -
36+
* -
3737
- **CYCBD**
3838
- **ACYCBD** (this notebook)
3939
* - Cyclic frequency

‎examples/deconvolution/imckd.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
.. list-table::
3535
:header-rows: 1
3636
37-
* -
37+
* -
3838
- **MCKD**
3939
- **IMCKD** (this notebook)
4040
* - Period :math:`T`

‎examples/demo.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
#
200200
# Dragomiretskiy & Zosso extend VMD to 2D: each mode is compact around an unknown center frequency :math:`\boldsymbol{\omega}_k\in\mathbb{R}^2`, which suits textures and directional oscillations. Below we use ``test_grayscale()`` (paper-style synthetic texture) and ``test_univariate_image`` for a quick demo; full experiments live in ``examples/image/vmd2d.py``.
201201

202+
202203
def show_image_modes(img, modes, title=""):
203204
"""modes: (H, W, K)"""
204205
K = modes.shape[2]
@@ -216,6 +217,7 @@ def show_image_modes(img, modes, title=""):
216217
plt.tight_layout()
217218
plt.show()
218219

220+
219221
img = test_grayscale()
220222
print("grayscale texture shape:", img.shape)
221223

‎examples/emd/emd.py‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
1313
This notebook walks through the **complete sifting pipeline** with visualizations at every stage:
1414
15-
#. Motivation and IMF definition
16-
#. Algorithm overview (paper flow diagram)
17-
#. Demo signal
18-
#. Extremum detection
19-
#. Upper / lower envelope construction
20-
#. Local mean (low-frequency trend)
21-
#. One sifting step: subtract the mean
22-
#. Multiple sifting iterations until an IMF
23-
#. Full EMD with PySDKit
24-
#. Completeness and reconstruction
15+
#. Motivation and IMF definition
16+
#. Algorithm overview (paper flow diagram)
17+
#. Demo signal
18+
#. Extremum detection
19+
#. Upper / lower envelope construction
20+
#. Local mean (low-frequency trend)
21+
#. One sifting step: subtract the mean
22+
#. Multiple sifting iterations until an IMF
23+
#. Full EMD with PySDKit
24+
#. Completeness and reconstruction
2525
#. Summary
2626
"""
2727

@@ -39,7 +39,7 @@
3939
#
4040
# An IMF :math:`x_n(t)` must satisfy (Zeiler et al. / Huang et al.):
4141
#
42-
# #. **Extremum–zero-crossing balance**: between two successive zero crossings there is only one extremum — equivalently, the numbers of local maxima and minima differ by at most one.
42+
# #. **Extremum–zero-crossing balance**: between two successive zero crossings there is only one extremum — equivalently, the numbers of local maxima and minima differ by at most one.
4343
# #. **Zero local mean**: the mean of the upper and lower envelopes is (approximately) zero.
4444
#
4545
# An IMF may still have **amplitude and frequency modulation**; the zero-mean condition makes subsequent Hilbert analysis physically meaningful.
@@ -59,23 +59,23 @@
5959
#
6060
# Paper §II / Fig. 1. To extract the :math:`n`-th IMF from the current residue :math:`r_{n-1}(t)`:
6161
#
62-
# #. Initialize :math:`h_0(t):=r_{n-1}(t)`, :math:`k:=1`.
63-
# #. **Find extrema** of :math:`h_{k-1}(t)`.
64-
# #. **Interpolate** cubic-spline envelopes :math:`U_{k-1}(t)` (through maxima) and :math:`L_{k-1}(t)` (through minima).
62+
# #. Initialize :math:`h_0(t):=r_{n-1}(t)`, :math:`k:=1`.
63+
# #. **Find extrema** of :math:`h_{k-1}(t)`.
64+
# #. **Interpolate** cubic-spline envelopes :math:`U_{k-1}(t)` (through maxima) and :math:`L_{k-1}(t)` (through minima).
6565
# #. **Local mean** (low-frequency trend):
6666
#
6767
# .. math::
6868
#
6969
# m_{k-1}(t)=\frac{U_{k-1}(t)+L_{k-1}(t)}{2}.
7070
#
71-
# (Some texts misprint this as a difference; the physically correct trend estimate is the **average** of the envelopes.)
71+
# (Some texts misprint this as a difference; the physically correct trend estimate is the **average** of the envelopes.)
7272
# #. **Sift**:
7373
#
7474
# .. math::
7575
#
7676
# h_k(t)=h_{k-1}(t)-m_{k-1}(t).
7777
#
78-
# #. If :math:`h_k` is not yet an IMF, set :math:`k\leftarrow k+1` and repeat from step 1; otherwise set :math:`x_n:=h_k` and :math:`r_n:=r_{n-1}-x_n`.
78+
# #. If :math:`h_k` is not yet an IMF, set :math:`k\leftarrow k+1` and repeat from step 1; otherwise set :math:`x_n:=h_k` and :math:`r_n:=r_{n-1}-x_n`.
7979
# #. Stop when :math:`r_n` is a monotonic / low-variation residuum; otherwise continue with :math:`n\leftarrow n+1`.
8080
#
8181
# The next cells implement and visualize steps 1–5 explicitly before calling the full PySDKit ``EMD`` class.
@@ -98,11 +98,13 @@
9898
}
9999
)
100100

101+
101102
def relative_error(ref, est):
102103
ref = np.asarray(ref, dtype=float)
103104
est = np.asarray(est, dtype=float)
104105
return np.linalg.norm(est - ref) / (np.linalg.norm(ref) + 1e-16)
105106

107+
106108
def find_extrema_simple(t, x):
107109
# Discrete extrema via first differences (same idea as EMD extrema_detection='simple').
108110
dx = np.diff(x)
@@ -121,6 +123,7 @@ def find_extrema_simple(t, x):
121123
min_idx = np.unique(np.r_[min_idx, len(x) - 1])
122124
return max_idx, min_idx
123125

126+
124127
def cubic_envelope(t, t_ext, x_ext):
125128
# Build a cubic spline through extrema; require >= 2 points.
126129
if len(t_ext) < 2:
@@ -135,6 +138,7 @@ def cubic_envelope(t, t_ext, x_ext):
135138
cs = CubicSpline(t_ext, x_ext, bc_type="not-a-knot", extrapolate=True)
136139
return cs(t)
137140

141+
138142
def one_sift_step(t, h):
139143
# One complete sifting iteration: extrema -> envelopes -> mean -> h - m.
140144
max_idx, min_idx = find_extrema_simple(t, h)
@@ -151,6 +155,7 @@ def one_sift_step(t, h):
151155
"h_new": h_new,
152156
}
153157

158+
154159
# %%
155160
# 3. Demo signal
156161
# --------------
@@ -289,8 +294,8 @@ def one_sift_step(t, h):
289294
#
290295
# We repeat Steps A–D for several iterations and watch:
291296
#
292-
# * envelopes become more symmetric;
293-
# * the local mean shrinks toward zero;
297+
# * envelopes become more symmetric;
298+
# * the local mean shrinks toward zero;
294299
# * the prototype becomes a zero-mean oscillation (IMF candidate).
295300

296301
n_show = 4
@@ -431,9 +436,9 @@ def one_sift_step(t, h):
431436
#
432437
# **Key takeaways**
433438
#
434-
# #. EMD is **data-driven**: no preset frequencies or mother wavelet.
435-
# #. Sifting is a local, iterative high-pass operation guided by envelopes.
436-
# #. Completeness: :math:`x=\sum\mathrm{IMFs}+r`.
439+
# #. EMD is **data-driven**: no preset frequencies or mother wavelet.
440+
# #. Sifting is a local, iterative high-pass operation guided by envelopes.
441+
# #. Completeness: :math:`x=\sum\mathrm{IMFs}+r`.
437442
# #. IMFs enable the **Hilbert–Huang Transform** (next example: ``hht.py``).
438443
#
439444
# One-liner

0 commit comments

Comments
 (0)