Skip to content

Commit

Permalink
Fix new flake8 errors [size skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Oct 24, 2017
1 parent 3d747d0 commit 574ddc4
Show file tree
Hide file tree
Showing 37 changed files with 163 additions and 161 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -24,7 +24,7 @@ large datasets. Applications of VisPy include:
Announcements
-------------

- **Release!** Version 0.5, October 23, 2017
- **Release!** Version 0.5, October 24, 2017
- **Release!** Version 0.4, May 22, 2015
- `VisPy tutorial in the IPython Cookbook <http://ipython-books.github.io/featured-06/>`__
- **Release!** Version 0.3, August 29, 2014
Expand Down
8 changes: 4 additions & 4 deletions examples/basics/gloo/animate_images.py
Expand Up @@ -14,7 +14,7 @@

# Image to be displayed
W, H = 64, 48
I = np.random.uniform(0, 1, (W, H)).astype(np.float32)
img_array = np.random.uniform(0, 1, (W, H)).astype(np.float32)

# A simple texture quad
data = np.zeros(4, dtype=[('a_position', np.float32, 2),
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self):
app.Canvas.__init__(self, keys='interactive', size=((W * 5), (H * 5)))

self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
self.texture = gloo.Texture2D(I, interpolation='linear')
self.texture = gloo.Texture2D(img_array, interpolation='linear')

self.program['u_texture'] = self.texture
self.program.bind(gloo.VertexBuffer(data))
Expand Down Expand Up @@ -104,8 +104,8 @@ def on_resize(self, event):

def on_draw(self, event):
gloo.clear(color=True, depth=True)
I[...] = np.random.uniform(0, 1, (W, H)).astype(np.float32)
self.texture.set_data(I)
img_array[...] = np.random.uniform(0, 1, (W, H)).astype(np.float32)
self.texture.set_data(img_array)
self.program.draw('triangle_strip')


Expand Down
10 changes: 5 additions & 5 deletions examples/basics/gloo/animate_images_slice.py
Expand Up @@ -21,13 +21,13 @@
D, H, W = 30, 60, 90

# Modulated image
I = np.random.uniform(0, 0.1, (D, H, W, 3)).astype(np.float32)
img_array = np.random.uniform(0, 0.1, (D, H, W, 3)).astype(np.float32)
# Depth slices are dark->light
I[...] += np.linspace(0, 0.9, D)[:, np.newaxis, np.newaxis, np.newaxis]
img_array[...] += np.linspace(0, 0.9, D)[:, np.newaxis, np.newaxis, np.newaxis]
# Make vertical direction more green moving upward
I[..., 1] *= np.linspace(0, 1, H)[np.newaxis, :, np.newaxis]
img_array[..., 1] *= np.linspace(0, 1, H)[np.newaxis, :, np.newaxis]
# Make horizontal direction more red moving rightward
I[..., 0] *= np.linspace(0, 1, W)[np.newaxis, np.newaxis, :]
img_array[..., 0] *= np.linspace(0, 1, W)[np.newaxis, np.newaxis, :]

# A simple texture quad
data = np.zeros(4, dtype=[('a_position', np.float32, 2),
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, emulate3d=True):
tex_cls = gloo.TextureEmulated3D
else:
tex_cls = gloo.Texture3D
self.texture = tex_cls(I, interpolation='nearest',
self.texture = tex_cls(img_array, interpolation='nearest',
wrapping='clamp_to_edge')

self.program = ModularProgram(VERT_SHADER, FRAG_SHADER)
Expand Down
12 changes: 6 additions & 6 deletions examples/basics/gloo/spatial_filters.py
Expand Up @@ -19,10 +19,10 @@

# create 5x5 matrix with border pixels 0, center pixels 1
# and other pixels 0.5
I = np.zeros(25).reshape((5, 5)).astype(np.float32)
I[1:4, 1::2] = 0.5
I[1::2, 2] = 0.5
I[2, 2] = 1.0
img_array = np.zeros(25).reshape((5, 5)).astype(np.float32)
img_array[1:4, 1::2] = 0.5
img_array[1::2, 2] = 0.5
img_array[2, 2] = 1.0

# loading interpolation kernel
kernel, names = load_spatial_filters()
Expand Down Expand Up @@ -69,12 +69,12 @@ def __init__(self):
app.Canvas.__init__(self, keys='interactive', size=((512), (512)))

self.program = gloo.Program(VERT_SHADER, FRAG_SHADER % 'Nearest')
self.texture = gloo.Texture2D(I, interpolation='nearest')
self.texture = gloo.Texture2D(img_array, interpolation='nearest')

# using packed data as discussed in pr #1069
self.kernel = gloo.Texture2D(kernel, interpolation='nearest')
self.program['u_texture'] = self.texture
self.program['u_shape'] = I.shape[1], I.shape[0]
self.program['u_shape'] = img_array.shape[1], img_array.shape[0]
self.program['u_kernel'] = self.kernel

self.names = names
Expand Down
5 changes: 3 additions & 2 deletions examples/basics/plotting/plot.py
Expand Up @@ -31,8 +31,9 @@
n = i * 2 + 1
y += (4. / np.pi) * (1. / n) * np.sin(n * np.pi * x / L)
if n in plot_nvals:
l = fig[0, 0].plot((x, y), color=colors[plot_nvals.index(n)], width=2)
l.update_gl_state(depth_test=False)
tmp_line = fig[0, 0].plot((x, y), color=colors[plot_nvals.index(n)],
width=2)
tmp_line.update_gl_state(depth_test=False)

labelgrid = fig[0, 0].view.add_grid(margin=10)

Expand Down
4 changes: 2 additions & 2 deletions examples/collections/triangle_collection.py
Expand Up @@ -38,14 +38,14 @@ def star(inner=0.5, outer=1.0, n=5):
triangles = TriangleCollection("raw", color='shared')

P0 = star()
P1, I = triangulate(P0)
P1, tris = triangulate(P0)

n = 1000
for i in range(n):
c = i / float(n)
x, y = np.random.uniform(-1, +1, 2)
s = 25 / 800.0
triangles.append(P1 * s + (x, y, i / 1000.), I, color=(1, 0, 0, .5))
triangles.append(P1 * s + (x, y, i / 1000.), tris, color=(1, 0, 0, .5))
paths.append(
P0 * s + (x, y, (i - 1) / 1000.), closed=True, color=(0, 0, 0, .5))

Expand Down
4 changes: 2 additions & 2 deletions examples/demo/gloo/boids.py
Expand Up @@ -159,10 +159,10 @@ def iteration(self, dt):
A = -(V - V.sum(axis=0) / n)

# Repulsion: steer to avoid crowding local flockmates
D, I = cKDTree(P).query(P, 5)
D, idxs = cKDTree(P).query(P, 5)
M = np.repeat(D < 0.05, 3, axis=1).reshape(n, 5, 3)
Z = np.repeat(P, 5, axis=0).reshape(n, 5, 3)
R = -((P[I] - Z) * M).sum(axis=1)
R = -((P[idxs] - Z) * M).sum(axis=1)

# Target : Follow target
T = self.target['position'] - P
Expand Down
8 changes: 4 additions & 4 deletions examples/demo/gloo/imshow.py
Expand Up @@ -19,11 +19,11 @@ def func(x, y):
x = np.linspace(-3.0, 3.0, 512).astype(np.float32)
y = np.linspace(-3.0, 3.0, 512).astype(np.float32)
X, Y = np.meshgrid(x, y)
I = func(X, Y)
idxs = func(X, Y)

# Image normalization
vmin, vmax = I.min(), I.max()
I = (I-vmin)/(vmax-vmin)
vmin, vmax = idxs.min(), idxs.max()
idxs = (idxs - vmin) / (vmax - vmin)


# Colormaps
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self):
self.image['colormaps'].interpolation = 'linear'
self.image['colormaps_shape'] = colormaps.shape[1], colormaps.shape[0]

self.image['image'] = I.astype('float32')
self.image['image'] = idxs.astype('float32')
self.image['image'].interpolation = 'linear'

set_clear_color('black')
Expand Down
12 changes: 6 additions & 6 deletions examples/demo/gloo/imshow_cuts.py
Expand Up @@ -15,11 +15,11 @@ def func(x, y):
x = np.linspace(-3.0, 3.0, 512).astype(np.float32)
y = np.linspace(-3.0, 3.0, 512).astype(np.float32)
X, Y = np.meshgrid(x, y)
I = func(X, Y)
idxs = func(X, Y)

# Image normalization
vmin, vmax = I.min(), I.max()
I = (I-vmin)/(vmax-vmin)
vmin, vmax = idxs.min(), idxs.max()
idxs = (idxs - vmin) / (vmax - vmin)


# Colormaps
Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(self):
self.image['cmap'] = 0 # Colormap index to use
self.image['colormaps'] = colormaps
self.image['n_colormaps'] = colormaps.shape[0]
self.image['image'] = I.astype('float32')
self.image['image'] = idxs.astype('float32')
self.image['image'].interpolation = 'linear'

set_viewport(0, 0, *self.physical_size)
Expand Down Expand Up @@ -174,11 +174,11 @@ def on_mouse_move(self, event):
y_baseline[...] = (xf, -1), (xf, -1), (xf, 1), (xf, 1)

x_profile[1:-1, 0] = np.linspace(-1, 1, 512)
x_profile[1:-1, 1] = yf+0.15*I[y_norm, :]
x_profile[1:-1, 1] = yf + 0.15 * idxs[y_norm, :]
x_profile[0] = x_profile[1]
x_profile[-1] = x_profile[-2]

y_profile[1:-1, 0] = xf+0.15*I[:, x_norm]
y_profile[1:-1, 0] = xf + 0.15 * idxs[:, x_norm]
y_profile[1:-1, 1] = np.linspace(-1, 1, 512)
y_profile[0] = y_profile[1]
y_profile[-1] = y_profile[-2]
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/scene/flow_lines.py
Expand Up @@ -167,8 +167,8 @@ def update_time(self, ev):
def fn(y, x):
dx = x-50
dy = y-30
l = (dx**2 + dy**2)**0.5 + 0.01
return np.array([100 * dy / l**1.7, -100 * dx / l**1.8])
hyp = (dx**2 + dy**2)**0.5 + 0.01
return np.array([100 * dy / hyp**1.7, -100 * dx / hyp**1.8])

field = np.fromfunction(fn, (100, 100)).transpose(1, 2, 0).astype('float32')
field[..., 0] += 10 * np.cos(np.linspace(0, 2 * 3.1415, 100))
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial/gloo/lighted_cube.py
Expand Up @@ -84,10 +84,10 @@ def __init__(self):
self.timer = app.Timer('auto', self.on_timer)

# Build cube data
V, F, O = create_cube()
V, F, outline = create_cube()
vertices = VertexBuffer(V)
self.faces = IndexBuffer(F)
self.outline = IndexBuffer(O)
self.outline = IndexBuffer(outline)

# Build view, model, projection & normal
# --------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial/gloo/outlined_cube.py
Expand Up @@ -49,10 +49,10 @@ def __init__(self):
self.timer = app.Timer('auto', self.on_timer)

# Build cube data
V, I, O = create_cube()
V, I, outline = create_cube()
vertices = VertexBuffer(V)
self.faces = IndexBuffer(I)
self.outline = IndexBuffer(O)
self.outline = IndexBuffer(outline)

# Build program
# --------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions vispy/app/tests/test_app.py
Expand Up @@ -320,12 +320,12 @@ def test_fs():
if (a.backend_name.lower() == 'glfw' or
(a.backend_name.lower() == 'sdl2' and sys.platform == 'darwin')):
raise SkipTest('Backend takes over screen')
with use_log_level('warning', record=True, print_msg=False) as l:
with use_log_level('warning', record=True, print_msg=False) as emit_list:
with Canvas(fullscreen=False) as c:
assert_equal(c.fullscreen, False)
c.fullscreen = True
assert_equal(c.fullscreen, True)
assert_equal(len(l), 0)
assert_equal(len(emit_list), 0)
with use_log_level('warning', record=True, print_msg=False):
# some backends print a warning b/c fullscreen can't be specified
with Canvas(fullscreen=0) as c:
Expand Down
2 changes: 1 addition & 1 deletion vispy/ext/_bundled/freetype.py
Expand Up @@ -230,7 +230,7 @@ def version():

try:
FT_Library_SetLcdFilter = __dll__.FT_Library_SetLcdFilter
except:
except AttributeError:
def FT_Library_SetLcdFilter(*args, **kwargs):
return 0
if version() >= (2, 4, 0):
Expand Down
6 changes: 3 additions & 3 deletions vispy/ext/_bundled/husl.py
Expand Up @@ -131,9 +131,9 @@ def max_chroma_for_LH(L, H):
hrad = H / 360.0 * math.pi * 2.0
lengths = []
for line in get_bounds(L):
l = length_of_ray_until_intersect(hrad, line)
if l is not None:
lengths.append(l)
ray_length = length_of_ray_until_intersect(hrad, line)
if ray_length is not None:
lengths.append(ray_length)
return min(lengths)


Expand Down
8 changes: 4 additions & 4 deletions vispy/ext/cocoapy.py
Expand Up @@ -579,7 +579,7 @@ def __init__(self, method):
try:
self.argtypes = [self.ctype_for_encoding(t)
for t in self.argument_types]
except:
except ValueError:
self.argtypes = None
try:
if self.return_type == b'@':
Expand All @@ -588,7 +588,7 @@ def __init__(self, method):
self.restype = ObjCClass
else:
self.restype = self.ctype_for_encoding(self.return_type)
except:
except ValueError:
self.restype = None
self.func = None

Expand All @@ -606,8 +606,8 @@ def ctype_for_encoding(self, encoding):
elif encoding[0:2] == b'r^' and encoding[2:] in self.typecodes:
return POINTER(self.typecodes[encoding[2:]])
else:
raise Exception('unknown encoding for %s: %s'
% (self.name, encoding))
raise ValueError('unknown encoding for %s: %s'
% (self.name, encoding))

def get_prototype(self):
if self.restype == ObjCInstance or self.restype == ObjCClass:
Expand Down
12 changes: 6 additions & 6 deletions vispy/geometry/_triangulation_debugger.py
Expand Up @@ -138,16 +138,16 @@ def edge_event(self, *args, **kwargs):
(6, 15),
(15, 12.5),
(0, 5)]
l = len(pts)
edges = [(i, (i+1) % l) for i in range(l)]
num_pts = len(pts)
edges = [(i, (i+1) % num_pts) for i in range(num_pts)]
pts += [(21, 21),
(24, 21),
(24, 24),
(21, 24)]
edges += [(l, l+1),
(l+1, l+2),
(l+2, l+3),
(l+3, l)]
edges += [(num_pts, num_pts + 1),
(num_pts + 1, num_pts + 2),
(num_pts + 2, num_pts + 3),
(num_pts + 3, num_pts)]

pts = np.array(pts, dtype=float)
edges = np.array(edges, dtype=int)
Expand Down
24 changes: 12 additions & 12 deletions vispy/geometry/triangulation.py
Expand Up @@ -137,24 +137,24 @@ def triangulate(self):
# and "edge events" (3.4.2).

# get index along front that intersects pts[i]
l = 0
while pts[front[l+1], 0] <= pi[0]:
l += 1
pl = pts[front[l]]
idx = 0
while pts[front[idx+1], 0] <= pi[0]:
idx += 1
pl = pts[front[idx]]

# "(i) middle case"
if pi[0] > pl[0]:
#debug(" mid case")
# Add a single triangle connecting pi,pl,pr
self._add_tri(front[l], front[l+1], i)
front.insert(l+1, i)
self._add_tri(front[idx], front[idx+1], i)
front.insert(idx+1, i)
# "(ii) left case"
else:
#debug(" left case")
# Add triangles connecting pi,pl,ps and pi,pl,pr
self._add_tri(front[l], front[l+1], i)
self._add_tri(front[l-1], front[l], i)
front[l] = i
self._add_tri(front[idx], front[idx+1], i)
self._add_tri(front[idx-1], front[idx], i)
front[idx] = i

#debug(front)

Expand Down Expand Up @@ -217,16 +217,16 @@ def _finalize(self):
#debug("== Fill hull")
front = list(OrderedDict.fromkeys(self._front))

l = len(front) - 2
idx = len(front) - 2
k = 1
while k < l-1:
while k < idx-1:
# if edges lie in counterclockwise direction, then signed area
# is positive
if self._iscounterclockwise(front[k], front[k+1], front[k+2]):
self._add_tri(front[k], front[k+1], front[k+2], legal=False,
source='fill_hull')
front.pop(k+1)
l -= 1
idx -= 1
continue
k += 1

Expand Down
2 changes: 1 addition & 1 deletion vispy/scene/canvas.py
Expand Up @@ -513,7 +513,7 @@ def push_viewport(self, viewport):
self._vp_stack.append(vp)
try:
self.context.set_viewport(*vp)
except:
except Exception:
self._vp_stack.pop()
raise

Expand Down

0 comments on commit 574ddc4

Please sign in to comment.