modulo-vki 2.1.2__py3-none-any.whl → 2.1.4__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.
modulo_vki/modulo.py CHANGED
@@ -131,6 +131,9 @@ class ModuloVKI:
131
131
 
132
132
  if self.MEMORY_SAVING:
133
133
  os.makedirs(self.FOLDER_OUT, exist_ok=True)
134
+
135
+ if data is not None:
136
+ raise ValueError("The memory saving option is active, so MODULO cannot be initialized with the full snapshot matrix. Use 'ReadData' routines to process the data in chunks instead.")
134
137
 
135
138
  # Load the data matrix
136
139
  if isinstance(data, np.ndarray):
@@ -53,7 +53,7 @@ def Plot_Field_TEXT_JET(File):
53
53
  ax.set_xlim([0, 35])
54
54
  ax.set_ylim(10, 29)
55
55
  ax.invert_yaxis() # Invert Axis for plotting purpose
56
- plt.show()
56
+ # plt.show()
57
57
  Name[len(Name) - 12:len(Name)] + ' Plotted'
58
58
  return n_s, Xg, Yg, Vxg, -Vyg, X_S, Y_S
59
59
 
@@ -1,313 +1,356 @@
1
- Metadata-Version: 2.4
2
- Name: modulo_vki
3
- Version: 2.1.2
4
- Summary: MODULO (MODal mULtiscale pOd) is a software developed at the von Karman Institute to perform Multiscale Modal Analysis of numerical and experimental data.
5
- Home-page: https://github.com/mendezVKI/MODULO/tree/master/modulo_python_package/
6
- Author: ['R. Poletti', 'L. Schena', 'D. Ninni', 'M. A. Mendez']
7
- Author-email: mendez@vki.ac.be
8
- License: BSD (3-clause)
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Natural Language :: English
11
- Classifier: Programming Language :: Python :: 3
12
- Requires-Python: >=3.6
13
- Description-Content-Type: text/x-rst
14
- License-File: LICENSE
15
- Requires-Dist: tqdm
16
- Requires-Dist: numpy
17
- Requires-Dist: scipy
18
- Requires-Dist: scikit-learn
19
- Requires-Dist: ipykernel
20
- Requires-Dist: ipython
21
- Requires-Dist: ipython-genutils
22
- Requires-Dist: ipywidgets
23
- Requires-Dist: matplotlib
24
- Dynamic: author
25
- Dynamic: author-email
26
- Dynamic: classifier
27
- Dynamic: description
28
- Dynamic: description-content-type
29
- Dynamic: home-page
30
- Dynamic: license
31
- Dynamic: license-file
32
- Dynamic: requires-dist
33
- Dynamic: requires-python
34
- Dynamic: summary
35
-
36
- MODULO: a python toolbox for data-driven modal decomposition
37
- ------------------------------------------------------------
38
-
39
- .. image:: https://modulo.readthedocs.io/en/latest/_images/modulo_logo.png
40
- :alt: MODULO logo
41
- :width: 500px
42
- :align: center
43
-
44
-
45
- **MODULO** is a modal decomposition package developed at the von Karman Institute for Fluid Dynamics (VKI). It offers a wide range of decomposition techniques, allowing users to choose the most appropriate method for their specific problem. MODULO can efficiently handle large datasets natively, thanks to a memory-saving feature that partitions the data and processes the decomposition in chunks (`Nini et al. (2022) <https://www.sciencedirect.com/science/article/pii/S2352711020303356>`_). Moreover, it supports non-uniform meshes through a weighted inner product formulation. Currently, MODULO heavily relies on NumPy routines and does not offer additional parallel computing capabilities beyond those naturally provided by NumPy.
46
-
47
- While the discontinued MATLAB version of MODULO is accessible in the “Old_Matlab_Implementation” branch,
48
- it is no longer maintained. The latest decomposition techniques are exclusively available in the current Python version (`Poletti et al. (2024) <https://joss.theoj.org/papers/10.21105/joss.06753>`_).
49
-
50
- As a part of the MODULO project, we provide a series of lectures on data-driven modal decomposition, and its applications.
51
- These are available at the `MODULO YouTube channel <https://www.youtube.com/@modulompod5682>`_.
52
-
53
- .. contents:: Table of contents
54
-
55
- Modal decompositions
56
- --------------------
57
- Modal decompositions aim to describe the data as a linear combination of *modes*, obtained by projecting the data
58
- onto a suitable set of basis. Different decompositions employ different bases, such as prescribed Fourier basis for
59
- the Discrete Fourier Transform (DFT), or data-driven basis, i.e. tailored on the dataset at hand,
60
- for the Proper Orthogonal Decomposition (POD). We refer to `Mendez (2022) <https://doi.org/10.48550/arXiv.2201.03847>`_, `Mendez (2023) <https://doi.org/10.1017/9781108896214.013>`_, and `Mendez et al. (2023) <https://arxiv.org/abs/2208.07746>`_ for an introduction to the topic.
61
- MODULO currently features the following decompositions:
62
-
63
- - Discrete Fourier Transform (DFT) (`Briggs et al. (1997) <https://epubs.siam.org/doi/book/10.1137/1.9781611971514>`_)
64
- - Proper Orthogonal Decomposition (POD) (`Sirovich et al. (1987) <https://www.ams.org/journals/qam/1987-45-03/S0033-569X-1987-0910464-1/S0033-569X-1987-0910464-1.pdf>`_ , `Berkooz et al. (1993) <https://doi.org/10.1146/annurev.fl.25.010193.002543>`_)
65
- - Multi-Scale Proper Orthogonal Decomposition (mPOD) (`Mendez et al. (2019) <https://arxiv.org/abs/1804.09646>`_)
66
- - Dynamic Mode Decomposition (DMD) (`Schmid (2010) <https://doi.org/10.1017/S0022112010001217>`_)
67
- - Spectral Proper Orthogonal Decomposition (SPOD) (`Sieber et al. (2016) <https://doi.org/10.48550/arXiv.1508.04642>`_, `Towne et al. (2018) <https://doi.org/10.48550/arXiv.1708.04393>`_),
68
- note that the two are different formulations, and both are available in MODULO.
69
- - Kernel Proper Orthogonal Decomposition (KPOD) (`Mika et al. (1998) <https://proceedings.neurips.cc/paper_files/paper/1998/file/226d1f15ecd35f784d2a20c3ecf56d7f-Paper.pdf>`_)
70
-
71
- We remind the curious reader to the respective references for a detailed description of each decomposition, and to the
72
- documentation for a practical guide on how to use them in MODULO.
73
-
74
- Release Notes
75
- -------------
76
- This version of MODULO includes the following updates:
77
-
78
- 1. **mPOD bug fix:** the previous version of mPOD was skipping the last scale of the frequency splitting vector. Fixed in this version.
79
-
80
- 2. **SPOD parallelisation:** CSD - SPOD can now be parallelized, leveraging `joblib`. The user needs just to pass the argument `n_processes` for the computation to be
81
- split between different workers.
82
-
83
- 3. **Simplified decomposition interface:** the interface of the decomposition methods has been simplified to improve user experience.
84
-
85
- 4. **Enhanced POD selection:** the POD function has been redesigned, allowing users to easily choose between different POD methods.
86
-
87
- 5. **Improved computational efficiency:** the code of the decomposition functions has been optimised, resulting in reduced computation time. mPOD now includes two additional optional arguments to enable faster filtering and to avoid recomputing the Sigmas after QR polishing.
88
-
89
- 6. **Extended documentation:** the documentation has been significantly enriched, now including theoretical foundations for all the supported modal decomposition techniques.
90
-
91
-
92
- Documentation
93
- -------------
94
-
95
- The documentation of MODULO is available `here <https://lorenzoschena.github.io/MODULO/intro.html>`_. It
96
- contains a comprehensive guide on how to install and use the package, as well as a detailed description of the
97
- decompositions required inputs and outputs. A `list of YouTube videos <https://www.youtube.com/@modulompod5682>`_
98
- is also available to guide the introduce the user to modal decomposition and MODULO.
99
-
100
- Installation
101
- -------------
102
-
103
- Installation via pip
104
- ^^^^^^^^^^^^^^^^^^^^
105
-
106
- You can access the latest update of the modulo python package on PyPI using the command line:
107
-
108
- .. code-block:: bash
109
-
110
- $ pip install modulo_vki
111
-
112
- Installation from source
113
- ^^^^^^^^^^^^^^^^^^^^^^^^
114
-
115
- Alternatively, you can clone the repository and install the package locally:
116
-
117
- .. code-block:: bash
118
-
119
- $ git clone https://github.com/mendezVKI/MODULO.git
120
-
121
- $ cd MODULO
122
-
123
- $ python setup.py install
124
-
125
- or, if you have pip installed in your environment,
126
-
127
- .. code-block:: bash
128
-
129
- $ pip install .
130
-
131
-
132
- Example
133
- -------------
134
-
135
- Example 1: POD decomposition
136
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137
-
138
- The following example illustrates how to decompose a data set (D) using the POD decomposition.
139
-
140
- .. code-block:: python
141
-
142
- from modulo_vki import ModuloVKI
143
- import numpy as np
144
-
145
- # Create a random dataset
146
- D = np.random.rand(100, 1000)
147
-
148
- # Initialize the ModuloVKI object
149
- m = ModuloVKI(D)
150
-
151
- # Compute the POD decomposition
152
- phi_POD, Sigma_POD, psi_POD = m.POD()
153
-
154
- which returns the spatial basis ($\phi$), the temporal basis ($\psi$), and the modal
155
- amplitudes ($\Sigma$) of the POD decomposition.
156
-
157
- Example 2: Memory Saving option
158
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159
-
160
- For the Memory Saving option, MODULO decomposes $D$ in `N_partitions`, defined
161
- by the user (refer to `examples/ex_04_Memory_Saving.py`).
162
-
163
- .. code-block:: python
164
-
165
- from modulo_vki import ModuloVKI
166
- import numpy as np
167
-
168
- # Create a random dataset
169
- D = np.random.rand(100, 1000)
170
-
171
- # Initialize the ModuloVKI object
172
- m = ModuloVKI(D, N_PARTITIONS=10)
173
-
174
- # Compute the POD decomposition
175
- phi_POD, Sigma_POD, psi_POD = m.POD()
176
-
177
- Example 3: non-uniform grid
178
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179
-
180
- If you are dealing with non-uniform grid (e.g. output of a Computational Fluid Dynamic (CFD) simulation),
181
- you can use the weighted inner product formulation (refer to `examples/ex_05_nonUniform_POD.py`).
182
-
183
- .. code-block:: python
184
-
185
- from modulo_vki import ModuloVKI
186
- import numpy as np
187
-
188
- # Create a random dataset
189
- D = np.random.rand(100, 1000)
190
-
191
- # Get the area of the grid
192
- a_dataSet = gridData.compute_cell_sizes()
193
- area = a_dataSet['Area']
194
-
195
- # Compute weights
196
- areaTot = np.sum(area)
197
- weights = area/areaTot # sum should be equal to 1
198
-
199
- # Initialize the ModuloVKI object
200
- m = ModuloVKI(D, weights=weights)
201
-
202
- # Compute the POD decomposition
203
- phi_POD, Sigma_POD, psi_POD = m.POD()
204
-
205
- Community guidelines
206
- ---------------------
207
-
208
- Contributing to MODULO
209
- ^^^^^^^^^^^^^^^^^^^^^^^
210
- We welcome contributions to MODULO.
211
-
212
- It is recommended to perform a shallow clone of the repository to avoid downloading the entire history of the project:
213
-
214
- .. code-block:: bash
215
-
216
- $ git clone --depth 1 https://github.com/mendezVKI/MODULO.git
217
-
218
- This will download only the latest version of the repository, which is sufficient for contributing to the project, and will save
219
- you time and disk space.
220
-
221
- To create a new feature, please submit a pull request, specifying the proposed changes and
222
- providing an example of how to use the new feature (that will be included in the `examples/` folder).
223
-
224
- The pull request will be reviewed by the MODULO team before being merged into the main branch, and your contribution duly acknowledged.
225
-
226
- Report bugs
227
- ^^^^^^^^^^^^
228
- If you find a bug, or you encounter unexpected behaviour, please open an issue on the MODULO GitHub repository.
229
-
230
- Ask for help
231
- ^^^^^^^^^^^^
232
- If you have troubles using MODULO, or you need help with a specific decomposition, please open an issue on the MODULO GitHub repository.
233
-
234
- Citation
235
- --------
236
-
237
- If you use MODULO in your research, please cite it as follows:
238
-
239
- Poletti, R., Schena, L., Ninni, D., Mendez, M. A. (2024).
240
- *MODULO: A Python toolbox for data-driven modal decomposition*.
241
- Journal of Open Source Software, 9(102), 6753. https://doi.org/10.21105/joss.06753
242
-
243
- .. code-block:: text
244
-
245
- @article{Poletti2024,
246
- doi = {10.21105/joss.06753},
247
- url = {https://doi.org/10.21105/joss.06753},
248
- year = {2024},
249
- publisher = {The Open Journal},
250
- volume = {9},
251
- number = {102},
252
- pages = {6753},
253
- author = {R. Poletti and L. Schena and D. Ninni and M. A. Mendez},
254
- title = {MODULO: A Python toolbox for data-driven modal decomposition},
255
- journal = {Journal of Open Source Software}
256
- }
257
-
258
- and
259
-
260
- Ninni, D., & Mendez, M. A. (2020).
261
- *MODULO: A software for Multiscale Proper Orthogonal Decomposition of data*.
262
- SoftwareX, 12, 100622. https://doi.org/10.1016/j.softx.2020.100622
263
-
264
- .. code-block:: text
265
-
266
- @article{ninni2020modulo,
267
- title={MODULO: A software for Multiscale Proper Orthogonal Decomposition of data},
268
- author={Ninni, Davide and Mendez, Miguel A},
269
- journal={SoftwareX},
270
- volume={12},
271
- pages={100622},
272
- year={2020},
273
- publisher={Elsevier}
274
- }
275
-
276
-
277
- References
278
- ----------
279
-
280
- - Mendez, Miguel Alfonso. "Statistical Treatment, Fourier and Modal Decomposition." arXiv preprint arXiv:2201.03847 (2022).
281
- - Mendez, M. A. (2023) "Generalized and Multiscale Modal Analysis". In : Mendez M.A., Ianiro, A., Noack, B.R., Brunton, S. L. (Eds),
282
- "Data-Driven Fluid Mechanics: Combining First Principles and Machine Learning". Cambridge University Press, 2023:153-181.
283
- https://doi.org/10.1017/9781108896214.013. The pre-print is available at https://arxiv.org/abs/2208.12630.
284
- - Ninni, Davide, and Miguel A. Mendez. "MODULO: A software for Multiscale Proper Orthogonal Decomposition of data." SoftwareX 12 (2020): 100622.
285
- - Poletti, Romain, Schena, Lorenzo, Ninni, David, and Mendez, Miguel A. "Modulo: A python toolbox for data-driven modal decomposition". Journal of Open Source Software (2024), 9(102), 6753.
286
- - Mendez, Miguel A. "Linear and nonlinear dimensionality reduction from fluid mechanics to machine learning." Measurement Science and Technology 34.4 (2023): 042001.
287
- - Briggs, William L., and Van Emden Henson. The DFT: an owner's manual for the discrete Fourier transform. Society for Industrial and Applied Mathematics, 1995.
288
- - Berkooz, Gal, Philip Holmes, and John L. Lumley. "The proper orthogonal decomposition in the analysis of turbulent flows." Annual review of fluid mechanics 25.1 (1993): 539-575.
289
- - Sirovich, Lawrence. "Turbulence and the dynamics of coherent structures. III. Dynamics and scaling." Quarterly of Applied mathematics 45.3 (1987): 583-590.
290
- - Mendez, M. A., M. Balabane, and J-M. Buchlin. "Multi-scale proper orthogonal decomposition of complex fluid flows." Journal of Fluid Mechanics 870 (2019): 988-1036.
291
- - Schmid, Peter J. "Dynamic mode decomposition of numerical and experimental data." Journal of fluid mechanics 656 (2010): 5-28.
292
- - Sieber, Moritz, C. Oliver Paschereit, and Kilian Oberleithner. "Spectral proper orthogonal decomposition." Journal of Fluid Mechanics 792 (2016): 798-828.
293
- - Towne, Aaron, Oliver T. Schmidt, and Tim Colonius. "Spectral proper orthogonal decomposition and its relationship to dynamic mode decomposition and resolvent analysis." Journal of Fluid Mechanics 847 (2018): 821-867.
294
- - Mika, Sebastian, et al. "Kernel PCA and de-noising in feature spaces." Advances in neural information processing systems 11 (1998).
295
-
296
- Related projects
297
- ----------------
298
- MODULO encapsulates a wide range of decomposition techniques, but not all of them. We refer to the project below for an additional set of decomposition techniques:
299
-
300
- - ModRed, https://github.com/belson17/modred
301
-
302
- There are also decomposition-specific projects, some of which are listed below:
303
-
304
- - Rogowski, Marcin, Brandon CY Yeung, Oliver T. Schmidt, Romit Maulik, Lisandro Dalcin, Matteo Parsani, and Gianmarco Mengaldo. "Unlocking massively parallel spectral proper orthogonal decompositions in the PySPOD package." Computer Physics Communications 302 (2024): 109246.
305
- - Lario, A., Maulik, R., Schmidt, O.T., Rozza, G. and Mengaldo, G., 2022. Neural-network learning of SPOD latent dynamics. Journal of Computational Physics, 468, p.111475.
306
- - Ichinaga, Andreuzzi, Demo, Tezzele, Lapo, Rozza, Brunton, Kutz. PyDMD: A Python package for robust dynamic mode decomposition. arXiv preprint, 2024.
307
- - Rogowski, Marcin, et al. "Unlocking massively parallel spectral proper orthogonal decompositions in the PySPOD package." Computer Physics Communications 302 (2024): 109246.
308
-
309
-
310
-
311
-
312
-
313
-
1
+ Metadata-Version: 2.4
2
+ Name: modulo_vki
3
+ Version: 2.1.4
4
+ Summary: MODULO (MODal mULtiscale pOd) is a software developed at the von Karman Institute to perform Multiscale Modal Analysis of numerical and experimental data.
5
+ Home-page: https://github.com/mendezVKI/MODULO/tree/master/modulo_python_package/
6
+ Author: ['R. Poletti', 'L. Schena', 'D. Ninni', 'M. A. Mendez']
7
+ Author-email: mendez@vki.ac.be
8
+ License: BSD (3-clause)
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Natural Language :: English
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/x-rst
14
+ License-File: LICENSE
15
+ Requires-Dist: tqdm
16
+ Requires-Dist: numpy
17
+ Requires-Dist: scipy
18
+ Requires-Dist: scikit-learn
19
+ Requires-Dist: ipykernel
20
+ Requires-Dist: ipython
21
+ Requires-Dist: ipython-genutils
22
+ Requires-Dist: ipywidgets
23
+ Requires-Dist: matplotlib
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: license
31
+ Dynamic: license-file
32
+ Dynamic: requires-dist
33
+ Dynamic: requires-python
34
+ Dynamic: summary
35
+
36
+ MODULO: a python toolbox for data-driven modal decomposition
37
+ -------------------------------------------------------------
38
+
39
+ .. image:: https://modulo.readthedocs.io/en/latest/_images/modulo_logo.png
40
+ :alt: MODULO logo
41
+ :width: 500px
42
+ :align: center
43
+
44
+
45
+ **MODULO** is a modal decomposition package developed at the von Karman Institute for Fluid Dynamics (VKI). It offers a wide range of decomposition techniques, allowing users to choose the most appropriate method for their specific problem. MODULO can efficiently handle large datasets natively, thanks to a memory-saving feature that partitions the data and processes the decomposition in chunks (`Nini et al. (2022) <https://www.sciencedirect.com/science/article/pii/S2352711020303356>`_). Moreover, it supports non-uniform meshes through a weighted inner product formulation. Currently, MODULO heavily relies on NumPy routines and does not offer additional parallel computing capabilities beyond those naturally provided by NumPy.
46
+
47
+ While the discontinued MATLAB version of MODULO is accessible in the “Old_Matlab_Implementation” branch,
48
+ it is no longer maintained. The latest decomposition techniques are exclusively available in the current Python version (`Poletti et al. (2024) <https://joss.theoj.org/papers/10.21105/joss.06753>`_).
49
+
50
+ As a part of the MODULO project, we provide a series of lectures on data-driven modal decomposition, and its applications.
51
+ These are available at the `MODULO YouTube channel <https://www.youtube.com/@modulompod5682>`_.
52
+
53
+ .. contents:: Table of contents
54
+
55
+ Modal decompositions
56
+ --------------------
57
+ Modal decompositions aim to describe the data as a linear combination of *modes*, obtained by projecting the data
58
+ onto a suitable set of basis. Different decompositions employ different bases, such as prescribed Fourier basis for
59
+ the Discrete Fourier Transform (DFT), or data-driven basis, i.e. tailored on the dataset at hand,
60
+ for the Proper Orthogonal Decomposition (POD). We refer to `Mendez (2022) <https://doi.org/10.48550/arXiv.2201.03847>`_, `Mendez (2023) <https://doi.org/10.1017/9781108896214.013>`_, and `Mendez et al. (2023) <https://arxiv.org/abs/2208.07746>`_ for an introduction to the topic.
61
+ MODULO currently features the following decompositions:
62
+
63
+ - Discrete Fourier Transform (DFT) (`Briggs et al. (1997) <https://epubs.siam.org/doi/book/10.1137/1.9781611971514>`_)
64
+ - Proper Orthogonal Decomposition (POD) (`Sirovich et al. (1987) <https://www.ams.org/journals/qam/1987-45-03/S0033-569X-1987-0910464-1/S0033-569X-1987-0910464-1.pdf>`_ , `Berkooz et al. (1993) <https://doi.org/10.1146/annurev.fl.25.010193.002543>`_)
65
+ - Multi-Scale Proper Orthogonal Decomposition (mPOD) (`Mendez et al. (2019) <https://arxiv.org/abs/1804.09646>`_)
66
+ - Dynamic Mode Decomposition (DMD) (`Schmid (2010) <https://doi.org/10.1017/S0022112010001217>`_)
67
+ - Spectral Proper Orthogonal Decomposition (SPOD) (`Sieber et al. (2016) <https://doi.org/10.48550/arXiv.1508.04642>`_, `Towne et al. (2018) <https://doi.org/10.48550/arXiv.1708.04393>`_),
68
+ note that the two are different formulations, and both are available in MODULO.
69
+ - Kernel Proper Orthogonal Decomposition (KPOD) (`Mika et al. (1998) <https://proceedings.neurips.cc/paper_files/paper/1998/file/226d1f15ecd35f784d2a20c3ecf56d7f-Paper.pdf>`_)
70
+
71
+ We remind the curious reader to the respective references for a detailed description of each decomposition, and to the
72
+ documentation for a practical guide on how to use them in MODULO.
73
+
74
+ Release Notes
75
+ -------------
76
+ This version of MODULO includes the following updates:
77
+
78
+ 1. **mPOD bug fix:** the previous version of mPOD was skipping the last scale of the frequency splitting vector. Fixed in this version.
79
+
80
+ 2. **SPOD parallelisation:** CSD - SPOD can now be parallelized, leveraging `joblib`. The user needs just to pass the argument `n_processes` for the computation to be
81
+ split between different workers.
82
+
83
+ 3. **Simplified decomposition interface:** the interface of the decomposition methods has been simplified to improve user experience.
84
+
85
+ 4. **Enhanced POD selection:** the POD function has been redesigned, allowing users to easily choose between different POD methods.
86
+
87
+ 5. **Improved computational efficiency:** the code of the decomposition functions has been optimised, resulting in reduced computation time. mPOD now includes two additional optional arguments to enable faster filtering and to avoid recomputing the Sigmas after QR polishing.
88
+
89
+ 6. **Extended documentation:** the documentation has been significantly enriched, now including theoretical foundations for all the supported modal decomposition techniques.
90
+
91
+
92
+ Documentation
93
+ -------------
94
+
95
+ The documentation of MODULO is available `here <https://lorenzoschena.github.io/MODULO/intro.html>`_. It
96
+ contains a comprehensive guide on how to install and use the package, as well as a detailed description of the
97
+ decompositions required inputs and outputs. A `list of YouTube videos <https://www.youtube.com/@modulompod5682>`_
98
+ is also available to guide the introduce the user to modal decomposition and MODULO.
99
+
100
+ Installation
101
+ -------------
102
+
103
+ Installation via pip
104
+ ^^^^^^^^^^^^^^^^^^^^
105
+
106
+ You can access the latest update of the modulo python package on PyPI using the command line:
107
+
108
+ .. code-block:: bash
109
+
110
+ $ pip install modulo_vki
111
+
112
+ Installation from source
113
+ ^^^^^^^^^^^^^^^^^^^^^^^^
114
+
115
+ Alternatively, you can clone the repository and install the package locally:
116
+
117
+ .. code-block:: bash
118
+
119
+ $ git clone https://github.com/mendezVKI/MODULO.git
120
+
121
+ $ cd MODULO
122
+
123
+ $ python setup.py install
124
+
125
+ or, if you have pip installed in your environment,
126
+
127
+ .. code-block:: bash
128
+
129
+ $ pip install .
130
+
131
+
132
+ Example
133
+ -------------
134
+
135
+ Example 1: POD decomposition
136
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137
+
138
+ The following example illustrates how to decompose a data set (D) using the POD decomposition.
139
+
140
+ .. code-block:: python
141
+
142
+ from modulo_vki import ModuloVKI
143
+ import numpy as np
144
+
145
+ # Create a random dataset
146
+ D = np.random.rand(100, 1000)
147
+
148
+ # Initialize the ModuloVKI object
149
+ m = ModuloVKI(D)
150
+
151
+ # Compute the POD decomposition
152
+ phi_POD, Sigma_POD, psi_POD = m.POD()
153
+
154
+ which returns the spatial basis ($\phi$), the temporal basis ($\psi$), and the modal
155
+ amplitudes ($\Sigma$) of the POD decomposition.
156
+
157
+ Example 2: Memory Saving option
158
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159
+
160
+ For the Memory Saving option, MODULO decomposes $D$ in `N_partitions`, defined
161
+ by the user (refer to `examples/ex_04_Memory_Saving.py`).
162
+
163
+ .. code-block:: python
164
+
165
+ import os
166
+ import numpy as np
167
+ from modulo_vki import ModuloVKI
168
+ from modulo_vki.utils.read_db import ReadData
169
+
170
+ # --- 1. User-defined settings ---
171
+ # Define the path to your data and the file naming convention.
172
+ FOLDER = 'path/to/your/snapshot_data'
173
+ FILE_ROOT_NAME = 'Res' # The base name, e.g., 'Res' for 'Res00001.dat'
174
+ n_t = 100 # The total number of snapshots (time steps) to process.
175
+
176
+ # --- 2. Data format parameters ---
177
+ # Specify how to read your text-based snapshot files.
178
+ H = 1 # H: Number of header lines to skip
179
+ F = 0 # F: Number of footer lines to skip
180
+ C = 0 # C: Number of initial columns to skip
181
+
182
+ # --- 3. Determine data dimensions from a sample file ---
183
+ # To understand the structure, we load the first snapshot.
184
+ first_snapshot_file = os.path.join(FOLDER, f"{FILE_ROOT_NAME}00001.dat")
185
+ Dat = np.genfromtxt(first_snapshot_file, skip_header=H, skip_footer=F)
186
+
187
+ # N: Number of components per point (e.g., 2 for 2D velocity u,v)
188
+ N = Dat.shape[1]
189
+ # nxny: Number of spatial points in the mesh
190
+ nxny = Dat.shape[0]
191
+ # N_T: Total number of snapshots (aliased from n_t for clarity)
192
+ N_T = n_t
193
+
194
+ # --- 4. Process the dataset into partitions on disk ---
195
+ # The ReadData utility reads all snapshots and chunks the snapshot matrix.
196
+
197
+ D = ReadData._data_processing(
198
+ D=None, # We start with no data in memory
199
+ FOLDER_IN=FOLDER,
200
+ filename=f'{FILE_ROOT_NAME}%05d', # File pattern for snapshot files
201
+ N=N, # Number of components per point
202
+ N_S=N * nxny, # Total size of a single snapshot vector
203
+ N_T=N_T, # Total number of snapshots
204
+ h=H, f=F, c=C, # Header, footer, and column skip parameters
205
+ N_PARTITIONS=10, # The dataset will be split into 10 chunks
206
+ MR=False, # Mean-removal flag
207
+ FOLDER_OUT=os.path.join('.', 'MODULO_tmp') # Where to save temp files
208
+ )
209
+
210
+ # --- 5. Initialize ModuloVKI and compute the POD ---
211
+ # Initialize the object, passing the number of partitions. D must be set to None
212
+ # MODULO will look for the partitions in FOLDER_OUT/MODULO_tmp
213
+ m = ModuloVKI(None, N_PARTITIONS=10, FOLDER_OUT=FOLDER_OUT)
214
+
215
+ # The POD method will now automatically read the data from the partitioned files.
216
+ phi_POD, Sigma_POD, psi_POD = m.POD()
217
+
218
+ print("POD computation complete.")
219
+
220
+ Example 3: non-uniform grid
221
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
222
+
223
+ If you are dealing with non-uniform grid (e.g. output of a Computational Fluid Dynamic (CFD) simulation),
224
+ you can use the weighted inner product formulation (refer to `examples/ex_05_nonUniform_POD.py`).
225
+
226
+ .. code-block:: python
227
+
228
+ from modulo_vki import ModuloVKI
229
+ import numpy as np
230
+
231
+ # Create a random dataset
232
+ D = np.random.rand(100, 1000)
233
+
234
+ # Get the area of the grid
235
+ a_dataSet = gridData.compute_cell_sizes()
236
+ area = a_dataSet['Area']
237
+
238
+ # Compute weights
239
+ areaTot = np.sum(area)
240
+ weights = area/areaTot # sum should be equal to 1
241
+
242
+ # Initialize the ModuloVKI object
243
+ m = ModuloVKI(D, weights=weights)
244
+
245
+ # Compute the POD decomposition
246
+ phi_POD, Sigma_POD, psi_POD = m.POD()
247
+
248
+ Community guidelines
249
+ ---------------------
250
+
251
+ Contributing to MODULO
252
+ ^^^^^^^^^^^^^^^^^^^^^^^
253
+ We welcome contributions to MODULO.
254
+
255
+ It is recommended to perform a shallow clone of the repository to avoid downloading the entire history of the project:
256
+
257
+ .. code-block:: bash
258
+
259
+ $ git clone --depth 1 https://github.com/mendezVKI/MODULO.git
260
+
261
+ This will download only the latest version of the repository, which is sufficient for contributing to the project, and will save
262
+ you time and disk space.
263
+
264
+ To create a new feature, please submit a pull request, specifying the proposed changes and
265
+ providing an example of how to use the new feature (that will be included in the `examples/` folder).
266
+
267
+ The pull request will be reviewed by the MODULO team before being merged into the main branch, and your contribution duly acknowledged.
268
+
269
+ Report bugs
270
+ ^^^^^^^^^^^^
271
+ If you find a bug, or you encounter unexpected behaviour, please open an issue on the MODULO GitHub repository.
272
+
273
+ Ask for help
274
+ ^^^^^^^^^^^^
275
+ If you have troubles using MODULO, or you need help with a specific decomposition, please open an issue on the MODULO GitHub repository.
276
+
277
+ Citation
278
+ --------
279
+
280
+ If you use MODULO in your research, please cite it as follows:
281
+
282
+ Poletti, R., Schena, L., Ninni, D., Mendez, M. A. (2024).
283
+ *MODULO: A Python toolbox for data-driven modal decomposition*.
284
+ Journal of Open Source Software, 9(102), 6753. https://doi.org/10.21105/joss.06753
285
+
286
+ .. code-block:: text
287
+
288
+ @article{Poletti2024,
289
+ doi = {10.21105/joss.06753},
290
+ url = {https://doi.org/10.21105/joss.06753},
291
+ year = {2024},
292
+ publisher = {The Open Journal},
293
+ volume = {9},
294
+ number = {102},
295
+ pages = {6753},
296
+ author = {R. Poletti and L. Schena and D. Ninni and M. A. Mendez},
297
+ title = {MODULO: A Python toolbox for data-driven modal decomposition},
298
+ journal = {Journal of Open Source Software}
299
+ }
300
+
301
+ and
302
+
303
+ Ninni, D., & Mendez, M. A. (2020).
304
+ *MODULO: A software for Multiscale Proper Orthogonal Decomposition of data*.
305
+ SoftwareX, 12, 100622. https://doi.org/10.1016/j.softx.2020.100622
306
+
307
+ .. code-block:: text
308
+
309
+ @article{ninni2020modulo,
310
+ title={MODULO: A software for Multiscale Proper Orthogonal Decomposition of data},
311
+ author={Ninni, Davide and Mendez, Miguel A},
312
+ journal={SoftwareX},
313
+ volume={12},
314
+ pages={100622},
315
+ year={2020},
316
+ publisher={Elsevier}
317
+ }
318
+
319
+
320
+ References
321
+ ----------
322
+
323
+ - Mendez, Miguel Alfonso. "Statistical Treatment, Fourier and Modal Decomposition." arXiv preprint arXiv:2201.03847 (2022).
324
+ - Mendez, M. A. (2023) "Generalized and Multiscale Modal Analysis". In : Mendez M.A., Ianiro, A., Noack, B.R., Brunton, S. L. (Eds),
325
+ "Data-Driven Fluid Mechanics: Combining First Principles and Machine Learning". Cambridge University Press, 2023:153-181.
326
+ https://doi.org/10.1017/9781108896214.013. The pre-print is available at https://arxiv.org/abs/2208.12630.
327
+ - Ninni, Davide, and Miguel A. Mendez. "MODULO: A software for Multiscale Proper Orthogonal Decomposition of data." SoftwareX 12 (2020): 100622.
328
+ - Poletti, Romain, Schena, Lorenzo, Ninni, David, and Mendez, Miguel A. "Modulo: A python toolbox for data-driven modal decomposition". Journal of Open Source Software (2024), 9(102), 6753.
329
+ - Mendez, Miguel A. "Linear and nonlinear dimensionality reduction from fluid mechanics to machine learning." Measurement Science and Technology 34.4 (2023): 042001.
330
+ - Briggs, William L., and Van Emden Henson. The DFT: an owner's manual for the discrete Fourier transform. Society for Industrial and Applied Mathematics, 1995.
331
+ - Berkooz, Gal, Philip Holmes, and John L. Lumley. "The proper orthogonal decomposition in the analysis of turbulent flows." Annual review of fluid mechanics 25.1 (1993): 539-575.
332
+ - Sirovich, Lawrence. "Turbulence and the dynamics of coherent structures. III. Dynamics and scaling." Quarterly of Applied mathematics 45.3 (1987): 583-590.
333
+ - Mendez, M. A., M. Balabane, and J-M. Buchlin. "Multi-scale proper orthogonal decomposition of complex fluid flows." Journal of Fluid Mechanics 870 (2019): 988-1036.
334
+ - Schmid, Peter J. "Dynamic mode decomposition of numerical and experimental data." Journal of fluid mechanics 656 (2010): 5-28.
335
+ - Sieber, Moritz, C. Oliver Paschereit, and Kilian Oberleithner. "Spectral proper orthogonal decomposition." Journal of Fluid Mechanics 792 (2016): 798-828.
336
+ - Towne, Aaron, Oliver T. Schmidt, and Tim Colonius. "Spectral proper orthogonal decomposition and its relationship to dynamic mode decomposition and resolvent analysis." Journal of Fluid Mechanics 847 (2018): 821-867.
337
+ - Mika, Sebastian, et al. "Kernel PCA and de-noising in feature spaces." Advances in neural information processing systems 11 (1998).
338
+
339
+ Related projects
340
+ ----------------
341
+ MODULO encapsulates a wide range of decomposition techniques, but not all of them. We refer to the project below for an additional set of decomposition techniques:
342
+
343
+ - ModRed, https://github.com/belson17/modred
344
+
345
+ There are also decomposition-specific projects, some of which are listed below:
346
+
347
+ - Rogowski, Marcin, Brandon CY Yeung, Oliver T. Schmidt, Romit Maulik, Lisandro Dalcin, Matteo Parsani, and Gianmarco Mengaldo. "Unlocking massively parallel spectral proper orthogonal decompositions in the PySPOD package." Computer Physics Communications 302 (2024): 109246.
348
+ - Lario, A., Maulik, R., Schmidt, O.T., Rozza, G. and Mengaldo, G., 2022. Neural-network learning of SPOD latent dynamics. Journal of Computational Physics, 468, p.111475.
349
+ - Ichinaga, Andreuzzi, Demo, Tezzele, Lapo, Rozza, Brunton, Kutz. PyDMD: A Python package for robust dynamic mode decomposition. arXiv preprint, 2024.
350
+ - Rogowski, Marcin, et al. "Unlocking massively parallel spectral proper orthogonal decompositions in the PySPOD package." Computer Physics Communications 302 (2024): 109246.
351
+
352
+
353
+
354
+
355
+
356
+
@@ -1,5 +1,5 @@
1
1
  modulo_vki/__init__.py,sha256=AOjmeFjHj69m45iZzfTHM6-SLUelgKdGeu3VdSg9hIo,39
2
- modulo_vki/modulo.py,sha256=OYMLteELmAHyhfByCoy2Vqg4h7bUMsgbmIDF7jUXf3A,38261
2
+ modulo_vki/modulo.py,sha256=bpevQHd6fGwd1fIn3VSEHKgBxc9oa1Q8Fpr_qzVeqA0,38517
3
3
  modulo_vki/modulo_old.py,sha256=3r_BBYQfbmZWGDyPukyJTVYVVcAVuEE0CmREEJkzsxU,59413
4
4
  modulo_vki/core/__init__.py,sha256=y9mIqtmSg3o8TXMqFxoiMCoMSle6mK0LBrvNJCVM1Zg,226
5
5
  modulo_vki/core/_dft.py,sha256=W98vC4HR1fivZjYRQXrFKV7RBa-O3RSRwq-nCKoxqjQ,4374
@@ -17,10 +17,13 @@ modulo_vki/core/utils.py,sha256=Ac9Im9knlbZRByP6Qgv-LCDt5zEC8PbyidqXzVdeYtQ,1788
17
17
  modulo_vki/utils/__init__.py,sha256=F5yy5R19dONK9oaBEpKzylorVJNcjT2kiJ5Og-ZX1ek,94
18
18
  modulo_vki/utils/_plots.py,sha256=m43t08cVq-TY0BW0YPqT71hN-54hBphIYKZEn8Kw16E,1453
19
19
  modulo_vki/utils/_utils.py,sha256=WFD7nwjSzVHpevVwTEvMdjAmcbeqwoXT9M48tIIniJw,14355
20
- modulo_vki/utils/others.py,sha256=26ES5EmsLhwkvcXTwNhDMkblGrxoWepX5c9TXeLTRWg,17336
20
+ modulo_vki/utils/others.py,sha256=9yZzD0_rZIOWYjV2Hbi74N5oXEYct7o5h9ZjNkmxHPw,17338
21
21
  modulo_vki/utils/read_db.py,sha256=lJFauxJxS0_mYoxrbn-43UqZjOkr-qb9f6RTUq4IxZU,15149
22
- modulo_vki-2.1.2.dist-info/licenses/LICENSE,sha256=5TivriXFErrYrJgBq3M72kHNHqtSiCft3xESM1zHc0k,1091
23
- modulo_vki-2.1.2.dist-info/METADATA,sha256=dCTKzUK0d91uWzg-CoySY5towOn3-ZhExDPXmLF7w-g,14816
24
- modulo_vki-2.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
- modulo_vki-2.1.2.dist-info/top_level.txt,sha256=4PA4AmafKU6M7us7gvt_Q976Khx3qjNUEThRRM5zxeA,11
26
- modulo_vki-2.1.2.dist-info/RECORD,,
22
+ modulo_vki-2.1.4.dist-info/licenses/LICENSE,sha256=5TivriXFErrYrJgBq3M72kHNHqtSiCft3xESM1zHc0k,1091
23
+ modulo_vki_2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ modulo_vki_2/modulo.py,sha256=JhQFHsoyQ3Bp0FZ80M0WOq9hYMVkMV1lMoEnxwf2Vng,7861
25
+ modulo_vki_2/utils.py,sha256=9Zwikg7x7MtvIK1Om1JKKnCH1OQd0nf3m76APjOIyas,858
26
+ modulo_vki-2.1.4.dist-info/METADATA,sha256=5S4EkRJbdLMriyOTNqb3jjcxPj8SEaglfHGbmXWYNn8,16733
27
+ modulo_vki-2.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ modulo_vki-2.1.4.dist-info/top_level.txt,sha256=xP1gbt8FGvhIM5-zQagZXO7ut-yjUI4cXuM2GeypNuw,24
29
+ modulo_vki-2.1.4.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ modulo_vki
2
+ modulo_vki_2
File without changes
modulo_vki_2/modulo.py ADDED
@@ -0,0 +1,187 @@
1
+ import numpy as np
2
+ import os
3
+
4
+
5
+
6
+ class ModuloVKI:
7
+ """
8
+ MODULO (MODal mULtiscale pOd) is a software developed at the von Karman Institute
9
+ to perform Multiscale Modal Analysis using Multiscale Proper Orthogonal Decomposition (mPOD)
10
+ on numerical and experimental data.
11
+
12
+ References
13
+ ----------
14
+ - Theoretical foundation:
15
+ https://arxiv.org/abs/1804.09646
16
+
17
+ - MODULO framework presentation:
18
+ https://arxiv.org/pdf/2004.12123.pdf
19
+
20
+ - Hands-on tutorial videos:
21
+ https://youtube.com/playlist?list=PLEJZLD0-4PeKW6Ze984q08bNz28GTntkR
22
+
23
+ Notes
24
+ -----
25
+ MODULO operations assume the dataset is uniformly spaced in both space
26
+ (Cartesian grid) and time. For non-cartesian grids, the user must
27
+ provide a weights vector `[w_1, w_2, ..., w_Ns]` where `w_i = area_cell_i / area_grid`.
28
+ """
29
+
30
+ def __init__(self,
31
+ data: np.ndarray,
32
+ N_PARTITIONS: int = 1,
33
+ FOLDER_OUT: str = './',
34
+ SAVE_K: bool = False,
35
+ N_T: int = 100,
36
+ N_S: int = 200,
37
+ n_Modes: int = 10,
38
+ dtype: str = 'float32',
39
+ eig_solver: str = 'eigh',
40
+ svd_solver: str = 'svd_sklearn_truncated',
41
+ weights: np.ndarray = np.array([])):
42
+ """
43
+ Initialize the MODULO analysis.
44
+
45
+ Parameters
46
+ ----------
47
+ data : np.ndarray
48
+ Data matrix of shape (N_S, N_T) to factorize. If not yet formatted, use the `ReadData`
49
+ method provided by MODULO. When memory saving mode (N_PARTITIONS > 1) is active,
50
+ set this parameter to None and use prepared partitions instead.
51
+
52
+ N_PARTITIONS : int, default=1
53
+ Number of partitions used for memory-saving computation. If set greater than 1,
54
+ data must be partitioned in advance and `data` set to None.
55
+
56
+ FOLDER_OUT : str, default='./'
57
+ Directory path to store output (Phi, Sigma, Psi matrices) and intermediate
58
+ calculation files (e.g., partitions, correlation matrix).
59
+
60
+ SAVE_K : bool, default=False
61
+ Whether to store the correlation matrix K to disk in
62
+ `FOLDER_OUT/correlation_matrix`.
63
+
64
+ N_T : int, default=100
65
+ Number of temporal snapshots. Mandatory when using partitions (N_PARTITIONS > 1).
66
+
67
+ N_S : int, default=200
68
+ Number of spatial grid points. Mandatory when using partitions (N_PARTITIONS > 1).
69
+
70
+ n_Modes : int, default=10
71
+ Number of modes to compute.
72
+
73
+ dtype : str, default='float32'
74
+ Data type for casting input data.
75
+
76
+ eig_solver : str, default='eigh'
77
+ Solver for eigenvalue decomposition.
78
+
79
+ svd_solver : str, default='svd_sklearn_truncated'
80
+ Solver for Singular Value Decomposition (SVD).
81
+
82
+ weights : np.ndarray, default=np.array([])
83
+ Weights vector `[w_1, w_2, ..., w_Ns]` to account for non-uniform spatial grids.
84
+ Defined as `w_i = area_cell_i / area_grid`. Leave empty for uniform grids.
85
+ """
86
+
87
+ print("MODULO (MODal mULtiscale pOd) is a software developed at the von Karman Institute to perform "
88
+ "data driven modal decomposition of numerical and experimental data. \n")
89
+
90
+ if not isinstance(data, np.ndarray) and N_PARTITIONS == 1:
91
+ raise TypeError(
92
+ "Please check that your database is in an numpy array format. If D=None, then you must have memory saving (N_PARTITIONS>1)")
93
+
94
+ if N_PARTITIONS > 1:
95
+ self.MEMORY_SAVING = True
96
+ else:
97
+ self.MEMORY_SAVING = False
98
+
99
+ # Assign the number of modes
100
+ self.n_Modes = n_Modes
101
+ # If particular needs, override choice for svd and eigen solve
102
+ self.svd_solver = svd_solver.lower()
103
+ self.eig_solver = eig_solver.lower()
104
+ possible_svds = ['svd_numpy', 'svd_scipy_sparse', 'svd_sklearn_randomized', 'svd_sklearn_truncated']
105
+ possible_eigs = ['svd_sklearn_randomized', 'eigsh', 'eigh']
106
+
107
+ if self.svd_solver not in possible_svds:
108
+ raise NotImplementedError("The requested SVD solver is not implemented. Please pick one of the following:"
109
+ "which belongs to: \n {}".format(possible_svds))
110
+
111
+ if self.eig_solver not in possible_eigs:
112
+ raise NotImplementedError("The requested EIG solver is not implemented. Please pick one of the following: "
113
+ " \n {}".format(possible_eigs))
114
+
115
+ # if N_PARTITIONS >= self.N_T:
116
+ # raise AttributeError("The number of requested partitions is greater of the total columns (N_T). Please,"
117
+ # "try again.")
118
+
119
+ self.N_PARTITIONS = N_PARTITIONS
120
+ self.FOLDER_OUT = FOLDER_OUT
121
+ self.SAVE_K = SAVE_K
122
+
123
+ if self.MEMORY_SAVING:
124
+ os.makedirs(self.FOLDER_OUT, exist_ok=True)
125
+
126
+ # Load the data matrix
127
+ if isinstance(data, np.ndarray):
128
+ # Number of points in time and space
129
+ self.N_T = data.shape[1]
130
+ self.N_S = data.shape[0]
131
+ # Check the data type
132
+ self.D = data.astype(dtype)
133
+ else:
134
+ self.D = None # D is never saved when N_partitions >1
135
+ self.N_S = N_S # so N_S and N_t must be given as parameters of modulo
136
+ self.N_T = N_T
137
+
138
+ '''If the grid is not cartesian, ensure inner product is properly defined using weights.'''
139
+
140
+ if weights.size == 0:
141
+ print('Modulo assumes you have a uniform grid. If not, please provide weights as parameters.')
142
+ else:
143
+ if len(weights) == self.N_S:
144
+ print("The weights you have input have the size of the columns of D \n"
145
+ "MODULO has considered that you have already duplicated the dimensions of the weights "
146
+ "to match the dimensions of the D columns \n")
147
+ self.weights = weights
148
+ elif len(weights) == 2 * self.N_S:
149
+ print("Assuming 2D domain. Automatically duplicating the weights to match the dimension of the D columns \n")
150
+ self.weights = np.concatenate((weights, weights))
151
+ else:
152
+ raise AttributeError("Make sure the size of the weight array is twice smaller than the size of D")
153
+
154
+ if isinstance(data, np.ndarray):
155
+ # Apply the weights only if D exist.
156
+ # If not (i.e. N_partitions >1), weights are applied in _k_matrix.py when loading partitions of D
157
+ self.Dstar = np.transpose(np.transpose(self.D) * np.sqrt(self.weights))
158
+ else:
159
+ self.Dstar = None
160
+
161
+ def compute(
162
+ self,
163
+ kind: str,
164
+ **engine_kwargs
165
+ ) -> tuple:
166
+ """
167
+ Unified entry point for all decompositions: POD, SPOD, kPOD, DMD, DFT.
168
+ Any engine‐specific parameters (e.g. F_S, L_B, gamma…) can be passed here
169
+ and will be forwarded to the chosen engine’s constructor.
170
+ """
171
+ engine_cls = self._engines.get(kind.lower())
172
+ if engine_cls is None:
173
+ raise ValueError(f"Unknown decomposition '{kind}'")
174
+
175
+ # pick the right data array
176
+ D_use = self.Dstar # or self.D if you want un-weighted
177
+
178
+ engine = engine_cls(
179
+ D=D_use,
180
+ folder_out=self.FOLDER_OUT,
181
+ save_k=self.SAVE_K,
182
+ memory_saving=self.MEMORY_SAVING,
183
+ n_partitions=self.N_PARTITIONS,
184
+ **engine_kwargs
185
+ )
186
+ return engine.run()
187
+
modulo_vki_2/utils.py ADDED
@@ -0,0 +1,22 @@
1
+ import numpy as np
2
+
3
+ def apply_weights(D: np.ndarray, weights: np.ndarray) -> np.ndarray:
4
+ """
5
+ If `weights` is empty, return D unchanged.
6
+ If `weights` has length n_s, assume 1D grid and tile automatically.
7
+ If `weights` has length 2*n_s, assume 2D grid and use directly.
8
+ Returns D_star = D * sqrt(w) applied column-wise.
9
+ """
10
+ n_s, n_t = D.shape
11
+ if weights.size == 0:
12
+ return D
13
+ w = np.asarray(weights, dtype=D.dtype)
14
+ if w.size == n_s:
15
+ # 1D grid: automatically broadcast each weight to full time series
16
+ w_full = np.repeat(w, n_t//n_s) # or tile as needed for time dims
17
+ elif w.size == 2*n_s:
18
+ w_full = w
19
+ else:
20
+ raise ValueError(f"weights must be length {n_s} or {2*n_s}, got {w.size}")
21
+ # apply weights: scale each row i by sqrt(w_full[i])
22
+ return (D.T * np.sqrt(w_full)).T
@@ -1 +0,0 @@
1
- modulo_vki