From d55c97677d0353e4c3e7f0411acda9d9bb85f825 Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 2 Jan 2024 09:54:25 -0800 Subject: [PATCH] ruff: remove unused imports and fix small typos. --- gunpowder/array.py | 2 -- gunpowder/batch.py | 3 +- .../contrib/nodes/add_blobs_from_points.py | 2 +- .../nodes/add_boundary_distance_gradients.py | 3 +- .../nodes/add_gt_mask_exclusive_zone.py | 3 +- .../nodes/add_nonsymmetric_affinities.py | 2 -- gunpowder/contrib/nodes/hdf5_points_source.py | 3 -- gunpowder/ext/__init__.py | 28 +++++++++---------- gunpowder/graph.py | 3 +- gunpowder/nodes/crop.py | 1 - gunpowder/nodes/elastic_augment.py | 1 - gunpowder/nodes/exclude_labels.py | 2 +- gunpowder/nodes/grow_boundary.py | 1 - gunpowder/nodes/klb_source.py | 1 - gunpowder/nodes/merge_provider.py | 1 - gunpowder/nodes/pad.py | 1 - gunpowder/nodes/precache.py | 3 -- gunpowder/nodes/rasterize_graph.py | 2 -- gunpowder/nodes/shift_augment.py | 1 - gunpowder/nodes/specified_location.py | 2 -- gunpowder/nodes/squeeze.py | 1 - gunpowder/nodes/unsqueeze.py | 1 - gunpowder/producer_pool.py | 2 -- gunpowder/provider_spec.py | 2 -- tests/cases/add_affinities.py | 4 --- tests/cases/dvid_source.py | 1 - tests/cases/elastic_augment_points.py | 2 -- tests/cases/expected_failures.py | 2 +- tests/cases/intensity_scale_shift.py | 1 - tests/cases/jax_train.py | 5 +--- tests/cases/noise_augment.py | 1 - tests/cases/random_location.py | 1 - tests/cases/resample.py | 1 - tests/cases/simple_augment.py | 2 -- tests/cases/snapshot.py | 2 -- tests/cases/tensorflow_train.py | 2 +- tests/cases/zarr_read_write.py | 2 +- 37 files changed, 24 insertions(+), 73 deletions(-) diff --git a/gunpowder/array.py b/gunpowder/array.py index 0177cf5a..a8da1322 100644 --- a/gunpowder/array.py +++ b/gunpowder/array.py @@ -1,7 +1,5 @@ from .freezable import Freezable from copy import deepcopy -from gunpowder.coordinate import Coordinate -from gunpowder.roi import Roi import logging import numpy as np import copy diff --git a/gunpowder/batch.py b/gunpowder/batch.py index 412c891f..ffc97e77 100644 --- a/gunpowder/batch.py +++ b/gunpowder/batch.py @@ -1,7 +1,6 @@ from copy import copy as shallow_copy import logging import multiprocessing -import warnings from .freezable import Freezable from .profiling import ProfilingStats @@ -75,7 +74,7 @@ def __setitem__(self, key, value): elif isinstance(value, Graph): assert isinstance( key, GraphKey - ), f"Only a GraphKey is allowed as key for Graph value." + ), "Only a GraphKey is allowed as key for Graph value." self.graphs[key] = value else: diff --git a/gunpowder/contrib/nodes/add_blobs_from_points.py b/gunpowder/contrib/nodes/add_blobs_from_points.py index 03b063ba..a78eb814 100644 --- a/gunpowder/contrib/nodes/add_blobs_from_points.py +++ b/gunpowder/contrib/nodes/add_blobs_from_points.py @@ -143,7 +143,7 @@ def process(self, batch, request): synapse_ids = [] for point_id, point in points.data.items(): # pdb.set_trace() - if not point.partner_ids[0] in partner_points.data.keys(): + if point.partner_ids[0] not in partner_points.data.keys(): logger.warning( "Point %s has no partner. Deleting..." % point_id ) diff --git a/gunpowder/contrib/nodes/add_boundary_distance_gradients.py b/gunpowder/contrib/nodes/add_boundary_distance_gradients.py index 2ef93870..b2897272 100644 --- a/gunpowder/contrib/nodes/add_boundary_distance_gradients.py +++ b/gunpowder/contrib/nodes/add_boundary_distance_gradients.py @@ -4,7 +4,6 @@ from gunpowder.array import Array from gunpowder.batch_request import BatchRequest from gunpowder.nodes.batch_filter import BatchFilter -from numpy.lib.stride_tricks import as_strided from scipy.ndimage.morphology import distance_transform_edt logger = logging.getLogger(__name__) @@ -83,7 +82,7 @@ def prepare(self, request): return deps def process(self, batch, request): - if not self.gradient_array_key in request: + if self.gradient_array_key not in request: return labels = batch.arrays[self.label_array_key].data diff --git a/gunpowder/contrib/nodes/add_gt_mask_exclusive_zone.py b/gunpowder/contrib/nodes/add_gt_mask_exclusive_zone.py index cff056f7..f50e6a70 100644 --- a/gunpowder/contrib/nodes/add_gt_mask_exclusive_zone.py +++ b/gunpowder/contrib/nodes/add_gt_mask_exclusive_zone.py @@ -1,10 +1,9 @@ import copy import logging import numpy as np -from scipy import ndimage from gunpowder.nodes.batch_filter import BatchFilter -from gunpowder.array import Array, ArrayKeys +from gunpowder.array import Array from gunpowder.nodes.rasterize_graph import RasterizationSettings from gunpowder.morphology import enlarge_binary_map diff --git a/gunpowder/contrib/nodes/add_nonsymmetric_affinities.py b/gunpowder/contrib/nodes/add_nonsymmetric_affinities.py index 6d47201b..ef16398b 100644 --- a/gunpowder/contrib/nodes/add_nonsymmetric_affinities.py +++ b/gunpowder/contrib/nodes/add_nonsymmetric_affinities.py @@ -1,7 +1,5 @@ -import copy import logging import numpy as np -import pdb from gunpowder.array import Array from gunpowder.nodes.batch_filter import BatchFilter diff --git a/gunpowder/contrib/nodes/hdf5_points_source.py b/gunpowder/contrib/nodes/hdf5_points_source.py index a3cd2b44..f78630a1 100644 --- a/gunpowder/contrib/nodes/hdf5_points_source.py +++ b/gunpowder/contrib/nodes/hdf5_points_source.py @@ -5,10 +5,7 @@ from gunpowder.batch import Batch from gunpowder.coordinate import Coordinate from gunpowder.ext import h5py -from gunpowder.graph import GraphKey, Graph -from gunpowder.graph_spec import GraphSpec from gunpowder.profiling import Timing -from gunpowder.roi import Roi from gunpowder.nodes.batch_provider import BatchProvider logger = logging.getLogger(__name__) diff --git a/gunpowder/ext/__init__.py b/gunpowder/ext/__init__.py index fdfcfa02..5b51124d 100644 --- a/gunpowder/ext/__init__.py +++ b/gunpowder/ext/__init__.py @@ -21,73 +21,73 @@ def __getattr__(self, item): try: import dvision -except ImportError as e: +except ImportError: dvision = NoSuchModule("dvision") try: import h5py -except ImportError as e: +except ImportError: h5py = NoSuchModule("h5py") try: import pyklb -except ImportError as e: +except ImportError: pyklb = NoSuchModule("pyklb") try: import tensorflow -except ImportError as e: +except ImportError: tensorflow = NoSuchModule("tensorflow") try: import torch -except ImportError as e: +except ImportError: torch = NoSuchModule("torch") try: import tensorboardX -except ImportError as e: +except ImportError: tensorboardX = NoSuchModule("tensorboardX") try: import malis -except ImportError as e: +except ImportError: malis = NoSuchModule("malis") try: import augment -except ImportError as e: +except ImportError: augment = NoSuchModule("augment") ZarrFile: Optional[Any] = None try: import zarr from .zarr_file import ZarrFile -except ImportError as e: +except ImportError: zarr = NoSuchModule("zarr") ZarrFile = None try: import daisy -except ImportError as e: +except ImportError: daisy = NoSuchModule("daisy") try: import jax -except ImportError as e: +except ImportError: jax = NoSuchModule("jax") try: import jax.numpy as jnp -except ImportError as e: +except ImportError: jnp = NoSuchModule("jnp") try: import haiku -except ImportError as e: +except ImportError: haiku = NoSuchModule("haiku") try: import optax -except ImportError as e: +except ImportError: optax = NoSuchModule("optax") diff --git a/gunpowder/graph.py b/gunpowder/graph.py index 91fdb883..3321c5ac 100644 --- a/gunpowder/graph.py +++ b/gunpowder/graph.py @@ -9,7 +9,6 @@ from typing import Dict, Optional, Set, Iterator, Any import logging import itertools -import warnings logger = logging.getLogger(__name__) @@ -485,7 +484,7 @@ def _roi_intercept( offset = outside - inside distance = np.linalg.norm(offset) - assert not np.isclose(distance, 0), f"Inside and Outside are the same location" + assert not np.isclose(distance, 0), "Inside and Outside are the same location" direction = offset / distance # `offset` can be 0 on some but not all axes leaving a 0 in the denominator. diff --git a/gunpowder/nodes/crop.py b/gunpowder/nodes/crop.py index 3e4cdeb5..0584335e 100644 --- a/gunpowder/nodes/crop.py +++ b/gunpowder/nodes/crop.py @@ -1,4 +1,3 @@ -import copy import logging from .batch_filter import BatchFilter diff --git a/gunpowder/nodes/elastic_augment.py b/gunpowder/nodes/elastic_augment.py index d999d6fe..a4413a44 100644 --- a/gunpowder/nodes/elastic_augment.py +++ b/gunpowder/nodes/elastic_augment.py @@ -9,7 +9,6 @@ from gunpowder.coordinate import Coordinate from gunpowder.ext import augment from gunpowder.roi import Roi -from gunpowder.array import ArrayKey import warnings diff --git a/gunpowder/nodes/exclude_labels.py b/gunpowder/nodes/exclude_labels.py index ae38d43a..2592dc25 100644 --- a/gunpowder/nodes/exclude_labels.py +++ b/gunpowder/nodes/exclude_labels.py @@ -71,7 +71,7 @@ def process(self, batch, request): include_mask[gt.data == label] = 0 # if no ignore mask is provided or requested, we are done - if not self.ignore_mask or not self.ignore_mask in request: + if not self.ignore_mask or self.ignore_mask not in request: return voxel_size = self.spec[self.labels].voxel_size diff --git a/gunpowder/nodes/grow_boundary.py b/gunpowder/nodes/grow_boundary.py index 08d20abf..d793345f 100644 --- a/gunpowder/nodes/grow_boundary.py +++ b/gunpowder/nodes/grow_boundary.py @@ -2,7 +2,6 @@ from scipy import ndimage from .batch_filter import BatchFilter -from gunpowder.array import Array class GrowBoundary(BatchFilter): diff --git a/gunpowder/nodes/klb_source.py b/gunpowder/nodes/klb_source.py index e2a3f758..d4776bba 100644 --- a/gunpowder/nodes/klb_source.py +++ b/gunpowder/nodes/klb_source.py @@ -1,4 +1,3 @@ -import copy import logging import numpy as np import glob diff --git a/gunpowder/nodes/merge_provider.py b/gunpowder/nodes/merge_provider.py index 0d32300e..6df979b8 100644 --- a/gunpowder/nodes/merge_provider.py +++ b/gunpowder/nodes/merge_provider.py @@ -1,4 +1,3 @@ -from gunpowder.provider_spec import ProviderSpec from gunpowder.batch import Batch from gunpowder.batch_request import BatchRequest diff --git a/gunpowder/nodes/pad.py b/gunpowder/nodes/pad.py index f025d9d7..758fd04a 100644 --- a/gunpowder/nodes/pad.py +++ b/gunpowder/nodes/pad.py @@ -7,7 +7,6 @@ from gunpowder.coordinate import Coordinate from gunpowder.batch_request import BatchRequest -from itertools import product logger = logging.getLogger(__name__) diff --git a/gunpowder/nodes/precache.py b/gunpowder/nodes/precache.py index ac35d32f..9c58ae53 100644 --- a/gunpowder/nodes/precache.py +++ b/gunpowder/nodes/precache.py @@ -1,7 +1,4 @@ import logging -import multiprocessing -import time -import random from .batch_filter import BatchFilter from gunpowder.profiling import Timing diff --git a/gunpowder/nodes/rasterize_graph.py b/gunpowder/nodes/rasterize_graph.py index b660dd57..bb2473f6 100644 --- a/gunpowder/nodes/rasterize_graph.py +++ b/gunpowder/nodes/rasterize_graph.py @@ -1,4 +1,3 @@ -import copy import logging import numpy as np from scipy.ndimage.filters import gaussian_filter @@ -12,7 +11,6 @@ from gunpowder.freezable import Freezable from gunpowder.morphology import enlarge_binary_map, create_ball_kernel from gunpowder.ndarray import replace -from gunpowder.graph import GraphKey from gunpowder.graph_spec import GraphSpec from gunpowder.roi import Roi diff --git a/gunpowder/nodes/shift_augment.py b/gunpowder/nodes/shift_augment.py index 8761a563..d42b1434 100644 --- a/gunpowder/nodes/shift_augment.py +++ b/gunpowder/nodes/shift_augment.py @@ -4,7 +4,6 @@ import random from gunpowder.roi import Roi from gunpowder.coordinate import Coordinate -from gunpowder.batch_request import BatchRequest from .batch_filter import BatchFilter diff --git a/gunpowder/nodes/specified_location.py b/gunpowder/nodes/specified_location.py index b209e078..cc5e5844 100644 --- a/gunpowder/nodes/specified_location.py +++ b/gunpowder/nodes/specified_location.py @@ -1,10 +1,8 @@ from random import randrange -from random import choice, seed import logging import numpy as np from gunpowder.coordinate import Coordinate -from gunpowder.batch_request import BatchRequest from .batch_filter import BatchFilter diff --git a/gunpowder/nodes/squeeze.py b/gunpowder/nodes/squeeze.py index 2e999714..d0a1469b 100644 --- a/gunpowder/nodes/squeeze.py +++ b/gunpowder/nodes/squeeze.py @@ -1,4 +1,3 @@ -import copy from typing import List import logging diff --git a/gunpowder/nodes/unsqueeze.py b/gunpowder/nodes/unsqueeze.py index 3df03ec4..9f019978 100644 --- a/gunpowder/nodes/unsqueeze.py +++ b/gunpowder/nodes/unsqueeze.py @@ -1,4 +1,3 @@ -import copy from typing import List import logging diff --git a/gunpowder/producer_pool.py b/gunpowder/producer_pool.py index 0f6c2888..73df6b6d 100644 --- a/gunpowder/producer_pool.py +++ b/gunpowder/producer_pool.py @@ -6,8 +6,6 @@ import multiprocessing import os import sys -import time -import traceback import numpy as np diff --git a/gunpowder/provider_spec.py b/gunpowder/provider_spec.py index 7c34324d..6a1ab818 100644 --- a/gunpowder/provider_spec.py +++ b/gunpowder/provider_spec.py @@ -6,7 +6,6 @@ from gunpowder.graph_spec import GraphSpec from gunpowder.roi import Roi from .freezable import Freezable -import time import logging import copy @@ -14,7 +13,6 @@ import logging -import warnings logger = logging.getLogger(__file__) diff --git a/tests/cases/add_affinities.py b/tests/cases/add_affinities.py index 792be290..bd6ebc93 100644 --- a/tests/cases/add_affinities.py +++ b/tests/cases/add_affinities.py @@ -1,10 +1,6 @@ -from .provider_test import ProviderTest from gunpowder import * from itertools import product -from unittest import skipIf -import itertools import numpy as np -import logging class ExampleSource(BatchProvider): diff --git a/tests/cases/dvid_source.py b/tests/cases/dvid_source.py index 8f2c31e6..ac206909 100644 --- a/tests/cases/dvid_source.py +++ b/tests/cases/dvid_source.py @@ -2,7 +2,6 @@ from unittest import skipIf from gunpowder import * from gunpowder.ext import dvision, NoSuchModule -import numpy as np import socket import logging diff --git a/tests/cases/elastic_augment_points.py b/tests/cases/elastic_augment_points.py index 76e9ae2b..ddb99741 100644 --- a/tests/cases/elastic_augment_points.py +++ b/tests/cases/elastic_augment_points.py @@ -1,4 +1,3 @@ -import unittest from gunpowder import ( BatchProvider, Batch, @@ -25,7 +24,6 @@ import numpy as np import math import time -import unittest class PointTestSource3D(BatchProvider): diff --git a/tests/cases/expected_failures.py b/tests/cases/expected_failures.py index 39a2d21e..8adf48af 100644 --- a/tests/cases/expected_failures.py +++ b/tests/cases/expected_failures.py @@ -2,7 +2,7 @@ from gunpowder.nodes.batch_provider import BatchRequestError from .helper_sources import ArraySource -from funlib.geometry import Roi, Coordinate +from funlib.geometry import Coordinate import numpy as np import pytest diff --git a/tests/cases/intensity_scale_shift.py b/tests/cases/intensity_scale_shift.py index d65df3dd..c64b4ec3 100644 --- a/tests/cases/intensity_scale_shift.py +++ b/tests/cases/intensity_scale_shift.py @@ -3,7 +3,6 @@ IntensityScaleShift, ArrayKey, build, - Normalize, Array, ArraySpec, Roi, diff --git a/tests/cases/jax_train.py b/tests/cases/jax_train.py index 14fbad46..2ff55be6 100644 --- a/tests/cases/jax_train.py +++ b/tests/cases/jax_train.py @@ -4,18 +4,15 @@ BatchRequest, ArraySpec, Roi, - Coordinate, ArrayKeys, ArrayKey, Array, Batch, - Scan, - PreCache, build, ) from gunpowder.ext import jax, haiku, optax, NoSuchModule from gunpowder.jax import Train, Predict, GenericJaxModel -from unittest import skipIf, expectedFailure +from unittest import skipIf import numpy as np import logging diff --git a/tests/cases/noise_augment.py b/tests/cases/noise_augment.py index 6e9f635c..1a2bcf63 100644 --- a/tests/cases/noise_augment.py +++ b/tests/cases/noise_augment.py @@ -1,7 +1,6 @@ from .provider_test import ProviderTest from gunpowder import IntensityAugment, ArrayKeys, build, Normalize, NoiseAugment -import numpy as np class TestIntensityAugment(ProviderTest): diff --git a/tests/cases/random_location.py b/tests/cases/random_location.py index df3f1cca..611289a8 100644 --- a/tests/cases/random_location.py +++ b/tests/cases/random_location.py @@ -3,7 +3,6 @@ BatchProvider, Roi, Coordinate, - ArrayKeys, ArrayKey, ArraySpec, Array, diff --git a/tests/cases/resample.py b/tests/cases/resample.py index d7a057b0..9784b152 100644 --- a/tests/cases/resample.py +++ b/tests/cases/resample.py @@ -5,7 +5,6 @@ ArraySpec, Roi, Coordinate, - Batch, BatchRequest, Array, MergeProvider, diff --git a/tests/cases/simple_augment.py b/tests/cases/simple_augment.py index c77709c0..0696213c 100644 --- a/tests/cases/simple_augment.py +++ b/tests/cases/simple_augment.py @@ -1,6 +1,4 @@ from gunpowder import ( - Batch, - BatchProvider, BatchRequest, Array, ArrayKey, diff --git a/tests/cases/snapshot.py b/tests/cases/snapshot.py index 8dcc4443..928076ea 100644 --- a/tests/cases/snapshot.py +++ b/tests/cases/snapshot.py @@ -4,10 +4,8 @@ GraphSpec, Graph, ArrayKey, - ArrayKeys, ArraySpec, Array, - RasterizeGraph, Snapshot, BatchProvider, BatchRequest, diff --git a/tests/cases/tensorflow_train.py b/tests/cases/tensorflow_train.py index f4eae06e..079be0d3 100644 --- a/tests/cases/tensorflow_train.py +++ b/tests/cases/tensorflow_train.py @@ -11,7 +11,7 @@ build, ) from gunpowder.ext import tensorflow, NoSuchModule -from gunpowder.tensorflow import Train, Predict, LocalServer +from gunpowder.tensorflow import Train import multiprocessing import numpy as np from unittest import skipIf diff --git a/tests/cases/zarr_read_write.py b/tests/cases/zarr_read_write.py index 64303174..c6cdb39b 100644 --- a/tests/cases/zarr_read_write.py +++ b/tests/cases/zarr_read_write.py @@ -1,7 +1,7 @@ from .helper_sources import ArraySource from gunpowder import * -from gunpowder.ext import zarr, ZarrFile, NoSuchModule +from gunpowder.ext import zarr, NoSuchModule import pytest import numpy as np