Skip to content

Commit

Permalink
Merge pull request #984 from PMEAL/style/apply-ruff-throghout
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-sadeghi authored Aug 9, 2024
2 parents 8faf86e + c19f735 commit 1d1fbd4
Show file tree
Hide file tree
Showing 61 changed files with 316 additions and 271 deletions.
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 6 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exclude = [
]

# Same as Black.
line-length = 95
line-length = 92
indent-width = 4

# Assume Python 3.10
Expand All @@ -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.
Expand Down Expand Up @@ -75,3 +76,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", "I001"]
"test/**" = ["F841"]
11 changes: 7 additions & 4 deletions src/porespy/beta/_drainage2.py
Original file line number Diff line number Diff line change
@@ -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()


Expand Down Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions src/porespy/beta/_gdd.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/porespy/beta/_generators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from scipy.signal import convolve
from porespy.tools import ps_rect

from porespy.tools import ps_rect

__all__ = [
"local_diff",
Expand Down
5 changes: 3 additions & 2 deletions src/porespy/beta/_poly_cylinders.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np

from porespy import settings
from porespy.tools import get_tqdm


tqdm = get_tqdm()


Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/porespy/dns/_funcs.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/porespy/filters/_fftmorphology.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from scipy.signal import fftconvolve


__all__ = [
"fftmorphology",
]
Expand Down
28 changes: 19 additions & 9 deletions src/porespy/filters/_funcs.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 4 additions & 3 deletions src/porespy/filters/_nlmeans.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/porespy/filters/_size_seq_satn.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
28 changes: 17 additions & 11 deletions src/porespy/filters/_snows.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -359,7 +366,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)
Expand Down Expand Up @@ -567,8 +574,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:
Expand Down
2 changes: 1 addition & 1 deletion src/porespy/filters/imagej/_funcs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import numpy as np

import numpy as np

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/porespy/generators/_borders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from typing import Literal

import numpy as np

__all__ = ['faces', 'borders']

Expand Down
5 changes: 3 additions & 2 deletions src/porespy/generators/_fractals.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down
28 changes: 15 additions & 13 deletions src/porespy/generators/_imgen.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
21 changes: 12 additions & 9 deletions src/porespy/generators/_noise.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -10,7 +12,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,
Expand All @@ -23,9 +25,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.
Expand Down Expand Up @@ -87,14 +89,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
Expand Down
Loading

0 comments on commit 1d1fbd4

Please sign in to comment.