Skip to content

Commit

Permalink
Fixed PEP8 coding style violations of "unit"folder
Browse files Browse the repository at this point in the history
`pep8 unit/*.py --ignore=E501` tells us everything is ok.

As part of http://24pullrequests.com
  • Loading branch information
habi committed Dec 16, 2014
1 parent 8aed22d commit e4dc869
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 184 deletions.
32 changes: 17 additions & 15 deletions unit/agg_memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"""

from __future__ import print_function
import sys, time, os
import os
from matplotlib.ft2font import FT2Font
from numpy.random import rand
from matplotlib.backend_bases import GraphicsContextBase
from matplotlib.backends._backend_agg import RendererAgg


def report_memory(i):
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
Expand All @@ -20,40 +21,41 @@ def report_memory(i):
N = 200
for i in range(N):
gc = GraphicsContextBase()
gc.set_clip_rectangle( [20,20,20,20] )
o = RendererAgg(400,400, 72)
gc.set_clip_rectangle([20, 20, 20, 20])
o = RendererAgg(400, 400, 72)

for j in range(50):
xs = [400*int(rand()) for k in range(8)]
ys = [400*int(rand()) for k in range(8)]
rgb = (1,0,0)
xs = [400 * int(rand()) for k in range(8)]
ys = [400 * int(rand()) for k in range(8)]
rgb = (1, 0, 0)
pnts = zip(xs, ys)
o.draw_polygon(gc, rgb, pnts) # no such method??
o.draw_polygon(gc, None, pnts)

for j in range(50):
x = [400*int(rand()) for k in range(4)]
y = [400*int(rand()) for k in range(4)]
o.draw_lines( gc, x, y)
x = [400 * int(rand()) for k in range(4)]
y = [400 * int(rand()) for k in range(4)]
o.draw_lines(gc, x, y)

for j in range(50):
args = [400*int(rand()) for k in range(4)]
rgb = (1,0,0)
args = [400 * int(rand()) for k in range(4)]
rgb = (1, 0, 0)
o.draw_rectangle(gc, rgb, *args)

if 1: # add text
if 1: # add text
font = FT2Font(fname)
font.clear()
font.set_text('hi mom', 60)
font.set_size(12, 72)
o.draw_text_image(font.get_image(), 30, 40, gc)

o.write_png('aggtest%d.png'%i)
o.write_png('aggtest%d.png' % i)
val = report_memory(i)
if i==1: start = val
if i == 1:
start = val

end = val
print('Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N)))
print('Average memory consumed per loop: %1.4f\n' % ((end - start) / float(N)))

# w/o text and w/o write_png: Average memory consumed per loop: 0.02
# w/o text and w/ write_png : Average memory consumed per loop: 0.3400
Expand Down
5 changes: 3 additions & 2 deletions unit/compare_backend_driver_results.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
import sys


def parse_results(filename):
results = {}
fd = open(filename, 'r')
Expand All @@ -22,11 +23,11 @@ def check_results_are_compatible(results_a, results_b):
for section in results_a.keys():
if not section in results_b:
raise RuntimeError("Backend '%s' in first set, but not in second" % section)

for section in results_b.keys():
if not section in results_a:
raise RuntimeError("Backend '%s' in second set, but not in first" % section)


def compare_results(results_a, results_b):
check_results_are_compatible(results_a, results_b)
Expand Down
124 changes: 57 additions & 67 deletions unit/ellipse_large.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# This example can be boiled down to a more simplistic example
# to show the problem, but bu including the upper and lower
# to show the problem, but including the upper and lower
# bound ellipses, it demonstrates how significant this error
# is to our plots.

Expand All @@ -14,129 +14,121 @@
y = 6720.850

# get is the radius of a circle through this point
r = math.sqrt( x*x+y*y )
r = math.sqrt(x * x + y * y)

# show some comparative circles
delta = 6


##################################################
def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ):
xs = []
ys = []
incr = 2.0*math.pi / numpoints
incrTheta = 0.0
while incrTheta <= (2.0*math.pi):
a = major * math.cos( incrTheta )
b = minor * math.sin( incrTheta )
l = math.sqrt( ( a**2 ) + ( b**2 ) )
phi = math.atan2( b, a )
incrTheta += incr

xs.append( x + ( l * math.cos( theta + phi ) ) )
ys.append( y + ( l * math.sin( theta + phi ) ) )
# end while

incrTheta = 2.0*math.pi
a = major * math.cos( incrTheta )
b = minor * math.sin( incrTheta )
l = sqrt( ( a**2 ) + ( b**2 ) )
phi = math.atan2( b, a )
xs.append( x + ( l * math.cos( theta + phi ) ) )
ys.append( y + ( l * math.sin( theta + phi ) ) )

ellipseLine = ax.plot( xs, ys, **kwargs )


def custom_ellipse(ax, x, y, major, minor, theta, numpoints=750, **kwargs):
xs = []
ys = []
incr = 2.0 * math.pi / numpoints
incrTheta = 0.0
while incrTheta <= (2.0 * math.pi):
a = major * math.cos(incrTheta)
b = minor * math.sin(incrTheta)
l = math.sqrt((a ** 2) + (b ** 2))
phi = math.atan2(b, a)
incrTheta += incr

xs.append(x + (l * math.cos(theta + phi)))
ys.append(y + (l * math.sin(theta + phi)))
# end while

incrTheta = 2.0 * math.pi
a = major * math.cos(incrTheta)
b = minor * math.sin(incrTheta)
l = sqrt((a ** 2) + (b ** 2))
phi = math.atan2(b, a)
xs.append(x + (l * math.cos(theta + phi)))
ys.append(y + (l * math.sin(theta + phi)))

ellipseLine = ax.plot(xs, ys, **kwargs)


##################################################
# make the axes
ax1 = subplot( 311, aspect='equal' )
ax1.set_aspect( 'equal', 'datalim' )
ax1 = subplot(311, aspect='equal')
ax1.set_aspect('equal', 'datalim')

# make the lower-bound ellipse
diam = (r - delta) * 2.0
lower_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen" )
ax1.add_patch( lower_ellipse )
lower_ellipse = Ellipse((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen")
ax1.add_patch(lower_ellipse)

# make the target ellipse
diam = r * 2.0
target_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred" )
ax1.add_patch( target_ellipse )
target_ellipse = Ellipse((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred")
ax1.add_patch(target_ellipse)

# make the upper-bound ellipse
diam = (r + delta) * 2.0
upper_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue" )
ax1.add_patch( upper_ellipse )
upper_ellipse = Ellipse((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue")
ax1.add_patch(upper_ellipse)

# make the target
diam = delta * 2.0
target = Ellipse( (x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208" )
ax1.add_patch( target )
target = Ellipse((x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208")
ax1.add_patch(target)

# give it a big marker
ax1.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
ax1.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)

##################################################
# make the axes
ax = subplot( 312, aspect='equal' , sharex=ax1, sharey=ax1)
ax.set_aspect( 'equal', 'datalim' )
ax = subplot(312, aspect='equal', sharex=ax1, sharey=ax1)
ax.set_aspect('equal', 'datalim')

# make the lower-bound arc
diam = (r - delta) * 2.0
lower_arc = Arc( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen" )
ax.add_patch( lower_arc )
lower_arc = Arc((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen")
ax.add_patch(lower_arc)

# make the target arc
diam = r * 2.0
target_arc = Arc( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred" )
ax.add_patch( target_arc )
target_arc = Arc((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred")
ax.add_patch(target_arc)

# make the upper-bound arc
diam = (r + delta) * 2.0
upper_arc = Arc( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue" )
ax.add_patch( upper_arc )
upper_arc = Arc((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue")
ax.add_patch(upper_arc)

# make the target
diam = delta * 2.0
target = Arc( (x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208" )
ax.add_patch( target )
target = Arc((x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208")
ax.add_patch(target)

# give it a big marker
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )




ax.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)

##################################################
# now lets do the same thing again using a custom ellipse function



# make the axes
ax = subplot( 313, aspect='equal', sharex=ax1, sharey=ax1 )
ax.set_aspect( 'equal', 'datalim' )
ax = subplot(313, aspect='equal', sharex=ax1, sharey=ax1)
ax.set_aspect('equal', 'datalim')

# make the lower-bound ellipse
custom_ellipse( ax, 0.0, 0.0, r-delta, r-delta, 0.0, color="darkgreen" )
custom_ellipse(ax, 0.0, 0.0, r - delta, r - delta, 0.0, color="darkgreen")

# make the target ellipse
custom_ellipse( ax, 0.0, 0.0, r, r, 0.0, color="darkred" )
custom_ellipse(ax, 0.0, 0.0, r, r, 0.0, color="darkred")

# make the upper-bound ellipse
custom_ellipse( ax, 0.0, 0.0, r+delta, r+delta, 0.0, color="darkblue" )
custom_ellipse(ax, 0.0, 0.0, r + delta, r + delta, 0.0, color="darkblue")

# make the target
custom_ellipse( ax, x, y, delta, delta, 0.0, color="#BB1208" )
custom_ellipse(ax, x, y, delta, delta, 0.0, color="#BB1208")

# give it a big marker
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
ax.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)


# give it a big marker
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
ax.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)

##################################################
# lets zoom in to see the area of interest
Expand All @@ -146,5 +138,3 @@ def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ):

savefig("ellipse")
show()


10 changes: 5 additions & 5 deletions unit/legend_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

Ntests = 3
t = np.arange(0.0, 1.0, 0.05)
s = np.sin(2*np.pi*t)
s = np.sin(2 * np.pi * t)

# scatter creates a RegPolyCollection
fig = figure()
ax = fig.add_subplot(Ntests, 1, 1)
N = 100
x, y = 0.9*np.random.rand(2,N)
area = np.pi*(10 * np.random.rand(N))**2 # 0 to 10 point radiuses
ax.scatter(x,y,s=area, marker='^', c='r', label='scatter')
x, y = 0.9 * np.random.rand(2, N)
area = np.pi * (10 * np.random.rand(N)) ** 2 # 0 to 10 point radiuses
ax.scatter(x, y, s=area, marker='^', c='r', label='scatter')
ax.legend()

# vlines creates a LineCollection
ax = fig.add_subplot(Ntests, 1, 2)
ax.vlines(t, [0], np.sin(2*np.pi*t), label='vlines')
ax.vlines(t, [0], np.sin(2 * np.pi * t), label='vlines')
ax.legend()

# vlines creates a LineCollection
Expand Down
6 changes: 3 additions & 3 deletions unit/longs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from __future__ import print_function

from pylab import *
x = arange(1000) + 2**32
x = arange(1000) + 2 ** 32

subplot(211)
plot(x,x)
plot(x, x)

subplot(212)
loglog(x,x)
loglog(x, x)

show()
11 changes: 5 additions & 6 deletions unit/memleak_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'''
from __future__ import print_function
import os, sys, time
import gc
from optparse import OptionParser

Expand Down Expand Up @@ -52,7 +51,7 @@

print('# columns are: iteration, OS memory (k), number of python objects')
print('#')
for i in range(indEnd+1):
for i in range(indEnd + 1):

fig = pylab.figure()
fig.savefig('test') # This seems to just slow down the testing.
Expand All @@ -63,9 +62,9 @@
if options.verbose:
if i % 10 == 0:
#print ("iter: %4d OS memory: %8d Python objects: %8d" %
print ("%4d %8d %8d" %
(i, val, len(gc.get_objects())))
if i==indStart: start = val # wait a few cycles for memory usage to stabilize
print("%4d %8d %8d" % (i, val, len(gc.get_objects())))
if i == indStart:
start = val # wait a few cycles for memory usage to stabilize

gc.collect()
end = val
Expand Down Expand Up @@ -98,7 +97,7 @@

print('# Averaging over loops %d to %d' % (indStart, indEnd))
print('# Memory went from %dk to %dk' % (start, end))
print('# Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)))
print('# Average memory consumed per loop: %1.4fk bytes\n' % ((end - start) / float(indEnd - indStart)))

if options.cycles:
cbook.print_cycles(gc.garbage)
Loading

0 comments on commit e4dc869

Please sign in to comment.