From 8c9a4dd5d5d3142e17c1601feea78aea56037336 Mon Sep 17 00:00:00 2001 From: Amin Sadeghi Date: Fri, 9 Aug 2024 11:11:46 -0400 Subject: [PATCH 1/5] maint: Remove duplicate ruff config from pyproject.toml --- pyproject.toml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 596ae15b5..429049f0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -158,11 +158,3 @@ exclude_lines = [ "raise NotImplementedError", "if __name__ == .__main__.:", ] - -[tool.ruff] -exclude = [".git", ".github", ".venv", "build", "docs", "examples", "test"] -line-length = 92 -[tool.ruff.lint.per-file-ignores] -"__init__.py" = ["E402", "F401", "F403"] -[tool.ruff.lint] -extend-ignore = ["F401"] From 95caf7331d7f434b205959a76cb6c37d0f349c7f Mon Sep 17 00:00:00 2001 From: Amin Sadeghi Date: Fri, 9 Aug 2024 11:12:08 -0400 Subject: [PATCH 2/5] style: Config ruff to our liking --- ruff.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 2e8916c60..939319d47 100644 --- a/ruff.toml +++ b/ruff.toml @@ -29,7 +29,7 @@ exclude = [ ] # Same as Black. -line-length = 95 +line-length = 92 indent-width = 4 # Assume Python 3.10 @@ -75,3 +75,7 @@ docstring-code-format = true # This only has an effect when the `docstring-code-format` setting is # enabled. docstring-code-line-length = "dynamic" + +[lint.per-file-ignores] +"__init__.py" = ["E402", "F401", "F403"] +"test/**" = ["F841"] From d77217527679520cd3fa70fbbe68ba97834d2eff Mon Sep 17 00:00:00 2001 From: Amin Sadeghi Date: Fri, 9 Aug 2024 11:12:39 -0400 Subject: [PATCH 3/5] style: Apply ruff throughout the code base --- src/porespy/beta/_generators.py | 1 - src/porespy/filters/_snows.py | 5 ++- src/porespy/generators/_noise.py | 15 ++++---- src/porespy/generators/_pseudo_packings.py | 2 -- src/porespy/io/_unzipper.py | 30 ++++++++-------- src/porespy/networks/_getnet_para.py | 11 +----- src/porespy/visualization/_views.py | 41 ++++++++++------------ test/unit/test_filters.py | 1 - test/unit/test_generators.py | 1 - test/unit/test_io.py | 2 -- test/unit/test_metrics.py | 3 -- test/unit/test_network_extraction.py | 1 - test/unit/test_parallel_filters.py | 2 -- test/unit/test_simulations.py | 4 --- test/unit/test_snow2.py | 1 - 15 files changed, 44 insertions(+), 76 deletions(-) diff --git a/src/porespy/beta/_generators.py b/src/porespy/beta/_generators.py index 896d8766d..b927e3c63 100644 --- a/src/porespy/beta/_generators.py +++ b/src/porespy/beta/_generators.py @@ -1,4 +1,3 @@ -import numpy as np from scipy.signal import convolve from porespy.tools import ps_rect diff --git a/src/porespy/filters/_snows.py b/src/porespy/filters/_snows.py index f12eab8e8..e0511141a 100644 --- a/src/porespy/filters/_snows.py +++ b/src/porespy/filters/_snows.py @@ -359,7 +359,7 @@ def reduce_peaks(peaks): else: strel = cube markers, N = spim.label(input=peaks, structure=strel(3)) - inds = spim.measurements.center_of_mass( + inds = spim.center_of_mass( input=peaks, labels=markers, index=np.arange(1, N + 1) ) inds = np.floor(inds).astype(int) @@ -567,8 +567,7 @@ def trim_nearby_peaks(peaks, dt, f=1): from skimage.morphology import cube labels, N = spim.label(peaks > 0, structure=cube(3)) - crds = spim.measurements.center_of_mass(peaks > 0, labels=labels, - index=np.arange(1, N + 1)) + crds = spim.center_of_mass(peaks > 0, labels=labels, index=np.arange(1, N + 1)) try: crds = np.vstack(crds).astype(int) # Convert to numpy array of ints except ValueError: diff --git a/src/porespy/generators/_noise.py b/src/porespy/generators/_noise.py index 5dfc5b625..ee5c642e9 100644 --- a/src/porespy/generators/_noise.py +++ b/src/porespy/generators/_noise.py @@ -10,7 +10,7 @@ def fractal_noise( frequency: float = 0.05, octaves: int = 4, gain: float = 0.5, - mode: Literal['simplex', 'perlin', 'value', 'cubic'] = 'simplex', + mode: Literal["simplex", "perlin", "value", "cubic"] = "simplex", seed: int = None, cores: int = 1, uniform: bool = True, @@ -23,9 +23,9 @@ def fractal_noise( shape : array_like The size of the image to generate, can be 2D or 3D. porosity : float - If specified, this will convert the noise distribution to uniform - (no need to set uniform to ``True``), and then threshold the image - to the specified value prior to returning. + If specified, this will convert the noise distribution to uniform + (no need to set uniform to ``True``), and then threshold the image + to the specified value prior to returning. frequency : scalar, default=0.05 Controls the overall scale of the generated noise, with larger values giving smaller structures. @@ -87,14 +87,15 @@ def fractal_noise( try: from pyfastnoisesimd import Noise, NoiseType, PerturbType except ModuleNotFoundError: - raise ModuleNotFoundError("You need to install `pyfastnoisesimd` using" - " `pip install pyfastnoisesimd`") + raise ModuleNotFoundError( + "You need to install `pyfastnoisesimd` using" " `pip install pyfastnoisesimd`" + ) if cores is None: cores = psutil.cpu_count(logical=False) if seed is None: seed = np.random.randint(2**31) perlin = Noise(numWorkers=cores) - perlin.noiseType = getattr(NoiseType, f'{mode.capitalize()}Fractal') + perlin.noiseType = getattr(NoiseType, f"{mode.capitalize()}Fractal") perlin.frequency = frequency perlin.fractal.octaves = octaves perlin.fractal.gain = gain diff --git a/src/porespy/generators/_pseudo_packings.py b/src/porespy/generators/_pseudo_packings.py index b9071c7a6..aa597f8c1 100644 --- a/src/porespy/generators/_pseudo_packings.py +++ b/src/porespy/generators/_pseudo_packings.py @@ -1,12 +1,10 @@ import logging -import heapq import numpy as np import scipy.ndimage as spim import numpy.typing as npt from numba import njit from typing import Literal, List from skimage.morphology import disk, ball -from porespy import settings from porespy.tools import ( get_tqdm, ps_round, diff --git a/src/porespy/io/_unzipper.py b/src/porespy/io/_unzipper.py index 67ab7bae7..0f5475085 100644 --- a/src/porespy/io/_unzipper.py +++ b/src/porespy/io/_unzipper.py @@ -12,8 +12,8 @@ __all__ = [ - 'zip_to_stack', - 'folder_to_stack', + "zip_to_stack", + "folder_to_stack", ] @@ -38,10 +38,9 @@ def folder_to_stack(target_dir): """ p = Path(target_dir) test_im = imageio.v2.imread(os.path.join(p, os.listdir(p)[0])) - im = np.zeros(shape=[test_im.shape[0], - test_im.shape[1], - len(os.listdir(p))], - dtype=test_im.dtype) + im = np.zeros( + shape=[test_im.shape[0], test_im.shape[1], len(os.listdir(p))], dtype=test_im.dtype + ) for i, f in enumerate(tqdm(os.listdir(p))): im[..., i] = imageio.v2.imread(os.path.join(p, f)) @@ -71,9 +70,9 @@ def zip_to_stack(f): layer number, like 001, 002, etc. """ p = Path(f) - dir_for_files = p.parts[-1].rpartition('.')[0] + dir_for_files = p.parts[-1].rpartition(".")[0] - with ZipFile(p, 'r') as f: + with ZipFile(p, "r") as f: f.extractall(dir_for_files) # Method 1: uses skimage and numpy function so is easy to understand @@ -84,16 +83,15 @@ def zip_to_stack(f): # im = np.stack(files, axis=2) # Method 2: Same speed as 1 but more complex, but allows tqdm progress bar - test_im = imageio.v2.imread(os.path.join(dir_for_files, - os.listdir(dir_for_files)[0])) - im = np.zeros(shape=[test_im.shape[0], - test_im.shape[1], - len(os.listdir(dir_for_files))], - dtype=test_im.dtype) + test_im = imageio.v2.imread(os.path.join(dir_for_files, os.listdir(dir_for_files)[0])) + im = np.zeros( + shape=[test_im.shape[0], test_im.shape[1], len(os.listdir(dir_for_files))], + dtype=test_im.dtype, + ) for i, f in enumerate(tqdm(os.listdir(dir_for_files))): - im[..., i] = imageio.v2.imread(os.path.join(dir_for_files , f)) + im[..., i] = imageio.v2.imread(os.path.join(dir_for_files, f)) - # Remove the unzipped folder + # Remove the unzipped folder shutil.rmtree(dir_for_files) return im diff --git a/src/porespy/networks/_getnet_para.py b/src/porespy/networks/_getnet_para.py index 955be41dc..ff78afc8e 100644 --- a/src/porespy/networks/_getnet_para.py +++ b/src/porespy/networks/_getnet_para.py @@ -1,14 +1,11 @@ import logging import numpy as np import numba -from numba import njit, prange, gdb +from numba import njit, prange from numba.typed import List, Dict from numba.core import types import scipy.ndimage as spim -from skimage.morphology import disk, ball -from porespy import settings from porespy.tools import ( - extend_slice, jit_extend_slice, center_of_mass, ) @@ -18,14 +15,8 @@ jit_marching_cubes_area_and_volume, jit_marching_squares_perimeter_and_area, create_mc_template_list, - calculate_area_and_volume, pad, ) -from porespy.metrics import ( - region_surface_areas, - region_interface_areas, - region_volumes, -) try: from pyedt import edt, jit_edt_cpu except ModuleNotFoundError: diff --git a/src/porespy/visualization/_views.py b/src/porespy/visualization/_views.py index d55033310..a497d8d76 100644 --- a/src/porespy/visualization/_views.py +++ b/src/porespy/visualization/_views.py @@ -5,10 +5,10 @@ __all__ = [ - 'show_3D', - 'show_planes', - 'sem', - 'xray', + "show_3D", + "show_planes", + "sem", + "xray", ] @@ -45,16 +45,16 @@ def show_3D(im): # pragma: no cover """ im = ~np.copy(im) if im.ndim < 3: - raise Exception('show_3D only applies to 3D images') + raise Exception("show_3D only applies to 3D images") im = spim.rotate(input=im, angle=22.5, axes=[0, 1], order=0) im = spim.rotate(input=im, angle=45, axes=[2, 1], order=0) im = spim.rotate(input=im, angle=-17, axes=[0, 1], order=0, reshape=False) mask = im != 0 view = np.where(mask.any(axis=2), mask.argmax(axis=2), 0) view = view.max() - view - f = view.max()/5 + f = view.max() / 5 view[view == view.max()] = -f - view = (view + f)**2 + view = (view + f) ** 2 return view @@ -84,8 +84,8 @@ def show_planes(im, spacing=10): # pragma: no cover """ s = spacing if np.squeeze(im.ndim) < 3: - raise Exception('This view is only necessary for 3D images') - x, y, z = (np.array(im.shape)/2).astype(int) + raise Exception("This view is only necessary for 3D images") + x, y, z = (np.array(im.shape) / 2).astype(int) im_xy = im[:, :, z] im_xz = im[:, y, :] im_yz = np.rot90(im[x, :, :]) @@ -94,18 +94,15 @@ def show_planes(im, spacing=10): # pragma: no cover new_y = im_xy.shape[1] + im_xz.shape[1] + s - new_im = np.zeros([new_x + 2*s, new_y + 2*s], dtype=im.dtype) + new_im = np.zeros([new_x + 2 * s, new_y + 2 * s], dtype=im.dtype) # Add xy image to upper left corner - new_im[s:im_xy.shape[0] + s, - s:im_xy.shape[1] + s] = im_xy + new_im[s : im_xy.shape[0] + s, s : im_xy.shape[1] + s] = im_xy # Add xz image to lower left coner - x_off = im_xy.shape[0] + 2*s - y_off = im_xy.shape[1] + 2*s - new_im[s:s + im_xz.shape[0], - y_off:y_off + im_xz.shape[1]] = im_xz - new_im[x_off:x_off + im_yz.shape[0], - s:s + im_yz.shape[1]] = im_yz + x_off = im_xy.shape[0] + 2 * s + y_off = im_xy.shape[1] + 2 * s + new_im[s : s + im_xz.shape[0], y_off : y_off + im_xz.shape[1]] = im_xz + new_im[x_off : x_off + im_yz.shape[0], s : s + im_yz.shape[1]] = im_yz return new_im @@ -149,7 +146,7 @@ def sem(im, axis=0): # pragma: no cover @njit(parallel=True) def _sem_parallel(im): # pragma: no cover r""" - This function is called `sem` to compute the height of the first + This function is called `sem` to compute the height of the first voxel in each x, y column. It uses numba for speed, and is parallelized. """ @@ -157,9 +154,9 @@ def _sem_parallel(im): # pragma: no cover depth = np.zeros(shape[:2]) for x in prange(shape[0]): for y in prange(shape[1]): - for z in range(shape[2]-1, 0, -1): + for z in range(shape[2] - 1, 0, -1): if not im[x][y][z]: - depth[x][y] = z/shape[2] + depth[x][y] = z / shape[2] break return depth @@ -198,5 +195,5 @@ def xray(im, axis=0): # pragma: no cover if axis == 2: im = np.transpose(im, axes=[2, 1, 0]) im = np.sum(im, axis=0, dtype=np.int64) - im = im/np.max(im) + im = im / np.max(im) return im diff --git a/test/unit/test_filters.py b/test/unit/test_filters.py index a35a9697f..e5eae02d7 100644 --- a/test/unit/test_filters.py +++ b/test/unit/test_filters.py @@ -4,7 +4,6 @@ import scipy.ndimage as spim from skimage.morphology import disk, ball, skeletonize_3d from skimage.util import random_noise -from scipy.stats import norm try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_generators.py b/test/unit/test_generators.py index 377095a97..99eba7db8 100644 --- a/test/unit/test_generators.py +++ b/test/unit/test_generators.py @@ -1,6 +1,5 @@ import pytest import numpy as np -from numpy.testing import assert_allclose import scipy.ndimage as spim import scipy.stats as spst import porespy as ps diff --git a/test/unit/test_io.py b/test/unit/test_io.py index 81343bbeb..11f6fdf3f 100644 --- a/test/unit/test_io.py +++ b/test/unit/test_io.py @@ -1,9 +1,7 @@ import os import sys import numpy as np -from numpy.testing import assert_allclose import porespy as ps -import openpnm as op from pathlib import Path diff --git a/test/unit/test_metrics.py b/test/unit/test_metrics.py index 0a6a83b76..bce53f91e 100644 --- a/test/unit/test_metrics.py +++ b/test/unit/test_metrics.py @@ -185,9 +185,6 @@ def test_region_volumes_for_sphere(self): assert_allclose(vol_march, 4102.28678846) assert_allclose(vol_vox, 4169.) - def test_region_interface_areas(self): - pass - def test_phase_fraction(self): im = np.reshape(np.random.randint(0, 10, 1000), [10, 10, 10]) labels = np.unique(im, return_counts=True)[1] diff --git a/test/unit/test_network_extraction.py b/test/unit/test_network_extraction.py index 568b145de..6f86a7cb4 100644 --- a/test/unit/test_network_extraction.py +++ b/test/unit/test_network_extraction.py @@ -5,7 +5,6 @@ from os.path import realpath import pytest import numpy as np -from numpy.testing import assert_allclose import porespy as ps ps.settings.tqdm['disable'] = True diff --git a/test/unit/test_parallel_filters.py b/test/unit/test_parallel_filters.py index ef6e6fc09..5d3296bbe 100644 --- a/test/unit/test_parallel_filters.py +++ b/test/unit/test_parallel_filters.py @@ -1,7 +1,5 @@ import numpy as np import porespy as ps -import scipy.ndimage as spim -from skimage.morphology import skeletonize_3d try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_simulations.py b/test/unit/test_simulations.py index 37d517795..5259d3bc3 100644 --- a/test/unit/test_simulations.py +++ b/test/unit/test_simulations.py @@ -1,10 +1,6 @@ import pytest import numpy as np import porespy as ps -import scipy.ndimage as spim -from skimage.morphology import disk, ball, skeletonize_3d -from skimage.util import random_noise -from scipy.stats import norm try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_snow2.py b/test/unit/test_snow2.py index 5a8b94ed6..d4b5941d8 100644 --- a/test/unit/test_snow2.py +++ b/test/unit/test_snow2.py @@ -1,4 +1,3 @@ -import pytest import numpy as np from scipy import stats as spst import scipy.ndimage as spim From 2f45048fb5148a853ebed9b43a10413adbbfbd67 Mon Sep 17 00:00:00 2001 From: Amin Sadeghi Date: Fri, 9 Aug 2024 11:21:26 -0400 Subject: [PATCH 4/5] style: Sort imports throughout the codebase --- src/porespy/beta/_drainage2.py | 11 +++++--- src/porespy/beta/_gdd.py | 15 ++++++---- src/porespy/beta/_generators.py | 2 +- src/porespy/beta/_poly_cylinders.py | 5 ++-- src/porespy/dns/_funcs.py | 2 +- src/porespy/filters/_fftmorphology.py | 1 - src/porespy/filters/_funcs.py | 28 +++++++++++++------ src/porespy/filters/_nlmeans.py | 7 +++-- src/porespy/filters/_size_seq_satn.py | 2 +- src/porespy/filters/_snows.py | 23 +++++++++------ src/porespy/filters/imagej/_funcs.py | 2 +- src/porespy/generators/_borders.py | 2 +- src/porespy/generators/_fractals.py | 5 ++-- src/porespy/generators/_imgen.py | 28 ++++++++++--------- src/porespy/generators/_noise.py | 6 ++-- src/porespy/generators/_pseudo_packings.py | 18 +++++++----- .../generators/_spheres_from_coords.py | 3 +- src/porespy/io/_funcs.py | 3 ++ src/porespy/metrics/_funcs.py | 12 ++++---- src/porespy/metrics/_meshtools.py | 15 ++++++---- src/porespy/metrics/_regionprops.py | 10 ++++--- src/porespy/networks/_funcs.py | 12 ++++---- src/porespy/networks/_getnet_orig.py | 11 ++++---- src/porespy/networks/_getnet_para.py | 17 +++++------ src/porespy/networks/_maximal_ball.py | 6 ++-- src/porespy/networks/_size_factors.py | 10 ++++--- src/porespy/networks/_snow2.py | 19 +++++++------ src/porespy/simulations/_drainage.py | 22 +++++++++------ src/porespy/simulations/_ibip.py | 14 ++++++---- src/porespy/simulations/_ibip_gpu.py | 7 +++-- src/porespy/tools/_funcs.py | 9 ++++-- src/porespy/tools/_marching_cubes.py | 10 +++---- src/porespy/tools/_sphere_insertions.py | 2 +- src/porespy/tools/_utils.py | 10 +++---- src/porespy/visualization/_funcs.py | 9 +++--- src/porespy/visualization/_plots.py | 4 +-- src/porespy/visualization/_views.py | 1 + test/integration/test_drainage.py | 2 +- test/integration/test_drainage_from_top.py | 2 +- test/integration/test_ibip_example_script.py | 7 +++-- test/integration/test_inverse_Bo_study.py | 5 ++-- test/integration/test_snow_example_script.py | 4 +-- test/integration/test_variable_Bo_study.py | 4 +-- test/unit/test_dns.py | 3 +- test/unit/test_filters.py | 5 ++-- test/unit/test_filters_size_seq_satn.py | 1 + test/unit/test_generators.py | 7 +++-- test/unit/test_imagej.py | 1 + test/unit/test_io.py | 3 +- test/unit/test_metrics.py | 10 ++++--- test/unit/test_network_extraction.py | 6 ++-- test/unit/test_network_size_factor.py | 1 + test/unit/test_parallel_filters.py | 1 + test/unit/test_simulations.py | 3 +- test/unit/test_simulations_ibip.py | 1 + test/unit/test_snow2.py | 7 +++-- test/unit/test_tools.py | 13 +++++---- test/unit/test_visualization.py | 3 +- 58 files changed, 266 insertions(+), 186 deletions(-) diff --git a/src/porespy/beta/_drainage2.py b/src/porespy/beta/_drainage2.py index 0c37de31b..27fb7acf6 100644 --- a/src/porespy/beta/_drainage2.py +++ b/src/porespy/beta/_drainage2.py @@ -1,9 +1,11 @@ import numpy as np from edt import edt from numba import njit, prange -from porespy.filters import trim_disconnected_blobs, pc_to_satn + from porespy import settings -from porespy.tools import get_tqdm, Results +from porespy.filters import pc_to_satn, trim_disconnected_blobs +from porespy.tools import Results, get_tqdm + tqdm = get_tqdm() @@ -180,11 +182,12 @@ def _insert_disks_npoints_nradii_1value_parallel( if __name__ == "__main__": - import numpy as np - import porespy as ps import matplotlib.pyplot as plt + import numpy as np from edt import edt + import porespy as ps + # %% im = ps.generators.blobs(shape=[200, 200, 200], porosity=0.7, blobiness=1.5, seed=0) inlets = np.zeros_like(im) diff --git a/src/porespy/beta/_gdd.py b/src/porespy/beta/_gdd.py index d403feb28..fef1907b7 100644 --- a/src/porespy/beta/_gdd.py +++ b/src/porespy/beta/_gdd.py @@ -1,12 +1,14 @@ import time -from porespy import simulations, settings -from porespy.tools import Results + +import dask +import dask.delayed +import edt import numpy as np import openpnm as op from pandas import DataFrame -import dask.delayed -import dask -import edt + +from porespy import settings, simulations +from porespy.tools import Results __all__ = ['tortuosity_gdd', 'chunks_to_dataframe'] settings.loglevel = 50 @@ -345,8 +347,9 @@ def chunks_to_dataframe(im, scale_factor=3, use_dask=True): if __name__ =="__main__": - import porespy as ps import numpy as np + + import porespy as ps np.random.seed(1) im = ps.generators.blobs(shape=[100, 100, 100], porosity=0.7) res = ps.simulations.tortuosity_gdd(im=im, scale_factor=3, use_dask=True) diff --git a/src/porespy/beta/_generators.py b/src/porespy/beta/_generators.py index b927e3c63..0a221b72f 100644 --- a/src/porespy/beta/_generators.py +++ b/src/porespy/beta/_generators.py @@ -1,6 +1,6 @@ from scipy.signal import convolve -from porespy.tools import ps_rect +from porespy.tools import ps_rect __all__ = [ "local_diff", diff --git a/src/porespy/beta/_poly_cylinders.py b/src/porespy/beta/_poly_cylinders.py index a496d742c..d44887baa 100644 --- a/src/porespy/beta/_poly_cylinders.py +++ b/src/porespy/beta/_poly_cylinders.py @@ -1,8 +1,8 @@ import numpy as np + from porespy import settings from porespy.tools import get_tqdm - tqdm = get_tqdm() @@ -145,8 +145,9 @@ def polydisperse_cylinders( if __name__ == "__main__": - import scipy.stats as spst import matplotlib.pyplot as plt + import scipy.stats as spst + import porespy as ps params = (5.65832732e+00, 1.54364793e-05, 7.37705832e+00) diff --git a/src/porespy/dns/_funcs.py b/src/porespy/dns/_funcs.py index 37afc03b5..a7dce3acf 100644 --- a/src/porespy/dns/_funcs.py +++ b/src/porespy/dns/_funcs.py @@ -1,6 +1,6 @@ from deprecated import deprecated -from porespy.simulations import tortuosity_fd as _tortuosity +from porespy.simulations import tortuosity_fd as _tortuosity __all__ = [ 'tortuosity', diff --git a/src/porespy/filters/_fftmorphology.py b/src/porespy/filters/_fftmorphology.py index a82c8f464..115ffdf6c 100644 --- a/src/porespy/filters/_fftmorphology.py +++ b/src/porespy/filters/_fftmorphology.py @@ -1,7 +1,6 @@ import numpy as np from scipy.signal import fftconvolve - __all__ = [ "fftmorphology", ] diff --git a/src/porespy/filters/_funcs.py b/src/porespy/filters/_funcs.py index dc50d047c..f10fe7566 100644 --- a/src/porespy/filters/_funcs.py +++ b/src/porespy/filters/_funcs.py @@ -1,20 +1,30 @@ import inspect as insp import logging +import operator as op +from typing import Literal + import dask import numpy as np -import operator as op import scipy.ndimage as spim from deprecated import deprecated -from skimage.morphology import reconstruction +from skimage.morphology import ball, cube, diamond, disk, octahedron, reconstruction, square from skimage.segmentation import clear_border -from skimage.morphology import ball, disk, square, cube, diamond, octahedron -from porespy.tools import _check_for_singleton_axes -from porespy.tools import get_border, subdivide, recombine, make_contiguous -from porespy.tools import unpad, extract_subsection -from porespy.tools import ps_disk, ps_ball, ps_round + from porespy import settings -from porespy.tools import get_tqdm -from typing import Literal +from porespy.tools import ( + _check_for_singleton_axes, + extract_subsection, + get_border, + get_tqdm, + make_contiguous, + ps_ball, + ps_disk, + ps_round, + recombine, + subdivide, + unpad, +) + try: from pyedt import edt except ModuleNotFoundError: diff --git a/src/porespy/filters/_nlmeans.py b/src/porespy/filters/_nlmeans.py index 4bff8a0cb..24e14492a 100644 --- a/src/porespy/filters/_nlmeans.py +++ b/src/porespy/filters/_nlmeans.py @@ -1,8 +1,9 @@ +import dask import numpy as np -from skimage.restoration.non_local_means import denoise_nl_means +from skimage.exposure import match_histograms, rescale_intensity from skimage.restoration import estimate_sigma -from skimage.exposure import rescale_intensity, match_histograms -import dask +from skimage.restoration.non_local_means import denoise_nl_means + dask.config.set(scheduler="threads") # from dask.diagnostics import ProgressBar diff --git a/src/porespy/filters/_size_seq_satn.py b/src/porespy/filters/_size_seq_satn.py index ace920e73..a13790957 100644 --- a/src/porespy/filters/_size_seq_satn.py +++ b/src/porespy/filters/_size_seq_satn.py @@ -1,7 +1,7 @@ import numpy as np -from porespy.tools import make_contiguous from scipy.stats import rankdata +from porespy.tools import make_contiguous __all__ = [ 'size_to_seq', diff --git a/src/porespy/filters/_snows.py b/src/porespy/filters/_snows.py index e0511141a..85842dade 100644 --- a/src/porespy/filters/_snows.py +++ b/src/porespy/filters/_snows.py @@ -1,18 +1,25 @@ -import dask.array as da import inspect as insp import logging + +import dask.array as da import numpy as np -from numba import njit, prange import scipy.ndimage as spim import scipy.spatial as sptl +from numba import njit, prange +from skimage.morphology import cube, square from skimage.segmentation import watershed -from skimage.morphology import square, cube -from porespy.tools import _check_for_singleton_axes -from porespy.tools import extend_slice, ps_rect, ps_round -from porespy.tools import Results -from porespy.tools import get_tqdm -from porespy.filters import chunked_func + from porespy import settings +from porespy.filters import chunked_func +from porespy.tools import ( + Results, + _check_for_singleton_axes, + extend_slice, + get_tqdm, + ps_rect, + ps_round, +) + try: from pyedt import edt except ModuleNotFoundError: diff --git a/src/porespy/filters/imagej/_funcs.py b/src/porespy/filters/imagej/_funcs.py index 6c71e159c..7ef8e0525 100644 --- a/src/porespy/filters/imagej/_funcs.py +++ b/src/porespy/filters/imagej/_funcs.py @@ -1,6 +1,6 @@ import logging -import numpy as np +import numpy as np logger = logging.getLogger(__name__) diff --git a/src/porespy/generators/_borders.py b/src/porespy/generators/_borders.py index 503e9a636..bfe41155f 100644 --- a/src/porespy/generators/_borders.py +++ b/src/porespy/generators/_borders.py @@ -1,6 +1,6 @@ -import numpy as np from typing import Literal +import numpy as np __all__ = ['faces', 'borders'] diff --git a/src/porespy/generators/_fractals.py b/src/porespy/generators/_fractals.py index 14a543fde..9049830d1 100644 --- a/src/porespy/generators/_fractals.py +++ b/src/porespy/generators/_fractals.py @@ -1,9 +1,10 @@ import logging + import numpy as np import scipy.ndimage as spim -from porespy.tools import get_tqdm -from porespy import settings +from porespy import settings +from porespy.tools import get_tqdm tqdm = get_tqdm() logger = logging.getLogger(__name__) diff --git a/src/porespy/generators/_imgen.py b/src/porespy/generators/_imgen.py index 130cfac34..23f27035d 100644 --- a/src/porespy/generators/_imgen.py +++ b/src/porespy/generators/_imgen.py @@ -1,26 +1,28 @@ +import inspect as insp import logging +from typing import List, Literal + import numpy as np -import inspect as insp -from numba import njit -import scipy.spatial as sptl +import numpy.typing as npt import scipy.ndimage as spim +import scipy.spatial as sptl import scipy.stats as spst -from porespy import metrics -from porespy import settings -from typing import List, Literal +from numba import njit + +from porespy import metrics, settings from porespy.filters import chunked_func from porespy.tools import ( + _insert_disk_at_points, + _insert_disk_at_points_parallel, all_to_uniform, - ps_ball, - ps_disk, - get_border, extract_subsection, - insert_sphere, + get_border, get_tqdm, - _insert_disk_at_points, - _insert_disk_at_points_parallel, + insert_sphere, + ps_ball, + ps_disk, ) -import numpy.typing as npt + try: from pyedt import edt except ModuleNotFoundError: diff --git a/src/porespy/generators/_noise.py b/src/porespy/generators/_noise.py index ee5c642e9..9095347ce 100644 --- a/src/porespy/generators/_noise.py +++ b/src/porespy/generators/_noise.py @@ -1,7 +1,9 @@ +from typing import Literal + import numpy as np -from porespy.tools import all_to_uniform import psutil -from typing import Literal + +from porespy.tools import all_to_uniform def fractal_noise( diff --git a/src/porespy/generators/_pseudo_packings.py b/src/porespy/generators/_pseudo_packings.py index aa597f8c1..5f807e1e4 100644 --- a/src/porespy/generators/_pseudo_packings.py +++ b/src/porespy/generators/_pseudo_packings.py @@ -1,18 +1,21 @@ import logging +from typing import List, Literal + import numpy as np -import scipy.ndimage as spim import numpy.typing as npt +import scipy.ndimage as spim from numba import njit -from typing import Literal, List -from skimage.morphology import disk, ball +from skimage.morphology import ball, disk + +from porespy.filters import trim_disconnected_blobs from porespy.tools import ( + _insert_disk_at_point, + get_border, get_tqdm, ps_round, - get_border, unpad, - _insert_disk_at_point, ) -from porespy.filters import trim_disconnected_blobs + try: from pyedt import edt except ModuleNotFoundError: @@ -453,9 +456,10 @@ def _do_packing(im, mask, q, r, value, clearance, smooth, maxiter): if __name__ == "__main__": - import porespy as ps import matplotlib.pyplot as plt import scipy.ndimage as spim + + import porespy as ps shape = [200, 200] diff --git a/src/porespy/generators/_spheres_from_coords.py b/src/porespy/generators/_spheres_from_coords.py index c2008a1f6..c3b25a4a3 100644 --- a/src/porespy/generators/_spheres_from_coords.py +++ b/src/porespy/generators/_spheres_from_coords.py @@ -1,7 +1,8 @@ import logging + import numpy as np -from porespy.tools import _insert_disks_at_points, find_bbox +from porespy.tools import _insert_disks_at_points, find_bbox __all__ = [ 'spheres_from_coords', diff --git a/src/porespy/io/_funcs.py b/src/porespy/io/_funcs.py index 3a219d8ba..a669b1c33 100644 --- a/src/porespy/io/_funcs.py +++ b/src/porespy/io/_funcs.py @@ -1,12 +1,15 @@ import os import subprocess + import numpy as np import scipy.ndimage as nd import skimage.measure as ms from skimage.morphology import ball + from porespy.filters import reduce_peaks from porespy.networks import generate_voxel_image from porespy.tools import sanitize_filename + try: from pyedt import edt except ModuleNotFoundError: diff --git a/src/porespy/metrics/_funcs.py b/src/porespy/metrics/_funcs.py index 8e11e73d5..49c0ce58b 100644 --- a/src/porespy/metrics/_funcs.py +++ b/src/porespy/metrics/_funcs.py @@ -1,17 +1,15 @@ import logging + import numpy as np import scipy.ndimage as spim import scipy.spatial as sptl -from scipy import fft as sp_ft -from skimage.measure import regionprops from deprecated import deprecated -from porespy.tools import extend_slice -from porespy.tools import _check_for_singleton_axes -from porespy.tools import Results -from porespy import settings -from porespy.tools import get_tqdm from numba import njit +from scipy import fft as sp_ft +from skimage.measure import regionprops +from porespy import settings +from porespy.tools import Results, _check_for_singleton_axes, extend_slice, get_tqdm __all__ = [ "boxcount", diff --git a/src/porespy/metrics/_meshtools.py b/src/porespy/metrics/_meshtools.py index c4b40f09a..22bc5336d 100644 --- a/src/porespy/metrics/_meshtools.py +++ b/src/porespy/metrics/_meshtools.py @@ -1,13 +1,18 @@ import logging + import numpy as np import scipy.ndimage as spim -from porespy.tools import extend_slice, ps_round -from porespy.tools import _check_for_singleton_axes, Results -from porespy.tools import mesh_region from skimage import measure -from porespy.tools import get_tqdm -from porespy import settings +from porespy import settings +from porespy.tools import ( + Results, + _check_for_singleton_axes, + extend_slice, + get_tqdm, + mesh_region, + ps_round, +) __all__ = [ "mesh_surface_area", diff --git a/src/porespy/metrics/_regionprops.py b/src/porespy/metrics/_regionprops.py index 9c27cf7d7..aaa1991b5 100644 --- a/src/porespy/metrics/_regionprops.py +++ b/src/porespy/metrics/_regionprops.py @@ -1,12 +1,14 @@ import logging + import numpy as np import scipy.ndimage as spim from pandas import DataFrame -from porespy.tools import extract_subsection, bbox_to_slices -from skimage.measure import mesh_surface_area -from skimage.morphology import skeletonize_3d, ball -from skimage.measure import regionprops +from skimage.measure import mesh_surface_area, regionprops from skimage.measure._regionprops import RegionProperties +from skimage.morphology import ball, skeletonize_3d + +from porespy.tools import bbox_to_slices, extract_subsection + try: from skimage.measure import marching_cubes except ImportError: diff --git a/src/porespy/networks/_funcs.py b/src/porespy/networks/_funcs.py index 6c56462e3..315d107c6 100644 --- a/src/porespy/networks/_funcs.py +++ b/src/porespy/networks/_funcs.py @@ -1,16 +1,14 @@ import logging + import numpy as np import openpnm as op import scipy.ndimage as spim -from skimage.segmentation import find_boundaries from skimage.morphology import ball, cube -from porespy.tools import make_contiguous -from porespy.tools import overlay -from porespy.tools import insert_cylinder -from porespy.generators import borders -from porespy import settings -from porespy.tools import get_tqdm +from skimage.segmentation import find_boundaries +from porespy import settings +from porespy.generators import borders +from porespy.tools import get_tqdm, insert_cylinder, make_contiguous, overlay __all__ = [ "add_boundary_regions", diff --git a/src/porespy/networks/_getnet_orig.py b/src/porespy/networks/_getnet_orig.py index 95c16ecf8..22c43888d 100644 --- a/src/porespy/networks/_getnet_orig.py +++ b/src/porespy/networks/_getnet_orig.py @@ -1,14 +1,13 @@ import logging + import numpy as np import scipy.ndimage as spim -from skimage.morphology import disk, ball from edt import edt -from porespy.tools import extend_slice -from porespy import settings -from porespy.tools import get_tqdm, make_contiguous -from porespy.metrics import region_surface_areas, region_interface_areas -from porespy.metrics import region_volumes +from skimage.morphology import ball, disk +from porespy import settings +from porespy.metrics import region_interface_areas, region_surface_areas, region_volumes +from porespy.tools import extend_slice, get_tqdm, make_contiguous __all__ = [ "regions_to_network", diff --git a/src/porespy/networks/_getnet_para.py b/src/porespy/networks/_getnet_para.py index ff78afc8e..cfce81e5a 100644 --- a/src/porespy/networks/_getnet_para.py +++ b/src/porespy/networks/_getnet_para.py @@ -1,22 +1,23 @@ import logging -import numpy as np + import numba +import numpy as np +import scipy.ndimage as spim from numba import njit, prange -from numba.typed import List, Dict from numba.core import types -import scipy.ndimage as spim +from numba.typed import Dict, List + from porespy.tools import ( - jit_extend_slice, center_of_mass, -) -from porespy.tools import ( + create_mc_template_list, get_tqdm, - make_contiguous, + jit_extend_slice, jit_marching_cubes_area_and_volume, jit_marching_squares_perimeter_and_area, - create_mc_template_list, + make_contiguous, pad, ) + try: from pyedt import edt, jit_edt_cpu except ModuleNotFoundError: diff --git a/src/porespy/networks/_maximal_ball.py b/src/porespy/networks/_maximal_ball.py index 269fdefc4..2d5671a89 100644 --- a/src/porespy/networks/_maximal_ball.py +++ b/src/porespy/networks/_maximal_ball.py @@ -1,10 +1,10 @@ import logging import os -import time -import psutil import subprocess -import numpy as np +import time +import numpy as np +import psutil __all__ = [ "maximal_ball_wrapper", diff --git a/src/porespy/networks/_size_factors.py b/src/porespy/networks/_size_factors.py index 8f7a6330c..6fe5c4393 100644 --- a/src/porespy/networks/_size_factors.py +++ b/src/porespy/networks/_size_factors.py @@ -1,11 +1,13 @@ +import math + import numpy as np import scipy.ndimage as spim -import math -from porespy import settings -from porespy.tools import extend_slice from scipy.ndimage import zoom as zm from skimage.morphology import ball -from porespy.tools import get_tqdm + +from porespy import settings +from porespy.tools import extend_slice, get_tqdm + tqdm = get_tqdm() diff --git a/src/porespy/networks/_snow2.py b/src/porespy/networks/_snow2.py index 17b92208a..a9b320bb3 100644 --- a/src/porespy/networks/_snow2.py +++ b/src/porespy/networks/_snow2.py @@ -1,16 +1,19 @@ -import numpy as np import logging -from porespy.tools import Results -from porespy.networks import ( - regions_to_network, - add_boundary_regions, - label_phases, - label_boundaries, -) + +import numpy as np + from porespy.filters import ( snow_partitioning, snow_partitioning_parallel, ) +from porespy.networks import ( + add_boundary_regions, + label_boundaries, + label_phases, + regions_to_network, +) +from porespy.tools import Results + try: from pyedt import edt except ModuleNotFoundError: diff --git a/src/porespy/simulations/_drainage.py b/src/porespy/simulations/_drainage.py index 9b4d2592a..821070a02 100644 --- a/src/porespy/simulations/_drainage.py +++ b/src/porespy/simulations/_drainage.py @@ -1,17 +1,19 @@ import numpy as np + from porespy import settings -from porespy.metrics import pc_curve -from porespy.tools import ( - _insert_disks_at_points, - get_tqdm, - Results, -) from porespy.filters import ( - trim_disconnected_blobs, find_trapped_regions, pc_to_satn, satn_to_seq, + trim_disconnected_blobs, +) +from porespy.metrics import pc_curve +from porespy.tools import ( + Results, + _insert_disks_at_points, + get_tqdm, ) + try: from pyedt import edt except ModuleNotFoundError: @@ -200,10 +202,12 @@ def drainage(im, voxel_size, pc=None, inlets=None, outlets=None, residual=None, if __name__ == "__main__": + from copy import copy + + import matplotlib.pyplot as plt import numpy as np + import porespy as ps - import matplotlib.pyplot as plt - from copy import copy # %% Run this cell to regenerate the variables in drainage np.random.seed(6) diff --git a/src/porespy/simulations/_ibip.py b/src/porespy/simulations/_ibip.py index ec1ac926b..91cc9809b 100644 --- a/src/porespy/simulations/_ibip.py +++ b/src/porespy/simulations/_ibip.py @@ -1,13 +1,15 @@ import numpy as np from numba import njit + from porespy import settings from porespy.tools import ( - get_tqdm, + Results, + _insert_disk_at_points, get_border, + get_tqdm, make_contiguous, - _insert_disk_at_points, - Results, ) + try: from pyedt import edt except ModuleNotFoundError: @@ -132,10 +134,12 @@ def _update_dt_and_bd(dt, bd, pt): if __name__ == "__main__": + from copy import copy + + import matplotlib.pyplot as plt import numpy as np + import porespy as ps - import matplotlib.pyplot as plt - from copy import copy # %% Run this cell to regenerate the variables in drainage np.random.seed(6) diff --git a/src/porespy/simulations/_ibip_gpu.py b/src/porespy/simulations/_ibip_gpu.py index 499a723e8..e13eb9fbd 100644 --- a/src/porespy/simulations/_ibip_gpu.py +++ b/src/porespy/simulations/_ibip_gpu.py @@ -1,10 +1,13 @@ import logging + import numpy as np + from porespy.tools import ( - get_tqdm, - get_border, Results, + get_border, + get_tqdm, ) + try: from pyedt import edt except ModuleNotFoundError: diff --git a/src/porespy/tools/_funcs.py b/src/porespy/tools/_funcs.py index 5b3cd1a5a..4b0bfe92a 100644 --- a/src/porespy/tools/_funcs.py +++ b/src/porespy/tools/_funcs.py @@ -1,10 +1,13 @@ import logging + import numpy as np import scipy.ndimage as spim -from numba import njit, boolean -from skimage.segmentation import relabel_sequential +from numba import boolean, njit from skimage.morphology import ball, disk +from skimage.segmentation import relabel_sequential + from ._utils import Results + try: from skimage.measure import marching_cubes except ImportError: @@ -953,7 +956,7 @@ def in_hull(points, hull): to view online example. """ - from scipy.spatial import Delaunay, ConvexHull + from scipy.spatial import ConvexHull, Delaunay if isinstance(hull, ConvexHull): hull = hull.points hull = Delaunay(hull) diff --git a/src/porespy/tools/_marching_cubes.py b/src/porespy/tools/_marching_cubes.py index af4f50f4a..a484f84a5 100644 --- a/src/porespy/tools/_marching_cubes.py +++ b/src/porespy/tools/_marching_cubes.py @@ -1,12 +1,12 @@ -import os -import math import itertools +import math +import os from pathlib import Path -from numba import njit + import numpy as np -from skimage import measure +from numba import njit from scipy import spatial - +from skimage import measure MC_TEMPLATES_FILENAME = 'marching_cubes_templates.dat' THIS_FOLDER = Path(__file__).absolute().parent diff --git a/src/porespy/tools/_sphere_insertions.py b/src/porespy/tools/_sphere_insertions.py index 947247ea4..bb64dac54 100644 --- a/src/porespy/tools/_sphere_insertions.py +++ b/src/porespy/tools/_sphere_insertions.py @@ -1,7 +1,6 @@ import numpy as np from numba import njit, prange - __all__ = [ '_make_disk', '_make_disks', @@ -505,6 +504,7 @@ def _make_balls(r, smooth=True): # pragma: no cover if __name__ == "__main__": import numpy as np + from porespy.tools import tic, toc np.random.seed(0) diff --git a/src/porespy/tools/_utils.py b/src/porespy/tools/_utils.py index 5e6e8a6c0..4b1398555 100644 --- a/src/porespy/tools/_utils.py +++ b/src/porespy/tools/_utils.py @@ -1,12 +1,12 @@ -import logging -import sys -import numpy as np import importlib -from dataclasses import dataclass -import psutil import inspect +import logging +import sys import time +from dataclasses import dataclass +import numpy as np +import psutil logger = logging.getLogger("porespy") diff --git a/src/porespy/visualization/_funcs.py b/src/porespy/visualization/_funcs.py index 8535b4874..a657212f3 100644 --- a/src/porespy/visualization/_funcs.py +++ b/src/porespy/visualization/_funcs.py @@ -1,11 +1,12 @@ -import porespy as ps +from copy import copy + import matplotlib.pyplot as plt import numpy as np -from tqdm import tqdm from matplotlib import animation -from copy import copy -from porespy import settings +from tqdm import tqdm +import porespy as ps +from porespy import settings __all__ = [ 'set_mpl_style', diff --git a/src/porespy/visualization/_plots.py b/src/porespy/visualization/_plots.py index 6f76486f1..08f2372fa 100644 --- a/src/porespy/visualization/_plots.py +++ b/src/porespy/visualization/_plots.py @@ -1,8 +1,8 @@ -import numpy as np import matplotlib.pyplot as plt +import numpy as np from mpl_toolkits.mplot3d.art3d import Poly3DCollection -from porespy.tools import get_tqdm +from porespy.tools import get_tqdm __all__ = [ 'bar', diff --git a/src/porespy/visualization/_views.py b/src/porespy/visualization/_views.py index a497d8d76..99205b9f9 100644 --- a/src/porespy/visualization/_views.py +++ b/src/porespy/visualization/_views.py @@ -1,6 +1,7 @@ import numpy as np import scipy.ndimage as spim from numba import njit, prange + # from mpl_toolkits.mplot3d.art3d import Poly3DCollection diff --git a/test/integration/test_drainage.py b/test/integration/test_drainage.py index b5d7c6905..44658a326 100644 --- a/test/integration/test_drainage.py +++ b/test/integration/test_drainage.py @@ -1,6 +1,6 @@ +import matplotlib.pyplot as plt import numpy as np import porespy as ps -import matplotlib.pyplot as plt def test_drainage(): diff --git a/test/integration/test_drainage_from_top.py b/test/integration/test_drainage_from_top.py index c5bdd494e..7a1a9c804 100644 --- a/test/integration/test_drainage_from_top.py +++ b/test/integration/test_drainage_from_top.py @@ -1,6 +1,6 @@ +import matplotlib.pyplot as plt import numpy as np import porespy as ps -import matplotlib.pyplot as plt def test_drainage_from_top(): diff --git a/test/integration/test_ibip_example_script.py b/test/integration/test_ibip_example_script.py index b77872a7c..96bcaedf2 100644 --- a/test/integration/test_ibip_example_script.py +++ b/test/integration/test_ibip_example_script.py @@ -1,8 +1,9 @@ -import porespy as ps -import numpy as np -import matplotlib.pyplot as plt from copy import copy +import matplotlib.pyplot as plt +import numpy as np +import porespy as ps + def test_ibip(): np.random.seed(0) diff --git a/test/integration/test_inverse_Bo_study.py b/test/integration/test_inverse_Bo_study.py index adf563df4..a912be48d 100644 --- a/test/integration/test_inverse_Bo_study.py +++ b/test/integration/test_inverse_Bo_study.py @@ -1,7 +1,8 @@ -import numpy as np -import porespy as ps import matplotlib.pyplot as plt +import numpy as np import pandas as pd +import porespy as ps + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/integration/test_snow_example_script.py b/test/integration/test_snow_example_script.py index ba1cab19b..bfead1abd 100644 --- a/test/integration/test_snow_example_script.py +++ b/test/integration/test_snow_example_script.py @@ -1,7 +1,7 @@ -import numpy as np -import porespy as ps import matplotlib.pyplot as plt +import numpy as np import openpnm as op +import porespy as ps def test_snow_example_script(): diff --git a/test/integration/test_variable_Bo_study.py b/test/integration/test_variable_Bo_study.py index 1a45b3bd6..84100492e 100644 --- a/test/integration/test_variable_Bo_study.py +++ b/test/integration/test_variable_Bo_study.py @@ -1,7 +1,7 @@ -import pytest +import matplotlib.pyplot as plt import numpy as np import porespy as ps -import matplotlib.pyplot as plt +import pytest @pytest.mark.skip(reason="Passes locally, fails on GitHub!") diff --git a/test/unit/test_dns.py b/test/unit/test_dns.py index c26aa138a..33b9662bb 100644 --- a/test/unit/test_dns.py +++ b/test/unit/test_dns.py @@ -1,9 +1,8 @@ import numpy as np import openpnm as op -import pytest - import porespy as ps import porespy.beta +import pytest ps.settings.tqdm['disable'] = True ps.settings.loglevel = 40 diff --git a/test/unit/test_filters.py b/test/unit/test_filters.py index e5eae02d7..908535dde 100644 --- a/test/unit/test_filters.py +++ b/test/unit/test_filters.py @@ -1,9 +1,10 @@ -import pytest import numpy as np import porespy as ps +import pytest import scipy.ndimage as spim -from skimage.morphology import disk, ball, skeletonize_3d +from skimage.morphology import ball, disk, skeletonize_3d from skimage.util import random_noise + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_filters_size_seq_satn.py b/test/unit/test_filters_size_seq_satn.py index 00e23d711..a731fe4ed 100644 --- a/test/unit/test_filters_size_seq_satn.py +++ b/test/unit/test_filters_size_seq_satn.py @@ -1,6 +1,7 @@ import numpy as np import porespy as ps from edt import edt + ps.settings.tqdm['disable'] = True diff --git a/test/unit/test_generators.py b/test/unit/test_generators.py index 99eba7db8..358315129 100644 --- a/test/unit/test_generators.py +++ b/test/unit/test_generators.py @@ -1,9 +1,10 @@ -import pytest import numpy as np +import pandas as pd +import porespy as ps +import pytest import scipy.ndimage as spim import scipy.stats as spst -import porespy as ps -import pandas as pd + ps.settings.tqdm['disable'] = True diff --git a/test/unit/test_imagej.py b/test/unit/test_imagej.py index a933452c4..e485ff455 100644 --- a/test/unit/test_imagej.py +++ b/test/unit/test_imagej.py @@ -1,5 +1,6 @@ import os import sys + import porespy as ps diff --git a/test/unit/test_io.py b/test/unit/test_io.py index 11f6fdf3f..6be7220f7 100644 --- a/test/unit/test_io.py +++ b/test/unit/test_io.py @@ -1,8 +1,9 @@ import os import sys +from pathlib import Path + import numpy as np import porespy as ps -from pathlib import Path class ExportTest(): diff --git a/test/unit/test_metrics.py b/test/unit/test_metrics.py index bce53f91e..eddf80c53 100644 --- a/test/unit/test_metrics.py +++ b/test/unit/test_metrics.py @@ -1,12 +1,14 @@ import os -import pytest +from pathlib import Path + import numpy as np import porespy as ps -from skimage import io -from pathlib import Path +import pytest import scipy.ndimage as spim -from skimage.morphology import ball from numpy.testing import assert_allclose +from skimage import io +from skimage.morphology import ball + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_network_extraction.py b/test/unit/test_network_extraction.py index 6f86a7cb4..c92619b2c 100644 --- a/test/unit/test_network_extraction.py +++ b/test/unit/test_network_extraction.py @@ -1,11 +1,13 @@ import os import sys +from os.path import realpath from pathlib import Path from platform import system -from os.path import realpath -import pytest + import numpy as np import porespy as ps +import pytest + ps.settings.tqdm['disable'] = True diff --git a/test/unit/test_network_size_factor.py b/test/unit/test_network_size_factor.py index 09c029092..0941ce782 100644 --- a/test/unit/test_network_size_factor.py +++ b/test/unit/test_network_size_factor.py @@ -1,5 +1,6 @@ import numpy as np import porespy as ps + ps.settings.tqdm['disable'] = True diff --git a/test/unit/test_parallel_filters.py b/test/unit/test_parallel_filters.py index 5d3296bbe..d1580fe3f 100644 --- a/test/unit/test_parallel_filters.py +++ b/test/unit/test_parallel_filters.py @@ -1,5 +1,6 @@ import numpy as np import porespy as ps + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_simulations.py b/test/unit/test_simulations.py index 5259d3bc3..6071a39fd 100644 --- a/test/unit/test_simulations.py +++ b/test/unit/test_simulations.py @@ -1,6 +1,7 @@ -import pytest import numpy as np import porespy as ps +import pytest + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_simulations_ibip.py b/test/unit/test_simulations_ibip.py index 6770e6f14..9db16f4d6 100644 --- a/test/unit/test_simulations_ibip.py +++ b/test/unit/test_simulations_ibip.py @@ -2,6 +2,7 @@ import porespy as ps import scipy.ndimage as spim from skimage.morphology import square + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_snow2.py b/test/unit/test_snow2.py index d4b5941d8..3236f720d 100644 --- a/test/unit/test_snow2.py +++ b/test/unit/test_snow2.py @@ -1,8 +1,9 @@ import numpy as np -from scipy import stats as spst -import scipy.ndimage as spim -import porespy as ps import openpnm as op +import porespy as ps +import scipy.ndimage as spim +from scipy import stats as spst + try: from pyedt import edt except ModuleNotFoundError: diff --git a/test/unit/test_tools.py b/test/unit/test_tools.py index ac3f62526..6ed02ad87 100644 --- a/test/unit/test_tools.py +++ b/test/unit/test_tools.py @@ -1,10 +1,12 @@ import sys -import porespy as ps -import numpy as np -import scipy.spatial as sptl -import scipy.ndimage as spim + import matplotlib.pyplot as plt +import numpy as np +import porespy as ps import pytest +import scipy.ndimage as spim +import scipy.spatial as sptl + try: from pyedt import edt except ModuleNotFoundError: @@ -434,8 +436,9 @@ def test_find_bbox_3D(self): assert bbox == [[15, 15, 15], [36, 36, 36]] def test_tic_toc(self): - from porespy.tools import tic, toc from time import sleep + + from porespy.tools import tic, toc tic() sleep(1) t = toc(quiet=True) diff --git a/test/unit/test_visualization.py b/test/unit/test_visualization.py index 4deefa6c2..bdf8496ca 100644 --- a/test/unit/test_visualization.py +++ b/test/unit/test_visualization.py @@ -1,5 +1,6 @@ -import porespy as ps import numpy as np +import porespy as ps + ps.settings.tqdm['disable'] = True From c19f735518bbb94138843b30d0152d17631589bc Mon Sep 17 00:00:00 2001 From: Amin Sadeghi Date: Fri, 9 Aug 2024 11:25:07 -0400 Subject: [PATCH 5/5] style: Config ruff to check imports by default except in init files --- ruff.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 939319d47..ab26a646f 100644 --- a/ruff.toml +++ b/ruff.toml @@ -40,6 +40,7 @@ target-version = "py310" # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or # McCabe complexity (`C901`) by default. select = ["E4", "E7", "E9", "F", "W"] +extend-select = ["I"] ignore = ["E731"] # Allow fix for all enabled rules (when `--fix`) is provided. @@ -77,5 +78,5 @@ docstring-code-format = true docstring-code-line-length = "dynamic" [lint.per-file-ignores] -"__init__.py" = ["E402", "F401", "F403"] +"__init__.py" = ["E402", "F401", "F403", "I001"] "test/**" = ["F841"]