pymodeflow 0.1.2__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.
modeflow/synthetic.py ADDED
@@ -0,0 +1,88 @@
1
+ """Synthetic time-resolved PIV-like data for demos and tests.
2
+
3
+ The field is the sum of two travelling-wave structures (each oscillating at one
4
+ frequency and optionally growing/decaying), spatially smooth noise and a constant
5
+ mean. Because the truth is known, results of :mod:`pivmodes.snap_pod` and
6
+ :mod:`pivmodes.spod` can be checked against it.
7
+
8
+ >>> from modeflow.synthetic import synthetic_piv
9
+ >>> data = synthetic_piv(nx=12, ny=8, nt=256, dt=0.004)
10
+ >>> data["U"].shape # [N, Nt] with N = nx * ny
11
+ (96, 256)
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from pathlib import Path
17
+
18
+ import numpy as np
19
+ from scipy.ndimage import gaussian_filter
20
+
21
+
22
+ def synthetic_piv(nx=60, ny=40, nt=5001, dt=0.002, tones=((5.0, 1.0), (12.0, 0.6)),
23
+ noise=3.0, mean=3.0, order="C", seed=1):
24
+ """Return a dict with the synthetic component ``U`` and the ground truth.
25
+
26
+ Parameters
27
+ ----------
28
+ nx, ny : grid size; ``nt`` snapshots ``dt`` seconds apart.
29
+ tones : ``((frequency_Hz, amplitude), (frequency_Hz, amplitude))``.
30
+ noise : standard deviation of the white noise before spatial smoothing.
31
+ mean : constant added to every point (removed again by the POD tools).
32
+ order : "C" or "F", the order in which every field is flattened into a column.
33
+
34
+ Keys of the result: ``U`` ([N, Nt]), ``dim`` ([nx, ny]), ``dt``, ``order``,
35
+ ``tones``, ``phi`` (list of the true complex spatial structures, each (nx, ny)),
36
+ ``signal`` ((nx, ny, nt), without noise and mean).
37
+ """
38
+ if order not in ("C", "F"):
39
+ raise ValueError("order must be 'C' or 'F'")
40
+ rng = np.random.default_rng(seed)
41
+ x = np.linspace(0, 1, nx)[:, None]
42
+ y = np.linspace(0, 1, ny)[None, :]
43
+ t = np.arange(nt) * dt
44
+ phi1 = np.exp(2j * np.pi * 1.0 * x) * np.sin(np.pi * y)
45
+ phi2 = np.exp(-2j * np.pi * 2.0 * x) * np.cos(np.pi * y) * np.ones_like(x)
46
+ phis = (phi1, phi2)
47
+ signal = np.zeros((nx, ny, nt))
48
+ for (f, a), phi in zip(tones, phis):
49
+ signal += a * np.real(phi[:, :, None] * np.exp(2j * np.pi * f * t))
50
+ rough = gaussian_filter(rng.normal(size=(nx, ny, nt)), sigma=(2, 2, 0)) * noise
51
+ field = signal + rough + mean
52
+ return {
53
+ "U": field.reshape(nx * ny, nt, order=order),
54
+ "dim": np.array([nx, ny]),
55
+ "dt": dt,
56
+ "order": order,
57
+ "tones": tuple(tones),
58
+ "phi": [np.asarray(p) for p in phis],
59
+ "signal": signal,
60
+ }
61
+
62
+
63
+ def save_synthetic_npz(path, **kwargs):
64
+ """Write :func:`synthetic_piv` data to an ``.npz`` file readable by the CLI tools."""
65
+ data = synthetic_piv(**kwargs)
66
+ path = Path(path)
67
+ np.savez(path, U=data["U"], dim=data["dim"])
68
+ return path
69
+
70
+
71
+ def main(argv=None):
72
+ import argparse
73
+
74
+ p = argparse.ArgumentParser(prog="python -m modeflow.synthetic",
75
+ description="Write a synthetic PIV-like .npz file.")
76
+ p.add_argument("-o", "--output", type=str, help="output .npz file")
77
+ p.add_argument("--nx", type=int, default=60)
78
+ p.add_argument("--ny", type=int, default=40)
79
+ p.add_argument("--nt", type=int, default=5001)
80
+ p.add_argument("--dt", type=float, default=0.002)
81
+ p.add_argument("--order", choices=("C", "F"), default="C")
82
+ args = p.parse_args(argv)
83
+ out = save_synthetic_npz(args.output, nx=args.nx, ny=args.ny, nt=args.nt, dt=args.dt, order=args.order)
84
+ print(f"wrote {out} (U: [{args.nx * args.ny}, {args.nt}], dim = [{args.nx}, {args.ny}], dt = {args.dt} s)")
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: pymodeflow
3
+ Version: 0.1.2
4
+ Summary: Python framework for Snapshot POD, spectral POD (SPOD, Welch's method) and Dynamic Mode Decomposition (DMD) of time-resolved experimental and schlieren imaging data
5
+ Author: Ekwonu Michael Chukwuemeka
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Ekwonu Michael Chukwuemeka
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/drmcekwonu/pyModeFlow
29
+ Project-URL: Documentation, https://drmcekwonu.github.io/pyModeFlow
30
+ Project-URL: Repository, https://github.com/drmcekwonu/pyModeFlow
31
+ Project-URL: Issues, https://github.com/drmcekwonu/pyModeFlow/issues
32
+ Project-URL: Changelog, https://github.com/drmcekwonu/pyModeFlow/blob/main/CHANGELOG.md
33
+ Keywords: DMD,PIV,POD,SPOD,spectral POD,modal decomposition,fluid mechanics,turbulence,coherent structures,Schlieren Imaging
34
+ Classifier: Development Status :: 3 - Alpha
35
+ Classifier: Intended Audience :: Science/Research
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3.13
44
+ Classifier: Topic :: Scientific/Engineering :: Physics
45
+ Classifier: Topic :: Scientific/Engineering :: Visualization
46
+ Requires-Python: >=3.9
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Requires-Dist: numpy>=1.22
50
+ Requires-Dist: scipy>=1.8
51
+ Requires-Dist: matplotlib>=3.5
52
+ Requires-Dist: tqdm>=4.60
53
+ Provides-Extra: mat73
54
+ Requires-Dist: h5py>=3.0; extra == "mat73"
55
+ Provides-Extra: dev
56
+ Requires-Dist: pytest>=7; extra == "dev"
57
+ Requires-Dist: pytest-cov; extra == "dev"
58
+ Requires-Dist: ruff; extra == "dev"
59
+ Requires-Dist: build; extra == "dev"
60
+ Requires-Dist: twine; extra == "dev"
61
+ Provides-Extra: docs
62
+ Requires-Dist: mkdocs-material; extra == "docs"
63
+ Dynamic: license-file
64
+
65
+ # pyModeFlow
66
+
67
+ [![CI](https://github.com/drmcekwonu/pyModeFlow/actions/workflows/ci.yml/badge.svg)](https://github.com/mcekwonu/pyModeFlow/actions/workflows/ci.yml)
68
+ [![PyPI](https://img.shields.io/pypi/v/pyModeFlow.svg)](https://pypi.org/project/pyModeFlow/)
69
+ [![Python](https://img.shields.io/pypi/pyversions/pyModeFlow.svg)](https://pypi.org/project/pyModeFlow/)
70
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
71
+ <!-- [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24769536.svg)](https://doi.org/10.5281/zenodo.24769536) -->
72
+
73
+ Framework for Modal decompositions of **time-resolved experimental and schlieren data** (u, v or w snapshots), as a Python package
74
+ with command line tools:
75
+
76
+ | Tool | Class | What it does |
77
+ | --- | --- | --- |
78
+ | `snap-pod` | `modeflow.SnapshotPOD` | Snapshot POD by the method of snapshots: spatial modes, time coefficients, energy ratio, PSD of the coefficients, reconstruction |
79
+ | `spod` | `modeflow.SpectralPOD` | Spectral POD with Welch's method after [Schmidt & Colonius (2020)](https://doi.org/10.2514/1.J058809): SPOD energy spectrum with confidence bounds, modes at every frequency |
80
+ | `dmd` | `modeflow.DMD` | Dynamic Mode Decomposition (DMD) of Experimental velocity-field and Image (Qualitative) data: DMD modes, time dynamics, DMD spectra, growth/decay rate and reconstructed data | Algorithm (exact DMD; the hand-written notes, Tu et al. 2014, Brunton & Kutz, PyDMD): A steady (background/mean-flow) component appears as a mode with omega ~ 0. [Brunton & Kutz (2020)](https://doi.org/10.2514/1.J058809):
81
+
82
+ Both tools read the same files, write 2D modes as `(nx, ny)` images and arrays, show `tqdm`
83
+ progress bars, and are tested against independent references (SciPy's Welch estimator, an explicit
84
+ cross-spectral-density eigendecomposition, data with a known answer).
85
+
86
+ ## Installation
87
+
88
+ ```bash
89
+ pip install pymodeflow # from PyPI
90
+ pip install "pymodeflow[mat73]" # + MATLAB v7.3 (.mat, HDF5) support
91
+ pip install git+https://github.com/drmcekwonu/pyModeFlow.git # latest development version
92
+ ```
93
+
94
+ Python >= 3.9; depends on NumPy, SciPy, Matplotlib and tqdm.
95
+
96
+ ## Input data
97
+
98
+ A `.npz` or `.mat` file with the velocity components `U`, `V`, `W` (and/or `Vmag`; names are
99
+ case-insensitive) and, optionally, `dim = [nx, ny]`. Each component is a matrix
100
+
101
+ ```
102
+ X with shape [N, Nt] N = nx * ny flattened grid points (rows)
103
+ Nt time snapshots, dt apart (columns)
104
+ ```
105
+
106
+ so `X[:, k]` is the field at snapshot `k` flattened in **C order** (row-major, NumPy
107
+ `field.reshape(-1)`) or **F order** (column-major, MATLAB `U(:)`, `--order F`). `dim` and the order
108
+ are only used to fold modes back into 2D images. Details: [docs/data-format.md](docs/data-format.md).
109
+
110
+ ```python
111
+ import numpy as np
112
+ np.savez("piv_data.npz", U=U.reshape(nx * ny, nt), dim=[nx, ny]) # U has shape (nx, ny, nt)
113
+ ```
114
+
115
+ > **Note on defaults.** `--order` defaults to `C` in `snap-pod`, `dmd` and `spod`; you can pass it
116
+ > explicitly as `F` when you data is saved using MATLAB's .mat.
117
+
118
+ ## Quick start
119
+
120
+ No data yet? Generate a synthetic set with known tones (5 Hz and 12 Hz):
121
+
122
+ ```bash
123
+ python -m modeflow.synthetic synthetic_data.npz # U: [2400, 5001], dt = 0.002 s
124
+
125
+ python3 -m snap-pod save -i synthetic_data.npz -c U -t 0.002 -o results --order C
126
+ python3 -m spod save -i synthetic_data.npz -c U -t 0.002 -o results --nfft 256
127
+ python3 -m dmd save -i synthetic_data.npz -c U -t 0.002 -o results --order F
128
+ ```
129
+
130
+ Results go to `<output-dir>/<input-file-stem>_<YYYYMMDD>/<component>`, for example
131
+ `results/synthetic_data_20261202/U/`, so runs for different components never overwrite each other.
132
+
133
+ ### snap-pod
134
+
135
+ ```bash
136
+ python3 -m snap-pod save -i piv_data.npz -c U -t 0.001 -o results -m 6 # compute and write everything
137
+ python3 -m snap-pod preview -i piv_data.npz -c V -t 0.001 # show figures, write nothing
138
+ python3 -m snap-pod replot -p results/piv_data_20261202/U/POD_modes.npy -m 4 -o figure
139
+ python3 -m snap-pod reconstruct -p results/piv_data_20261202/U/POD_modes.npy -r 10 # rebuild the data with 10 modes
140
+ ```
141
+
142
+ Writes `POD_modes.npy` `[N, K]`, `POD_coefficients.npy` `[K, Nt]`, `POD_mean.npy`, `eigs_result.csv`,
143
+ `psd_result_mode_<i>.csv`, one image per mode, the energy and PSD figures.
144
+
145
+ ### spod
146
+
147
+ ```bash
148
+ python3 -m spod save -i piv_data.npz -c U -t 0.001 -o results --nfft 512 # 50 % overlap, Hamming window
149
+ python3 -m spod preview -i piv_data.npz -c U -t 0.001 --nfft 256 --window hann
150
+ python3 -m spod replot -p results/piv_data_20261202/U --freqs 1.59 0.238 -m 2 -o modes_selected
151
+ ```
152
+
153
+ Writes `SPOD_spectrum.png` (energy of every mode, PSD, 99 % confidence bounds), `SPOD_low_rank.png`
154
+ (`lambda_1 / sum(lambda)` with the peak frequencies, `f_max` and `f_s`), one `SPOD_mode<k>_f<f>Hz.png`
155
+ per mode, `SPOD_modes.npy` `[n_freq, N, n_modes]`, `SPOD_spectrum.csv/.npz`. Choose `--nfft`, `--novlp`
156
+ and the window with the trade-offs of the paper in mind: [docs/spod.md](docs/spod.md).
157
+
158
+ ### dmd
159
+
160
+ ```bash
161
+ python3 dmd.py save -i piv_data.npz -c U -o ./results -t 0.002 -r 20
162
+ python3 dmd.py save -i piv_data.mat -c W -o ./results -t 0.002 --order F --predict 100
163
+ python3 dmd.py preview -i piv_data.npz -c V -t 0.002 -r 10 --dim 120 80
164
+ python3 dmd.py reconstruct -p ./results/piv_data_20261128/U -r 4
165
+ python3 dmd.py reconstruct -p ./results/piv_data_20261128/U --fmin 4.5 --fmax 5.5 --predict 50
166
+ python3 dmd.py reconstruct -p ./results/piv_data_20261128/U --part background
167
+ ```
168
+
169
+ Writes DMD modes in `DMD_modes.npy` `[N, r]` and saves `DMD_mode_<i>.png` `(2D, shape (nx, ny))`,
170
+ Dynamics `DMD_dynamics.npy` `(b * exp(omega * t)` and saves `DMD_dynamics.png`,
171
+ DMD spectra `DMD_eigenvalues.png` `(lambda plane)` and `DMD_omega.png` `(omega plane)` and `DMD_spectrum.png` (amplitude vs frequency)`
172
+ Growth/decay rate `Re(omega) [1/s] and frequency Im(omega)/(2 pi) [Hz]` in `DMD_eigenvalues.csv` and `DMD_spectrum.npz`
173
+ Reconstructed data in `DMD_reconstructed.npy [N, Nt (+ predicted)]`: [docs/dmd.md](docs/dmd.md).
174
+
175
+
176
+ ### Python API
177
+
178
+ ```python
179
+ from modeflow import SnapshotPOD, SpectralPOD, DMD
180
+
181
+ pod = SnapshotPOD("piv_data.npz", dt=1e-3, component="U", num_modes=6, order="C")
182
+ pod.compute() # pod.modes, pod.coeffs, pod.s, pod.r (optimal rank)
183
+
184
+ spod = SpectralPOD("piv_data.npz", dt=1e-3, nfft=512, num_modes=4, order="C")
185
+ spod.compute() # spod.freq, spod.lam (n_freq, N_blk), spod.modes (n_freq, N, n_modes)
186
+
187
+ dmd = DMD("piv_data.npz", dt=1e-3, component="U", rank=6, order="C")
188
+ dmd.compute() # dmd.modes, dmd.dynamics, dmd.growth-rate
189
+ ```
190
+
191
+ See [docs/api.md](docs/api.md) and `examples/quickstart.py`.
192
+
193
+ ## Citing
194
+
195
+ If `pyModeFlow` contributes to a publication, please cite the software (GitHub shows a *Cite this
196
+ repository* button from [`CITATION.cff`](CITATION.cff); a Zenodo DOI is minted for every release) **and**
197
+ the papers that describe the methods:
198
+
199
+ ```bibtex
200
+ @software{pyModeFlow,
201
+ author = {Ekwonu, Michael Chukwuemeka},
202
+ title = {pyModeFlow: pyModeFlow: Snapshot Proper Orthogonal Decompostion (snapPOD), Spectral Proper Orthogonal Decomposition (SPOD) and Dynamic Mode Decomposition (DMD) of time-resolved experimental and schlieren image data},
203
+ year = {2026},
204
+ version = {0.1.0},
205
+ url = {https://github.com/drmcekwonu/pyModeFlow}
206
+ }
207
+
208
+ @article{SchmidtColonius2020,
209
+ author = {Schmidt, Oliver T. and Colonius, Tim},
210
+ title = {Guide to Spectral Proper Orthogonal Decomposition},
211
+ journal = {AIAA Journal},
212
+ volume = {58}, number = {3}, pages = {1023--1033}, year = {2020},
213
+ doi = {10.2514/1.J058809}
214
+ }
215
+ ```
216
+
217
+ Related references (Welch 1967, Towne et al. 2018, Sirovich 1987) are listed in
218
+ [docs/citing.md](docs/citing.md).
219
+
220
+ ## Development, releases and roadmap
221
+
222
+ - Contributing and tests: [CONTRIBUTING.md](CONTRIBUTING.md) (`pip install -e ".[dev]"`, `pytest`)
223
+ - Versions come from git tags (`v0.2.0`); how to release: [docs/releasing.md](docs/releasing.md)
224
+ - Changes: [CHANGELOG.md](CHANGELOG.md); ideas for future development: [docs/roadmap.md](docs/roadmap.md)
225
+
226
+ ## License
227
+
228
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,15 @@
1
+ modeflow/__init__.py,sha256=CVAgnrPcLto8iw3Mmv6czXL-nBGjoxKCxNXA0lekjSM,1292
2
+ modeflow/__main__.py,sha256=XaVoB7X1yngDhlBtGKCbMx50nIo_dIuRR46nJK_2w0g,406
3
+ modeflow/_common.py,sha256=8AMh06M3eH2ATi-g5eDQEMVvQUdQ_0gbgj6T2Xo_Egg,5649
4
+ modeflow/_version.py,sha256=Q6ScJXlkBsUI-cazSvpYPMyIVUB-Vd0R3pq3_rM1wmI,520
5
+ modeflow/dmd.py,sha256=1Jbc8dHRQcgyHQerHuR8iRENYh8LQi7vrc_J3rajDuQ,32270
6
+ modeflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ modeflow/snap_pod.py,sha256=UivqBFXIEtvEPFja2P0teTfgJJqMz6JQCAGIdzyxPDU,29268
8
+ modeflow/spod.py,sha256=lxVp0Z_ggioh0MEud-ApyPLeoW8aEtDfR7snCVLtj-4,36706
9
+ modeflow/synthetic.py,sha256=Z4KygGppYUGblBd-HE-YyGKgGbLpgUxwaP4iqZB5pM8,3512
10
+ pymodeflow-0.1.2.dist-info/licenses/LICENSE,sha256=IZelyUuZz4V_8xgGX2Lb9FtmmaUrpGa6NANsnWE4_s4,1083
11
+ pymodeflow-0.1.2.dist-info/METADATA,sha256=97sOC0CgBRJtt49cvPLS6rhwtYvFi_0aKTEpS05yu5s,11360
12
+ pymodeflow-0.1.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
13
+ pymodeflow-0.1.2.dist-info/entry_points.txt,sha256=bY53NliAsioPDg1mTmwDbSwCqKHc5gg0etGSMk6lK3o,102
14
+ pymodeflow-0.1.2.dist-info/top_level.txt,sha256=RW3nou1U3cotBsw9rXUsbzfw1ZXPh7xOA-bmOfvvEQw,9
15
+ pymodeflow-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ dmd = modeflow.dmd:main
3
+ snap-pod = modeflow.snap_pod:main
4
+ spod = modeflow.spod:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ekwonu Michael Chukwuemeka
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ modeflow