Skip to content

Commit 9edbf04

Browse files
committed
Tutorial updates
1 parent fcc35ae commit 9edbf04

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

tutorials/quickstart-tutorial1/quickstart-bopdmd.ipynb

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,94 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "2a54ce30-2805-4878-a5dc-e836f88c4e4a",
6+
"metadata": {},
7+
"source": [
8+
"# PyDMD"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "9bb703be-d0b0-4780-bac3-ae2395b0a854",
14+
"metadata": {},
15+
"source": [
16+
"## Quickstart Tutorial 1: BOP-DMD on Flow Past a Cylinder Data"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 3,
22+
"id": "40509c89-9cae-4b8b-b8ae-c9245edda061",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"import numpy as np\n",
27+
"import scipy.io as sio\n",
28+
"import matplotlib.pyplot as plt\n",
29+
"\n",
30+
"from pydmd import BOPDMD\n",
31+
"from pydmd.plotter import plot_summary\n",
32+
"from pydmd.preprocessing import zero_mean_preprocessing"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "237dcc38-2edd-48a1-9513-6f59e5be60db",
38+
"metadata": {},
39+
"source": [
40+
"### Import Data"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 4,
46+
"id": "816096f6-5814-4599-812d-f27a8c076f12",
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"ename": "FileNotFoundError",
51+
"evalue": "[Errno 2] No such file or directory: 'CYLINDER_ALL.mat'",
52+
"output_type": "error",
53+
"traceback": [
54+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
55+
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
56+
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/io/matlab/_mio.py:39\u001b[0m, in \u001b[0;36m_open_file\u001b[0;34m(file_like, appendmat, mode)\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m---> 39\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mfile_like\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m, \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 41\u001b[0m \u001b[38;5;66;03m# Probably \"not found\"\u001b[39;00m\n",
57+
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'CYLINDER_ALL.mat'",
58+
"\nDuring handling of the above exception, another exception occurred:\n",
59+
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
60+
"Cell \u001b[0;32mIn[4], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Import vorticity data and frame dimensions.\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m mat \u001b[38;5;241m=\u001b[39m \u001b[43msio\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloadmat\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mCYLINDER_ALL.mat\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m X \u001b[38;5;241m=\u001b[39m mat[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mVORTALL\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;66;03m# Vorticity data.\u001b[39;00m\n\u001b[1;32m 4\u001b[0m nx \u001b[38;5;241m=\u001b[39m mat[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnx\u001b[39m\u001b[38;5;124m\"\u001b[39m][\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m] \u001b[38;5;66;03m# Number of pixels along x-axis.\u001b[39;00m\n",
61+
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/io/matlab/_mio.py:225\u001b[0m, in \u001b[0;36mloadmat\u001b[0;34m(file_name, mdict, appendmat, **kwargs)\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 89\u001b[0m \u001b[38;5;124;03mLoad MATLAB file.\u001b[39;00m\n\u001b[1;32m 90\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 222\u001b[0m \u001b[38;5;124;03m 3.14159265+3.14159265j])\u001b[39;00m\n\u001b[1;32m 223\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 224\u001b[0m variable_names \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvariable_names\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[0;32m--> 225\u001b[0m \u001b[43m\u001b[49m\u001b[38;5;28;43;01mwith\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43m_open_file_context\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mappendmat\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mas\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 226\u001b[0m \u001b[43m \u001b[49m\u001b[43mMR\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mmat_reader_factory\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 227\u001b[0m \u001b[43m \u001b[49m\u001b[43mmatfile_dict\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mMR\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_variables\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvariable_names\u001b[49m\u001b[43m)\u001b[49m\n",
62+
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py:137\u001b[0m, in \u001b[0;36m_GeneratorContextManager.__enter__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 135\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39margs, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkwds, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfunc\n\u001b[1;32m 136\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 137\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mnext\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mgen)\n\u001b[1;32m 138\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m:\n\u001b[1;32m 139\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgenerator didn\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt yield\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
63+
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/io/matlab/_mio.py:17\u001b[0m, in \u001b[0;36m_open_file_context\u001b[0;34m(file_like, appendmat, mode)\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;129m@contextmanager\u001b[39m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_open_file_context\u001b[39m(file_like, appendmat, mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrb\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[0;32m---> 17\u001b[0m f, opened \u001b[38;5;241m=\u001b[39m \u001b[43m_open_file\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile_like\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mappendmat\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m f\n",
64+
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/io/matlab/_mio.py:45\u001b[0m, in \u001b[0;36m_open_file\u001b[0;34m(file_like, appendmat, mode)\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m appendmat \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m file_like\u001b[38;5;241m.\u001b[39mendswith(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.mat\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 44\u001b[0m file_like \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.mat\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m---> 45\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mfile_like\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m, \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m 46\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 47\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\n\u001b[1;32m 48\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mReader needs file name or open file-like object\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 49\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n",
65+
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'CYLINDER_ALL.mat'"
66+
]
67+
}
68+
],
69+
"source": [
70+
"# Import vorticity data and frame dimensions.\n",
71+
"mat = sio.loadmat(\"CYLINDER_ALL.mat\")\n",
72+
"\n",
73+
"X = mat[\"VORTALL\"] # Vorticity data.\n",
74+
"nx = mat[\"nx\"][0][0] # Number of pixels along x-axis.\n",
75+
"ny = mat[\"ny\"][0][0] # Number of pixels along y-axis.\n",
76+
"m = X.shape[-1] # Number of time points.\n",
77+
"t = np.arange(m) # Time data.\n",
78+
"\n",
79+
"# Add Gaussian noise to the data.\n",
80+
"noise_magnitude = 0.2\n",
81+
"rng = np.random.default_rng(seed=1234)\n",
82+
"noise = noise_magnitude * rng.standard_normal(X.shape)\n",
83+
"X += noise\n",
84+
"\n",
85+
"print(X.shape)"
86+
]
87+
},
388
{
489
"cell_type": "code",
590
"execution_count": null,
6-
"id": "9004b72d-029b-46c5-9a89-3155e8437be3",
91+
"id": "4c6d9d90-8a03-413d-a428-d7331e96daa9",
792
"metadata": {},
893
"outputs": [],
994
"source": []

0 commit comments

Comments
 (0)