Browse code

run pre-commit run --all

Bas Nijholt authored on 11/12/2019 14:00:39
Showing 1 changed files
... ...
@@ -8,7 +8,7 @@ from PIL import Image, ImageDraw
8 8
 
9 9
 sys.path.insert(0, os.path.abspath(".."))  # to get adaptive on the path
10 10
 
11
-import adaptive  # noqa: E402
11
+import adaptive  # noqa: E402, isort:skip
12 12
 
13 13
 holoviews.notebook_extension("matplotlib")
14 14
 
... ...
@@ -19,7 +19,7 @@ def create_and_run_learner():
19 19
 
20 20
         x, y = xy
21 21
         a = 0.2
22
-        return x + np.exp(-(x ** 2 + y ** 2 - 0.75 ** 2) ** 2 / a ** 4)
22
+        return x + np.exp(-((x ** 2 + y ** 2 - 0.75 ** 2) ** 2) / a ** 4)
23 23
 
24 24
     learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
25 25
     adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)
Browse code

2D: remove other occurrences of learner.ip()

Bas Nijholt authored on 08/10/2019 16:26:02
Showing 1 changed files
... ...
@@ -28,7 +28,7 @@ def create_and_run_learner():
28 28
 
29 29
 def plot_learner_and_save(learner, fname):
30 30
     fig, ax = plt.subplots()
31
-    tri = learner.ip().tri
31
+    tri = learner.interpolator(scaled=True).tri
32 32
     triang = mtri.Triangulation(*tri.points.T, triangles=tri.vertices)
33 33
     ax.triplot(triang, c="k", lw=0.8)
34 34
     ax.imshow(learner.plot().Image.I.data, extent=(-0.5, 0.5, -0.5, 0.5))
Browse code

fix all flake8 issues and run pre-commit filters

Bas Nijholt authored on 08/05/2019 02:26:15
Showing 1 changed files
... ...
@@ -1,22 +1,25 @@
1 1
 import os
2 2
 import sys
3 3
 
4
-sys.path.insert(0, os.path.abspath('..'))  # to get adaptive on the path
5
-
6
-import adaptive
7 4
 import holoviews
8 5
 import matplotlib.pyplot as plt
9 6
 import matplotlib.tri as mtri
10 7
 from PIL import Image, ImageDraw
11
-holoviews.notebook_extension('matplotlib')
8
+
9
+sys.path.insert(0, os.path.abspath(".."))  # to get adaptive on the path
10
+
11
+import adaptive  # noqa: E402
12
+
13
+holoviews.notebook_extension("matplotlib")
12 14
 
13 15
 
14 16
 def create_and_run_learner():
15 17
     def ring(xy):
16 18
         import numpy as np
19
+
17 20
         x, y = xy
18 21
         a = 0.2
19
-        return x + np.exp(-(x**2 + y**2 - 0.75**2)**2/a**4)
22
+        return x + np.exp(-(x ** 2 + y ** 2 - 0.75 ** 2) ** 2 / a ** 4)
20 23
 
21 24
     learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
22 25
     adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)
... ...
@@ -27,7 +30,7 @@ def plot_learner_and_save(learner, fname):
27 30
     fig, ax = plt.subplots()
28 31
     tri = learner.ip().tri
29 32
     triang = mtri.Triangulation(*tri.points.T, triangles=tri.vertices)
30
-    ax.triplot(triang, c='k', lw=0.8)
33
+    ax.triplot(triang, c="k", lw=0.8)
31 34
     ax.imshow(learner.plot().Image.I.data, extent=(-0.5, 0.5, -0.5, 0.5))
32 35
     ax.set_xticks([])
33 36
     ax.set_yticks([])
... ...
@@ -36,10 +39,10 @@ def plot_learner_and_save(learner, fname):
36 39
 
37 40
 def add_rounded_corners(fname, rad):
38 41
     im = Image.open(fname)
39
-    circle = Image.new('L', (rad * 2, rad * 2), 0)
42
+    circle = Image.new("L", (rad * 2, rad * 2), 0)
40 43
     draw = ImageDraw.Draw(circle)
41 44
     draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
42
-    alpha = Image.new('L', im.size, 255)
45
+    alpha = Image.new("L", im.size, 255)
43 46
     w, h = im.size
44 47
     alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
45 48
     alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
... ...
@@ -49,9 +52,9 @@ def add_rounded_corners(fname, rad):
49 52
     return im
50 53
 
51 54
 
52
-if __name__ == '__main__':
55
+if __name__ == "__main__":
53 56
     learner = create_and_run_learner()
54
-    fname = 'source/_static/logo_docs.png'
57
+    fname = "source/_static/logo_docs.png"
55 58
     plot_learner_and_save(learner, fname)
56 59
     im = add_rounded_corners(fname, rad=200)
57 60
     im.thumbnail((200, 200), Image.ANTIALIAS)  # resize
Browse code

add logo building to Makefile

Joseph Weston authored on 08/04/2019 12:55:59
Showing 1 changed files
... ...
@@ -1,3 +1,8 @@
1
+import os
2
+import sys
3
+
4
+sys.path.insert(0, os.path.abspath('..'))  # to get adaptive on the path
5
+
1 6
 import adaptive
2 7
 import holoviews
3 8
 import matplotlib.pyplot as plt
Browse code

add documentation logo creation script

Bas Nijholt authored on 21/03/2019 10:26:21
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,53 @@
1
+import adaptive
2
+import holoviews
3
+import matplotlib.pyplot as plt
4
+import matplotlib.tri as mtri
5
+from PIL import Image, ImageDraw
6
+holoviews.notebook_extension('matplotlib')
7
+
8
+
9
+def create_and_run_learner():
10
+    def ring(xy):
11
+        import numpy as np
12
+        x, y = xy
13
+        a = 0.2
14
+        return x + np.exp(-(x**2 + y**2 - 0.75**2)**2/a**4)
15
+
16
+    learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])
17
+    adaptive.runner.simple(learner, goal=lambda l: l.loss() < 0.01)
18
+    return learner
19
+
20
+
21
+def plot_learner_and_save(learner, fname):
22
+    fig, ax = plt.subplots()
23
+    tri = learner.ip().tri
24
+    triang = mtri.Triangulation(*tri.points.T, triangles=tri.vertices)
25
+    ax.triplot(triang, c='k', lw=0.8)
26
+    ax.imshow(learner.plot().Image.I.data, extent=(-0.5, 0.5, -0.5, 0.5))
27
+    ax.set_xticks([])
28
+    ax.set_yticks([])
29
+    plt.savefig(fname, bbox_inches="tight", transparent=True, dpi=300, pad_inches=-0.1)
30
+
31
+
32
+def add_rounded_corners(fname, rad):
33
+    im = Image.open(fname)
34
+    circle = Image.new('L', (rad * 2, rad * 2), 0)
35
+    draw = ImageDraw.Draw(circle)
36
+    draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
37
+    alpha = Image.new('L', im.size, 255)
38
+    w, h = im.size
39
+    alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
40
+    alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
41
+    alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
42
+    alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
43
+    im.putalpha(alpha)
44
+    return im
45
+
46
+
47
+if __name__ == '__main__':
48
+    learner = create_and_run_learner()
49
+    fname = 'source/_static/logo_docs.png'
50
+    plot_learner_and_save(learner, fname)
51
+    im = add_rounded_corners(fname, rad=200)
52
+    im.thumbnail((200, 200), Image.ANTIALIAS)  # resize
53
+    im.save(fname)