Skip to content

Commit

Permalink
COSMIT pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
amueller committed Jun 29, 2012
1 parent b891a7c commit f7b3d80
Show file tree
Hide file tree
Showing 98 changed files with 1,025 additions and 866 deletions.
6 changes: 5 additions & 1 deletion skimage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
except ImportError:
__version__ = "unbuilt-dev"


def _setup_test(verbose=False):
import gzip
import functools
Expand Down Expand Up @@ -93,6 +94,7 @@ def _setup_test(verbose=False):
except NameError:
pass


def get_log(name=None):
"""Return a console logger.
Expand Down Expand Up @@ -120,11 +122,13 @@ def get_log(name=None):
log = logging.getLogger(name)
return log


def _setup_log():
"""Configure root logger.
"""
import logging, sys
import logging
import sys

log = logging.getLogger()

Expand Down
9 changes: 5 additions & 4 deletions skimage/_build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import sys
import os
import shutil
import hashlib
import subprocess
import platform


def cython(pyx_files, working_path=''):
"""Use Cython to convert the given files to C.
Expand Down Expand Up @@ -39,17 +38,18 @@ def cython(pyx_files, working_path=''):
print(cmd)

try:
status = subprocess.call(['cython', '-o', c_file, pyxfile])
subprocess.call(['cython', '-o', c_file, pyxfile])
except WindowsError:
# On Windows cython.exe may be missing if Cython was installed
# via distutils. Run the cython.py script instead.
status = subprocess.call(
subprocess.call(
[sys.executable,
os.path.join(os.path.dirname(sys.executable),
'Scripts', 'cython.py'),
'-o', c_file, pyxfile],
shell=True)


def _md5sum(f):
m = hashlib.new('md5')
while True:
Expand All @@ -60,6 +60,7 @@ def _md5sum(f):
m.update(d)
return m.hexdigest()


def _changed(filename):
"""Compare the hash of a Cython file to the cached hash value on disk.
Expand Down
2 changes: 1 addition & 1 deletion skimage/color/colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def rgb2grey(rgb):
Raises
------
ValueError
If `rgb2grey` is not a 3-D array of shape (.., .., 3) or
If `rgb2grey` is not a 3-D array of shape (.., .., 3) or
(.., .., 4).
References
Expand Down
43 changes: 19 additions & 24 deletions skimage/color/tests/test_colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def test_rgb2hsv_error_grayscale(self):
self.assertRaises(ValueError, rgb2hsv, self.img_grayscale)

def test_rgb2hsv_error_one_element(self):
self.assertRaises(ValueError, rgb2hsv, self.img_rgb[0,0])

self.assertRaises(ValueError, rgb2hsv, self.img_rgb[0, 0])

# HSV to RGB
def test_hsv2rgb_conversion(self):
Expand All @@ -74,19 +73,18 @@ def test_hsv2rgb_error_grayscale(self):
self.assertRaises(ValueError, hsv2rgb, self.img_grayscale)

def test_hsv2rgb_error_one_element(self):
self.assertRaises(ValueError, hsv2rgb, self.img_rgb[0,0])

self.assertRaises(ValueError, hsv2rgb, self.img_rgb[0, 0])

# RGB to XYZ
def test_rgb2xyz_conversion(self):
gt = np.array([[[ 0.950456, 1. , 1.088754],
[ 0.538003, 0.787329, 1.06942 ],
[ 0.592876, 0.28484 , 0.969561],
[ 0.180423, 0.072169, 0.950227]],
[[ 0.770033, 0.927831, 0.138527],
[ 0.35758 , 0.71516 , 0.119193],
[ 0.412453, 0.212671, 0.019334],
[ 0. , 0. , 0. ]]])
gt = np.array([[[0.950456, 1., 1.088754],
[0.538003, 0.787329, 1.06942],
[0.592876, 0.28484, 0.969561],
[0.180423, 0.072169, 0.950227]],
[[0.770033, 0.927831, 0.138527],
[0.35758, 0.71516, 0.119193],
[0.412453, 0.212671, 0.019334],
[0., 0., 0.]]])
assert_almost_equal(rgb2xyz(self.colbars_array), gt)

# stop repeating the "raises" checks for all other functions that are
Expand All @@ -95,29 +93,26 @@ def test_rgb2xyz_error_grayscale(self):
self.assertRaises(ValueError, rgb2xyz, self.img_grayscale)

def test_rgb2xyz_error_one_element(self):
self.assertRaises(ValueError, rgb2xyz, self.img_rgb[0,0])

self.assertRaises(ValueError, rgb2xyz, self.img_rgb[0, 0])

# XYZ to RGB
def test_xyz2rgb_conversion(self):
# only roundtrip test, we checked rgb2xyz above already
assert_almost_equal(xyz2rgb(rgb2xyz(self.colbars_array)),
self.colbars_array)


# RGB to RGB CIE
def test_rgb2rgbcie_conversion(self):
gt = np.array([[[ 0.1488856 , 0.18288098, 0.19277574],
[ 0.01163224, 0.16649536, 0.18948516],
[ 0.12259182, 0.03308008, 0.17298223],
gt = np.array([[[0.1488856, 0.18288098, 0.19277574],
[0.01163224, 0.16649536, 0.18948516],
[0.12259182, 0.03308008, 0.17298223],
[-0.01466154, 0.01669446, 0.16969164]],
[[ 0.16354714, 0.16618652, 0.0230841 ],
[ 0.02629378, 0.1498009 , 0.01979351],
[ 0.13725336, 0.01638562, 0.00329059],
[ 0. , 0. , 0. ]]])
[[0.16354714, 0.16618652, 0.0230841],
[0.02629378, 0.1498009, 0.01979351],
[0.13725336, 0.01638562, 0.00329059],
[0., 0., 0.]]])
assert_almost_equal(rgb2rgbcie(self.colbars_array), gt)


# RGB CIE to RGB
def test_rgbcie2rgb_conversion(self):
# only roundtrip test, we checked rgb2rgbcie above already
Expand Down Expand Up @@ -151,6 +146,7 @@ def test_rgb2grey(self):

assert_equal(g.shape, (1, 1))


def test_gray2rgb():
x = np.array([0, 0.5, 1])
assert_raises(ValueError, gray2rgb, x)
Expand All @@ -170,4 +166,3 @@ def test_gray2rgb():

if __name__ == "__main__":
run_module_suite()

7 changes: 7 additions & 0 deletions skimage/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..io import imread
from skimage import data_dir


def load(f):
"""Load an image file located in the data directory.
Expand All @@ -26,13 +27,15 @@ def load(f):
"""
return imread(_os.path.join(data_dir, f))


def camera():
"""Gray-level "camera" image, often used for segmentation
and denoising examples.
"""
return load("camera.png")


def lena():
"""Colour "Lena" image.
Expand All @@ -44,6 +47,7 @@ def lena():
"""
return load("lena.png")


def text():
""" Gray-level "text" image used for corner detection.
Expand All @@ -68,6 +72,7 @@ def checkerboard():
"""
return load("chessboard_GRAY.png")


def coins():
"""Greek coins from Pompeii.
Expand All @@ -88,6 +93,7 @@ def coins():
"""
return load("coins.png")


def moon():
"""Surface of the moon.
Expand All @@ -97,6 +103,7 @@ def moon():
"""
return load("moon.png")


def page():
"""Scanned page.
Expand Down
4 changes: 3 additions & 1 deletion skimage/data/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
from numpy.testing import assert_equal, assert_array_equal
import numpy as np


def test_lena():
""" Test that "Lena" image can be loaded. """
lena = data.lena()
assert_equal(lena.shape, (512, 512, 3))


def test_camera():
""" Test that "camera" image can be loaded. """
cameraman = data.camera()
assert_equal(cameraman.ndim, 2)


def test_checkerboard():
""" Test that checkerboard image can be loaded. """
checkerboard = data.checkerboard()

if __name__ == "__main__":
from numpy.testing import run_module_suite
run_module_suite()

13 changes: 7 additions & 6 deletions skimage/draw/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

base_path = os.path.abspath(os.path.dirname(__file__))


def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs

Expand All @@ -20,11 +21,11 @@ def configuration(parent_package='', top_path=None):

if __name__ == '__main__':
from numpy.distutils.core import setup
setup(maintainer = 'scikits-image developers',
author = 'scikits-image developers',
maintainer_email = 'scikits-image@googlegroups.com',
description = 'Drawing',
url = 'https://github.com/scikits-image/scikits-image',
license = 'SciPy License (BSD Style)',
setup(maintainer='scikits-image developers',
author='scikits-image developers',
maintainer_email='scikits-image@googlegroups.com',
description='Drawing',
url='https://github.com/scikits-image/scikits-image',
license='SciPy License (BSD Style)',
**(configuration(top_path='').todict())
)
32 changes: 20 additions & 12 deletions skimage/draw/tests/test_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_line_horizontal():

assert_array_equal(img, img_)


def test_line_vertical():
img = np.zeros((10, 10))

Expand All @@ -26,6 +27,7 @@ def test_line_vertical():

assert_array_equal(img, img_)


def test_line_reverse():
img = np.zeros((10, 10))

Expand All @@ -37,6 +39,7 @@ def test_line_reverse():

assert_array_equal(img, img_)


def test_line_diag():
img = np.zeros((5, 5))

Expand All @@ -52,20 +55,21 @@ def test_polygon_rectangle():
img = np.zeros((10, 10), 'uint8')
poly = np.array(((1, 1), (4, 1), (4, 4), (1, 4), (1, 1)))

rr, cc = polygon(poly[:,0], poly[:,1])
img[rr,cc] = 1
rr, cc = polygon(poly[:, 0], poly[:, 1])
img[rr, cc] = 1

img_ = np.zeros((10, 10))
img_[1:4,1:4] = 1
img_[1:4, 1:4] = 1

assert_array_equal(img, img_)


def test_polygon_rectangle_angular():
img = np.zeros((10, 10), 'uint8')
poly = np.array(((0, 3), (4, 7), (7, 4), (3, 0), (0, 3)))

rr, cc = polygon(poly[:,0], poly[:,1])
img[rr,cc] = 1
rr, cc = polygon(poly[:, 0], poly[:, 1])
img[rr, cc] = 1

img_ = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand All @@ -82,12 +86,13 @@ def test_polygon_rectangle_angular():

assert_array_equal(img, img_)


def test_polygon_parallelogram():
img = np.zeros((10, 10), 'uint8')
poly = np.array(((1, 1), (5, 1), (7, 6), (3, 6), (1, 1)))

rr, cc = polygon(poly[:,0], poly[:,1])
img[rr,cc] = 1
rr, cc = polygon(poly[:, 0], poly[:, 1])
img[rr, cc] = 1

img_ = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand All @@ -104,23 +109,25 @@ def test_polygon_parallelogram():

assert_array_equal(img, img_)


def test_polygon_exceed():
img = np.zeros((10, 10), 'uint8')
poly = np.array(((1, -1), (100, -1), (100, 100), (1, 100), (1, 1)))

rr, cc = polygon(poly[:,0], poly[:,1], img.shape)
img[rr,cc] = 1
rr, cc = polygon(poly[:, 0], poly[:, 1], img.shape)
img[rr, cc] = 1

img_ = np.zeros((10, 10))
img_[1:,:] = 1
img_[1:, :] = 1

assert_array_equal(img, img_)


def test_circle():
img = np.zeros((15, 15), 'uint8')

rr, cc = circle(7, 7, 6)
img[rr,cc] = 1
img[rr, cc] = 1

img_ = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand All @@ -142,11 +149,12 @@ def test_circle():

assert_array_equal(img, img_)


def test_ellipse():
img = np.zeros((15, 15), 'uint8')

rr, cc = ellipse(7, 7, 3, 7)
img[rr,cc] = 1
img[rr, cc] = 1

img_ = np.array(
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand Down
1 change: 0 additions & 1 deletion skimage/exposure/exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,3 @@ def rescale_intensity(image, in_range=None, out_range=None):

image = (image - imin) / float(imax - imin)
return dtype(image * (omax - omin) + omin)

1 change: 0 additions & 1 deletion skimage/exposure/tests/test_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ def test_rescale_out_range():
if __name__ == '__main__':
from numpy import testing
testing.run_module_suite()

Loading

0 comments on commit f7b3d80

Please sign in to comment.