You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc_source/notebooks/Matisse/example_matisse.ipynb
+68-4Lines changed: 68 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,55 @@
21
21
"execution_count": null,
22
22
"metadata": {},
23
23
"outputs": [],
24
-
"source": "# -----------------\n# Standard imports\n# -----------------\nimport numpy as np # for arrays\nimport matplotlib.pyplot as plt # for plotting\nfrom sklearn.decomposition import PCA # for PCA for normalization\nfrom scipy.spatial import distance_matrix\n\nfrom os import listdir # for retrieving files from directory\nfrom os.path import isfile, join # for retrieving files from directory\nfrom sklearn.manifold import MDS # for MDS\nimport pandas as pd # for loading in colors csv\nimport os\nimport zipfile\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\n# ---------------------------\n# The ECT packages we'll use\n# ---------------------------\nfrom ect import ECT, EmbeddedComplex # for calculating ECTs\n# Note: EmbeddedGraph is now unified into EmbeddedComplex\n# For backward compatibility, you can still use:\n# from ect import EmbeddedGraph\n\n# Simple data paths\ndata_dir = \"outlines/\"\ncolors_path = \"colors.csv\"\n\nfile_names = [\n f for f in listdir(data_dir) if isfile(join(data_dir, f)) and f[-4:] == \".txt\"\n]\nfile_names.sort()\nprint(f\"There are {len(file_names)} files in the directory\")"
24
+
"source": [
25
+
"# -----------------\n",
26
+
"# Standard imports\n",
27
+
"# -----------------\n",
28
+
"import numpy as np # for arrays\n",
29
+
"import matplotlib.pyplot as plt # for plotting\n",
30
+
"from sklearn.decomposition import PCA # for PCA for normalization\n",
31
+
"from scipy.spatial import distance_matrix\n",
32
+
"\n",
33
+
"from os import listdir # for retrieving files from directory\n",
34
+
"from os.path import isfile, join # for retrieving files from directory\n",
35
+
"from sklearn.manifold import MDS # for MDS\n",
36
+
"import pandas as pd # for loading in colors csv\n",
37
+
"import os\n",
38
+
"import zipfile\n",
39
+
"\n",
40
+
"import warnings\n",
41
+
"warnings.filterwarnings('ignore')\n",
42
+
"\n",
43
+
"# ---------------------------\n",
44
+
"# The ECT packages we'll use\n",
45
+
"# ---------------------------\n",
46
+
"from ect import ECT, EmbeddedComplex # for calculating ECTs\n",
47
+
"# Note: EmbeddedGraph is now unified into EmbeddedComplex\n",
48
+
"# For backward compatibility, you can still use:\n",
49
+
"# from ect import EmbeddedGraph\n",
50
+
"\n",
51
+
"# Simple data paths\n",
52
+
"data_dir = \"outlines/\"\n",
53
+
"colors_path = \"colors.csv\"\n",
54
+
"\n",
55
+
"# Ensure outlines are available when running under Sphinx/CI\n",
56
+
"if not os.path.isdir(data_dir):\n",
57
+
" zip_path = \"outlines.zip\"\n",
58
+
" if os.path.isfile(zip_path):\n",
59
+
" with zipfile.ZipFile(zip_path, \"r\") as zf:\n",
60
+
" zf.extractall(\".\")\n",
61
+
" else:\n",
62
+
" raise FileNotFoundError(\n",
63
+
"\"Could not find 'outlines/' directory or 'outlines.zip'. \"\n",
64
+
"\"Please download the Matisse outlines and place them next to this notebook.\"\n",
65
+
" )\n",
66
+
"\n",
67
+
"file_names = [\n",
68
+
" f for f in listdir(data_dir) if isfile(join(data_dir, f)) and f[-4:] == \".txt\"\n",
69
+
"]\n",
70
+
"file_names.sort()\n",
71
+
"print(f\"There are {len(file_names)} files in the directory\")"
72
+
]
25
73
},
26
74
{
27
75
"cell_type": "markdown",
@@ -39,7 +87,14 @@
39
87
"execution_count": null,
40
88
"metadata": {},
41
89
"outputs": [],
42
-
"source": "i = 3\nshape = np.loadtxt(data_dir + file_names[i])\n# shape = normalize(shape)\nG = EmbeddedComplex() # Using the unified EmbeddedComplex class\nG.add_cycle(shape)\nG.plot(with_labels=False, node_size=10)"
90
+
"source": [
91
+
"i = 3\n",
92
+
"shape = np.loadtxt(data_dir + file_names[i])\n",
93
+
"# shape = normalize(shape)\n",
94
+
"G = EmbeddedComplex() # Using the unified EmbeddedComplex class\n",
95
+
"G.add_cycle(shape)\n",
96
+
"G.plot(with_labels=False, node_size=10)"
97
+
]
43
98
},
44
99
{
45
100
"cell_type": "markdown",
@@ -133,7 +188,16 @@
133
188
"execution_count": null,
134
189
"metadata": {},
135
190
"outputs": [],
136
-
"source": "def matisse_ect(filename, ect):\n shape = np.loadtxt(data_dir + filename)\n G = EmbeddedComplex() # Using the unified EmbeddedComplex class \n G.add_cycle(shape)\n G.transform_coordinates(projection_type=\"pca\")\n G.scale_coordinates(1)\n result = ect.calculate(G)\n return result"
191
+
"source": [
192
+
"def matisse_ect(filename, ect):\n",
193
+
" shape = np.loadtxt(data_dir + filename)\n",
194
+
" G = EmbeddedComplex() # Using the unified EmbeddedComplex class \n",
0 commit comments