Skip to content

Commit

Permalink
Merge pull request #7197 from jarrodmillman/black
Browse files Browse the repository at this point in the history
Use Black
  • Loading branch information
jarrodmillman committed Oct 18, 2023
2 parents e6cb9a9 + 257e4a9 commit 7bd8e2a
Show file tree
Hide file tree
Showing 448 changed files with 20,741 additions and 13,566 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ f4978b11499e499cc006c417b3bf0ccf245ca72c

# Adopt ruff and cython-lint (gh-6729)
b22ecff8d52eeb59e5d1d2e7fcc7962b4a0a84ce

# Adopt black (gh-7197)
659af605da92732b57b7862f78fe77f3fd161fd0
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ repos:
rev: v0.0.292 # v0.0.261
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --show-fixes, --exit-non-zero-on-fix]

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0 # v0.15.0
hooks:
- id: cython-lint
args: [--no-pycodestyle, --max-line-length=88]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black

- repo: local
hooks:
- id: generate_requirements.py
Expand Down
17 changes: 9 additions & 8 deletions .spin/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
@click.option(
"--install-deps/--no-install-deps",
default=False,
help="Install dependencies before building"
help="Install dependencies before building",
)
@click.pass_context
def docs(ctx, sphinx_target, clean, first_build, jobs, sphinx_gallery_plot, install_deps):
def docs(
ctx, sphinx_target, clean, first_build, jobs, sphinx_gallery_plot, install_deps
):
"""📖 Build documentation
By default, SPHINXOPTS="-W", raising errors on warnings.
Expand Down Expand Up @@ -77,14 +79,11 @@ def asv(asv_args):

@click.command()
def sdist():
"""📦 Build a source distribution in `dist/`.
"""
"""📦 Build a source distribution in `dist/`."""
util.run(['python', '-m', 'build', '.', '--sdist'])


@click.command(context_settings={
'ignore_unknown_options': True
})
@click.command(context_settings={'ignore_unknown_options': True})
@click.argument("ipython_args", metavar='', nargs=-1)
@click.pass_context
def ipython(ctx, ipython_args):
Expand All @@ -101,6 +100,8 @@ def ipython(ctx, ipython_args):
r"import skimage as ski; "
r"print(f'\nPreimported scikit-image {ski.__version__} as ski')"
)
ctx.params['ipython_args'] = (f"--TerminalIPythonApp.exec_lines={preimport}",) + ipython_args
ctx.params['ipython_args'] = (
f"--TerminalIPythonApp.exec_lines={preimport}",
) + ipython_args

ctx.forward(meson.ipython)
10 changes: 5 additions & 5 deletions benchmarks/benchmark_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class ExposureSuite:
"""Benchmark for exposure routines in scikit-image."""

def setup(self):
self.image_u8 = data.moon()
self.image = img_as_float(self.image_u8)
Expand All @@ -29,8 +30,8 @@ def time_equalize_adapthist(self):
exposure.equalize_adapthist(self.image, clip_limit=0.03)

def time_rescale_intensity(self):
exposure.rescale_intensity(self.image,
in_range=(self.p2, self.p98))
exposure.rescale_intensity(self.image, in_range=(self.p2, self.p98))

def time_histogram(self):
# Running it 10 times to achieve significant performance time.
for i in range(10):
Expand All @@ -42,7 +43,6 @@ def time_gamma_adjust_u8(self):


class MatchHistogramsSuite:

param_names = ["shape", "dtype", "multichannel"]
params = [
((64, 64), (256, 256), (1024, 1024)),
Expand All @@ -60,13 +60,13 @@ def _tile_to_shape(self, image, shape, multichannel):
return image[sl]

"""Benchmark for exposure routines in scikit-image."""

def setup(self, shape, dtype, multichannel):
self.image = data.moon().astype(dtype, copy=False)
self.reference = data.camera().astype(dtype, copy=False)

self.image = self._tile_to_shape(self.image, shape, multichannel)
self.reference = self._tile_to_shape(self.reference, shape,
multichannel)
self.reference = self._tile_to_shape(self.reference, shape, multichannel)
channel_axis = -1 if multichannel else None
self.kwargs = {'channel_axis': channel_axis}

Expand Down
10 changes: 6 additions & 4 deletions benchmarks/benchmark_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@

class FeatureSuite:
"""Benchmark for feature routines in scikit-image."""

def setup(self):
# Use a real-world image for more realistic features, but tile it to
# get a larger size for the benchmark.
self.image = np.tile(color.rgb2gray(data.astronaut()), (4, 4))
self.image_ubyte = util.img_as_ubyte(self.image)
self.keypoints = feature.corner_peaks(
self.image, min_distance=5, threshold_rel=0.1
)
self.image, min_distance=5, threshold_rel=0.1
)

def time_canny(self):
feature.canny(self.image)

def time_glcm(self):
pi = np.pi
feature.greycomatrix(self.image_ubyte, distances=[1, 2],
angles=[0, pi/4, pi/2, 3*pi/4])
feature.greycomatrix(
self.image_ubyte, distances=[1, 2], angles=[0, pi / 4, pi / 2, 3 * pi / 4]
)

def time_brief(self):
extractor = feature.BRIEF()
Expand Down
5 changes: 4 additions & 1 deletion benchmarks/benchmark_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class FiltersSuite:
"""Benchmark for filter routines in scikit-image."""

def setup(self):
self.image = np.random.random((4000, 4000))
self.image[:2000, :2000] += 1
Expand All @@ -19,6 +20,7 @@ def time_sobel(self):

class FiltersSobel3D:
"""Benchmark for 3d sobel filters."""

def setup(self):
try:
filters.sobel(np.ones((8, 8, 8)))
Expand All @@ -32,8 +34,10 @@ def time_sobel_3d(self):

class MultiOtsu:
"""Benchmarks for MultiOtsu threshold."""

param_names = ['classes']
params = [3, 4, 5]

def setup(self, *args):
self.image = data.camera()

Expand Down Expand Up @@ -63,7 +67,6 @@ def peakmem_threshold_multiotsu(self, classes):
class ThresholdSauvolaSuite:
"""Benchmark for transform routines in scikit-image."""


def setup(self):
self.image = np.zeros((2000, 2000), dtype=np.uint8)
self.image3D = np.zeros((30, 300, 300), dtype=np.uint8)
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/benchmark_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@

class GraphSuite:
"""Benchmark for pixel graph routines in scikit-image."""

def setup(self):
retina = color.rgb2gray(data.retina())
t0, _ = filters.threshold_multiotsu(retina, classes=3)
mask = (retina > t0)
mask = retina > t0
vessels = filters.sato(retina, sigmas=range(1, 10)) * mask
thresholded = filters.apply_hysteresis_threshold(vessels, 0.01, 0.03)
labeled = ndi.label(thresholded)[0]
largest_nonzero_label = np.argmax(np.bincount(labeled[labeled > 0]))
binary = (labeled == largest_nonzero_label)
binary = labeled == largest_nonzero_label
self.skeleton = morphology.skeletonize(binary)

labeled2 = ndi.label(thresholded[::2, ::2])[0]
largest_nonzero_label2 = np.argmax(np.bincount(labeled2[labeled2 > 0]))
binary2 = (labeled2 == largest_nonzero_label2)
binary2 = labeled2 == largest_nonzero_label2
small_skeleton = morphology.skeletonize(binary2)
self.g, self.n = graph.pixel_graph(small_skeleton, connectivity=2)

Expand Down
11 changes: 9 additions & 2 deletions benchmarks/benchmark_import_time.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from subprocess import run, PIPE
from sys import executable


class ImportSuite:
"""Benchmark the time it takes to import various modules"""

params = [
'numpy',
'skimage',
Expand All @@ -12,9 +14,14 @@ class ImportSuite:
'skimage.io',
]
param_names = ["package_name"]

def setup(self, package_name):
pass

def time_import(self, package_name):
run(executable + ' -c "import ' + package_name + '"',
capture_output=True, stdin=PIPE, shell=True)
run(
executable + ' -c "import ' + package_name + '"',
capture_output=True,
stdin=PIPE,
shell=True,
)
23 changes: 13 additions & 10 deletions benchmarks/benchmark_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@


class InterpolationResize:

param_names = ['new_shape', 'order', 'mode', 'dtype', 'anti_aliasing']
params = [
((500, 800), (2000, 4000), (80, 80, 80), (150, 150, 150)), # new_shape
(0, 1, 3, 5), # order
(0, 1, 3, 5), # order
('symmetric',), # mode
(np.float64, ), # dtype
(True,), # anti_aliasing
(np.float64,), # dtype
(True,), # anti_aliasing
]

"""Benchmark for filter routines in scikit-image."""

def setup(self, new_shape, order, mode, dtype, anti_aliasing):
ndim = len(new_shape)
if ndim == 2:
Expand All @@ -25,17 +25,20 @@ def setup(self, new_shape, order, mode, dtype, anti_aliasing):
self.image = image.astype(dtype, copy=False)

def time_resize(self, new_shape, order, mode, dtype, anti_aliasing):
transform.resize(self.image, new_shape, order=order, mode=mode,
anti_aliasing=anti_aliasing)
transform.resize(
self.image, new_shape, order=order, mode=mode, anti_aliasing=anti_aliasing
)

def time_rescale(self, new_shape, order, mode, dtype, anti_aliasing):
scale = tuple(s2 / s1 for s2, s1 in zip(new_shape, self.image.shape))
transform.rescale(self.image, scale, order=order, mode=mode,
anti_aliasing=anti_aliasing)
transform.rescale(
self.image, scale, order=order, mode=mode, anti_aliasing=anti_aliasing
)

def peakmem_resize(self, new_shape, order, mode, dtype, anti_aliasing):
transform.resize(self.image, new_shape, order=order, mode=mode,
anti_aliasing=anti_aliasing)
transform.resize(
self.image, new_shape, order=order, mode=mode, anti_aliasing=anti_aliasing
)

def peakmem_reference(self, *args):
"""Provide reference for memory measurement with empty benchmark.
Expand Down
22 changes: 13 additions & 9 deletions benchmarks/benchmark_measure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from skimage import data, filters, measure

