jcandane commited on
Commit
68ef771
·
verified ·
1 Parent(s): d21d039

Upload ring_dataset.ipynb

Browse files
Files changed (1) hide show
  1. ring_dataset.ipynb +367 -0
ring_dataset.ipynb ADDED
@@ -0,0 +1,367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "authorship_tag": "ABX9TyOqoPlJxEzXB/rGffrk47H3",
8
+ "include_colab_link": true
9
+ },
10
+ "kernelspec": {
11
+ "name": "python3",
12
+ "display_name": "Python 3"
13
+ },
14
+ "language_info": {
15
+ "name": "python"
16
+ }
17
+ },
18
+ "cells": [
19
+ {
20
+ "cell_type": "markdown",
21
+ "metadata": {
22
+ "id": "view-in-github",
23
+ "colab_type": "text"
24
+ },
25
+ "source": [
26
+ "<a href=\"https://colab.research.google.com/github/jcandane/gym_rings/blob/main/ring_dataset.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "markdown",
31
+ "source": [
32
+ "# Ring Dataset for Calibration of Classification & Manifold Models"
33
+ ],
34
+ "metadata": {
35
+ "id": "H-BUP1FKiX4R"
36
+ }
37
+ },
38
+ {
39
+ "cell_type": "markdown",
40
+ "source": [
41
+ "## defs"
42
+ ],
43
+ "metadata": {
44
+ "id": "PBkKn7m0ydvB"
45
+ }
46
+ },
47
+ {
48
+ "cell_type": "markdown",
49
+ "source": [
50
+ "### optional download from github repo"
51
+ ],
52
+ "metadata": {
53
+ "id": "t2ypmzGg6PaJ"
54
+ }
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "source": [
59
+ "try:\n",
60
+ " from gym_rings import get_rings\n",
61
+ "except:\n",
62
+ " !wget https://raw.githubusercontent.com/jcandane/gym_rings/main/gym_rings.py\n",
63
+ " from gym_rings import get_rings"
64
+ ],
65
+ "metadata": {
66
+ "id": "0MWhz-V36ZjT"
67
+ },
68
+ "execution_count": 1,
69
+ "outputs": []
70
+ },
71
+ {
72
+ "cell_type": "markdown",
73
+ "source": [
74
+ "### raw code"
75
+ ],
76
+ "metadata": {
77
+ "id": "JiZ9NcKW6Xpi"
78
+ }
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "source": [
83
+ "import numpy as np\n",
84
+ "\n",
85
+ "def define_ring(A, radii):\n",
86
+ " \"\"\"\n",
87
+ " define a Boolean ring, such that the image is made from \"True\" or \"1\".\n",
88
+ " A:np.ndarray (initial array)\n",
89
+ " radius_range:tuple defined by (minimum radius, maximum radius)\n",
90
+ " GET>\n",
91
+ " A:np.ndarray (initial array with an additional ring with radius_range)\n",
92
+ " \"\"\"\n",
93
+ " height, width = A.shape\n",
94
+ " radii = radii.reshape(-1,2).T\n",
95
+ "\n",
96
+ " center = np.array([width / 2, height / 2])\n",
97
+ " I_xi = np.indices((height, width)).reshape(2, -1) ## meshgrid -> flatten image\n",
98
+ " I_xi = np.vstack((I_xi[1], I_xi[0]))\n",
99
+ "\n",
100
+ " ### RINGS\n",
101
+ " mask_i = (np.linalg.norm(I_xi-center[:,None], axis=0)[:,None] >= radii[0][None,:]) ##&\n",
102
+ " mask_i &= (np.linalg.norm(I_xi-center[:,None], axis=0)[:,None] < radii[1][None,:])\n",
103
+ " mask_i = np.any(mask_i, axis=-1)\n",
104
+ "\n",
105
+ " A = A.reshape(-1)\n",
106
+ " A[mask_i] = 1\n",
107
+ " return A.reshape(height, width)\n",
108
+ "\n",
109
+ "def ring_notch(image_shape, θ:np.ndarray, radius_range, notch_width=5.):\n",
110
+ " \"\"\"\n",
111
+ " GIVEN>\n",
112
+ " image_shape:tuple (The shape of the image (height, width))\n",
113
+ " θ:np.ndarray[1d] (list of angles, θ.shape=(samples,))\n",
114
+ " radius_range:np.ndarray (for a given ring, [R_min,R_max])\n",
115
+ " notch_width:float (in degrees)\n",
116
+ " GET>\n",
117
+ " np.ndarray (A boolean mask for the notches)\n",
118
+ " \"\"\"\n",
119
+ " height, width = image_shape\n",
120
+ "\n",
121
+ " θ = (θ).astype(float)\n",
122
+ " θ *= -1.\n",
123
+ " #θ -= 1.*notch_width\n",
124
+ " θ_min = np.deg2rad(θ - notch_width)\n",
125
+ " θ_max = np.deg2rad(θ + notch_width)\n",
126
+ "\n",
127
+ " # Create a grid of x and y coordinates\n",
128
+ " y, x = np.ogrid[:height, :width]\n",
129
+ "\n",
130
+ " # Calculate the distances and angles\n",
131
+ " y = y - width / 2\n",
132
+ " x = x - height / 2\n",
133
+ " distance = np.sqrt(x**2 + y**2)\n",
134
+ " angle = np.arctan2(y, x) ## every pixel associated an angle\n",
135
+ "\n",
136
+ " # Normalize angles to [0, 2*pi)\n",
137
+ " angle = np.mod(angle, 2 * np.pi)\n",
138
+ " θ_min = np.mod(θ_min, 2 * np.pi)\n",
139
+ " θ_max = np.mod(θ_max, 2 * np.pi)\n",
140
+ "\n",
141
+ " # Create the mask for the angle range\n",
142
+ " R_min, R_max = radius_range\n",
143
+ " R_min = float(R_min)-0.01\n",
144
+ " R_max = float(R_max)+0.01\n",
145
+ "\n",
146
+ " shifted_angle = (angle[:,:,None] - θ_min[None,None,:]) % 360 ### why not % 2*np.pi ???\n",
147
+ " shifted_end_angle = (θ_max - θ_min) % 360\n",
148
+ " angle_mask = (shifted_angle <= shifted_end_angle[None,None,:])\n",
149
+ "\n",
150
+ " radius_mask = (distance <= R_max) & (distance > R_min)\n",
151
+ " mask = angle_mask & radius_mask[:,:,None]\n",
152
+ " return mask.swapaxes(0,2).swapaxes(1,2) ### s.t. snapshots, pixels\n",
153
+ "\n",
154
+ "def get_rings(N:int, θs:np.ndarray, radii, notch_width=5.): ##\n",
155
+ " \"\"\"\n",
156
+ " GIVEN>\n",
157
+ " N:int (image side size, such that image.shape=(N,N))\n",
158
+ " θs:np.ndarray[2d] (list of angles for each ring, with θs.shape=(ring count, samples) )\n",
159
+ " radii:np.ndarray[2] (with shape=(ring count, 2), i.e. axis=1 is the R_min, R_max for each ring)\n",
160
+ " notch_width:float (notch angle, default=5 degrees, this can be generalized)\n",
161
+ " GET>\n",
162
+ " np.ndarray (dataset of shape=(θs.shape[1], N, N))\n",
163
+ " \"\"\"\n",
164
+ " img_shape = (N,N)\n",
165
+ "\n",
166
+ " R = define_ring(np.zeros(img_shape, dtype=bool), radii)\n",
167
+ " mask = np.asarray([ ring_notch(img_shape, θs[r], radii[r], notch_width=notch_width) for r in range(len(radii))])\n",
168
+ " mask = np.sum(mask, axis=0)\n",
169
+ "\n",
170
+ " return R[None,:,:]*np.logical_not( mask )"
171
+ ],
172
+ "metadata": {
173
+ "id": "53embXj5iqV6"
174
+ },
175
+ "execution_count": 2,
176
+ "outputs": []
177
+ },
178
+ {
179
+ "cell_type": "markdown",
180
+ "source": [
181
+ "## Rings test"
182
+ ],
183
+ "metadata": {
184
+ "id": "Jm3p1JlLqxO5"
185
+ }
186
+ },
187
+ {
188
+ "cell_type": "code",
189
+ "source": [
190
+ "import matplotlib.pyplot as plt\n",
191
+ "\n",
192
+ "### input\n",
193
+ "N = 256\n",
194
+ "angles = np.array([[90,270,180.,0,360,65,182, 234], [45,86,243,360,97,12, 311, 34], [90,270,90,5,156,65,182, 211]])\n",
195
+ "radii = np.array([[30,50],[70,90],[110,130]])\n",
196
+ "\n",
197
+ "### ouput\n",
198
+ "A = get_rings(N, angles, radii)\n",
199
+ "\n",
200
+ "plt.imshow(A[-8], interpolation='none', cmap='Greys')\n",
201
+ "plt.axis(\"off\")\n",
202
+ "plt.show()"
203
+ ],
204
+ "metadata": {
205
+ "colab": {
206
+ "base_uri": "https://localhost:8080/",
207
+ "height": 406
208
+ },
209
+ "id": "2by18XdLq1bh",
210
+ "outputId": "e71e882d-e45e-479b-fb72-bb49f74efe99"
211
+ },
212
+ "execution_count": 3,
213
+ "outputs": [
214
+ {
215
+ "output_type": "display_data",
216
+ "data": {
217
+ "text/plain": [
218
+ "<Figure size 640x480 with 1 Axes>"
219
+ ],
220
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAATzElEQVR4nO3d0ZbqOA4FUDOr//+XmYdufLlVFEUgiY/svd9mreluIsmRraTgcr1erw0AWmv/G/0BAMihKQDQaQoAdJoCAJ2mAECnKQDQaQoAdJoCAN0/oz8A3Fwul4/++YS/w5zhGlibpsCpPr1pzu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HAHROCnRGS2tyOuCepsBDj24UGsUcNAGeMT4CoHNS4GVOD7U4EfAOTYGP/HTj0SzO4+bPnoyPAOicFDiEE8T+nAg4g6bAqdzYIJvxEQCdpgBApykA0GkKAHSaAgCdpgBApykA0GkKAHSaAgDd/wHCLXipRXdU0gAAAABJRU5ErkJggg==\n"
221
+ },
222
+ "metadata": {}
223
+ }
224
+ ]
225
+ },
226
+ {
227
+ "cell_type": "code",
228
+ "source": [
229
+ "import matplotlib.pyplot as plt\n",
230
+ "\n",
231
+ "### input\n",
232
+ "N = 64\n",
233
+ "angles = 360*np.random.rand(3,100000)\n",
234
+ "radii = np.array([[1,10],[15,30]]) #np.array([[30,50],[70,90],[110,130]])\n",
235
+ "\n",
236
+ "### ouput\n",
237
+ "A = get_rings(N, angles, radii)\n",
238
+ "\n",
239
+ "\n",
240
+ "print(A.size/1024/1024, A.dtype)\n",
241
+ "plt.imshow(A[-8], interpolation='none', cmap='Greys')\n",
242
+ "plt.axis(\"off\")\n",
243
+ "plt.show()"
244
+ ],
245
+ "metadata": {
246
+ "colab": {
247
+ "base_uri": "https://localhost:8080/",
248
+ "height": 424
249
+ },
250
+ "id": "9KT-Nq39oJw_",
251
+ "outputId": "27070a9b-8f0a-425b-c843-c28883e82282"
252
+ },
253
+ "execution_count": 4,
254
+ "outputs": [
255
+ {
256
+ "output_type": "stream",
257
+ "name": "stdout",
258
+ "text": [
259
+ "390.625 bool\n"
260
+ ]
261
+ },
262
+ {
263
+ "output_type": "display_data",
264
+ "data": {
265
+ "text/plain": [
266
+ "<Figure size 640x480 with 1 Axes>"
267
+ ],
268
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAHf0lEQVR4nO3dwW7bRhRAUarI//8yuyh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AiCgAEFEAIKIAQGwfDcBb3eAnW0bXMikAEFEAIKIAQEQBgDhoHpRHZbASh8fzMCkAEFEAIKIAQEQBgIgCALF9tIij7Q5bSXySLaP5mRQAiCgAEFEAIKIAQEQBgNg+WtwZ2yA2mO7B5hDbZlIA4BeiAEBEAYCIAgARBQBi+4iXztpKscX0PWwNcSaTAgARBQAiCgBEFACIg2Y+xoEojM+kAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAORfYbo0OJmrIksAAAAASUVORK5CYII=\n"
269
+ },
270
+ "metadata": {}
271
+ }
272
+ ]
273
+ },
274
+ {
275
+ "cell_type": "markdown",
276
+ "source": [
277
+ "## Pendulum Data Set"
278
+ ],
279
+ "metadata": {
280
+ "id": "xIZtaQQp710J"
281
+ }
282
+ },
283
+ {
284
+ "cell_type": "code",
285
+ "source": [
286
+ "### download numpy zip file for pendulum trajectory\n",
287
+ "try:\n",
288
+ " angles = np.load(\"pendulum_L100m_1000s_90deg_a0_0014mss.npy\")[1]\n",
289
+ "except:\n",
290
+ " !wget https://raw.githubusercontent.com/jcandane/gym_rings/main/pendulum_L100m_1000s_90deg_a0_0014mss.npy\n",
291
+ " angles = np.load(\"pendulum_L100m_1000s_90deg_a0_0014mss.npy\")[1] ## for angles, [0] are real time-stamps\n",
292
+ "\n",
293
+ "angles=np.array([angles])-90\n",
294
+ "N = 32\n",
295
+ "radii = np.array([[5,15]])\n",
296
+ "\n",
297
+ "### ouput data_set\n",
298
+ "A = get_rings(N, angles, radii)"
299
+ ],
300
+ "metadata": {
301
+ "id": "ppzst4Fjpje4"
302
+ },
303
+ "execution_count": 5,
304
+ "outputs": []
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "source": [
309
+ "print(A.size/1024/1024, A.dtype)\n",
310
+ "plt.imshow(A[0], interpolation='none', cmap='Greys')\n",
311
+ "plt.axis(\"off\")\n",
312
+ "plt.show()\n",
313
+ "\n",
314
+ "plt.imshow(A[-1], interpolation='none', cmap='Greys')\n",
315
+ "plt.axis(\"off\")\n",
316
+ "plt.show()"
317
+ ],
318
+ "metadata": {
319
+ "colab": {
320
+ "base_uri": "https://localhost:8080/",
321
+ "height": 813
322
+ },
323
+ "id": "AzxYEkL5AEGy",
324
+ "outputId": "26a585a7-41d6-47c3-b726-7ec69366cfa2"
325
+ },
326
+ "execution_count": 6,
327
+ "outputs": [
328
+ {
329
+ "output_type": "stream",
330
+ "name": "stdout",
331
+ "text": [
332
+ "97.65625 bool\n"
333
+ ]
334
+ },
335
+ {
336
+ "output_type": "display_data",
337
+ "data": {
338
+ "text/plain": [
339
+ "<Figure size 640x480 with 1 Axes>"
340
+ ],
341
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAGJElEQVR4nO3cwW4TMRhG0Rjl/V/Z7C6CBdQ0E09mzllHwqraXP0LvjHnnA8AeDweP3Y/AIDzEAUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQJ67H8D5jTF2P4FN5py7n8CbuRQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACC2jy7CPhFHOPL3yq7SObkUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQMxcnZbaCq1v9HTeL8R4uBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiO2jb7BPBO9z5N+bXaVfXAoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIiZiz+YroD7Wf27v/IshksBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIA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qzujthKAv7l0/aMVrgUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCAHnufsDZzDm//NkxxoEvAd5l5e/+6lwKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQ20ffcOReil0l+J19ovdwKQAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIGYuTmr1v/SbxeDTmK04J5cCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgDE9tFFHLkjY1fpvuwT3Y9LAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAMXPBP5k6gPtwKQAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgD5CVIkbTS2TJ6sAAAAAElFTkSuQmCC\n"
342
+ },
343
+ "metadata": {}
344
+ },
345
+ {
346
+ "output_type": "display_data",
347
+ "data": {
348
+ "text/plain": [
349
+ "<Figure size 640x480 with 1 Axes>"
350
+ ],
351
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAGJ0lEQVR4nO3cwW5TMRRF0Rjl/3/ZzDaCAdQ0L3aStcaRsKo2W3fAGXPOeQOA2+32Y/cDADiHKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAct/9AM43xtj9BDaZc+5+Ak/mUgAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgNg+ehP2ibjClb9XdpXO5FIAIKIAQEQBgIgCABEF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AQEQBgIgCABEFACIKAOSImYs559LnTR0A72r1+/DRXAoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGA3Hc/4H/MOb/82THGhS8B+LuV76sTuBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACAvuX20YnV3xFYS8C+vtme0wqUAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAyH33A04z5/zyZ8cYF74EeJaVv/t351IAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYDYPvqGK/dS7CrB7+wTPYdLAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAMXNxqNX/0m8Wg1djtuJMLgUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIjtozdx5Y6MXaXPZZ/o87gUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQMxf8k6kD+BwuBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACA/Aeq5ajq2wg9GAAAAAElFTkSuQmCC\n"
352
+ },
353
+ "metadata": {}
354
+ }
355
+ ]
356
+ },
357
+ {
358
+ "cell_type": "code",
359
+ "source": [],
360
+ "metadata": {
361
+ "id": "W--VG00o83zE"
362
+ },
363
+ "execution_count": 6,
364
+ "outputs": []
365
+ }
366
+ ]
367
+ }