try:
from skimage.measure._regionprops import PROP_VALS
except ImportError:
Expand All @@ -17,7 +18,6 @@ def init_regionprops_data():


class RegionpropsTableIndividual:

param_names = ['prop']
params = sorted(list(PROP_VALS))

Expand All @@ -30,14 +30,14 @@ def setup(self, prop):
self.label_image, self.intensity_image = init_regionprops_data()

def time_single_region_property(self, prop):
measure.regionprops_table(self.label_image, self.intensity_image,
properties=[prop], cache=True)
measure.regionprops_table(
self.label_image, self.intensity_image, properties=[prop], cache=True
)

# omit peakmem tests to save time (memory usage was minimal)


class RegionpropsTableAll:

param_names = ['cache']
params = (False, True)

Expand All @@ -50,19 +50,23 @@ def setup(self, cache):
self.label_image, self.intensity_image = init_regionprops_data()

def time_regionprops_table_all(self, cache):
measure.regionprops_table(self.label_image, self.intensity_image,
properties=PROP_VALS, cache=cache)
measure.regionprops_table(
self.label_image, self.intensity_image, properties=PROP_VALS, cache=cache
)

# omit peakmem tests to save time (memory usage was minimal)


class MomentsSuite:
params = ([(64, 64), (4096, 2048), (32, 32, 32), (256, 256, 192)],
[np.uint8, np.float32, np.float64],
[1, 2, 3])
params = (
[(64, 64), (4096, 2048), (32, 32, 32), (256, 256, 192)],
[np.uint8, np.float32, np.float64],
[1, 2, 3],
)
param_names = ['shape', 'dtype', 'order']

"""Benchmark for filter routines in scikit-image."""

def setup(self, shape, dtype, *args):
rng = np.random.default_rng(1234)
if np.dtype(dtype).kind in 'iu':
Expand Down

0 comments on commit 7bd8e2a

Please sign in to comment.