Skip to content

Commit

Permalink
Merge pull request #921 from PMEAL/maint/pyproject.toml
Browse files Browse the repository at this point in the history
- Migrated from setup.py to pyproject.toml #maint
- Migrated from flat layout to the PyPA recommended src layout #maint
  • Loading branch information
ma-sadeghi authored Mar 10, 2024
2 parents 8b9c0cb + 202bc53 commit e0b3e02
Show file tree
Hide file tree
Showing 57 changed files with 110 additions and 119 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ cython_debug/
*.pyc
*.nblink

# OpenPNM
*.mphtxt
docs/_build/
docs/**/generated
docs/examples

examples/networks/*.vt*

.vscode/
84 changes: 84 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[project]
name = "porespy"
dynamic = ["version"]
description = "A set of tools for analyzing 3D images of porous materials"
authors = [{ name = "PoreSpy Team", email = "jgostick@gmail.com" }]
maintainers = [
{ name = "Jeff Gostick", email = "jgostick@gmail.com" },
{ name = "Amin Sadeghi", email = "amin.sadeghi@live.com" },
]
license = "MIT"
keywords = [
"voxel images",
"porous materials",
"image analysis",
"direct numerical simulation",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
]
dependencies = [
"dask",
"deprecated",
"edt",
"matplotlib",
"numba",
"numpy",
"openpnm",
"pandas",
"psutil",
"rich",
"scikit-image",
"scipy",
"tqdm",
"pywavelets",
"nanomesh",
"setuptools",
]
readme = "README.md"
requires-python = ">= 3.8"

[project.urls]
Homepage = "https://porespy.org"
Repository = "https://github.com/PMEAL/porespy"
"Bug Tracker" = "https://github.com/PMEAL/porespy/issues"
Documentation = "https://porespy.org/"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = [
"pytest",
"hatch",
"numpy-stl",
"pyevtk",
"trimesh",
"ipykernel",
"pypardiso",
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.version]
path = "src/porespy/__version__.py"

[tool.hatch.build.targets.wheel]
packages = ["src/porespy"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -v"
testpaths = ["test"]

[tool.ruff]
line-length = 92
98 changes: 0 additions & 98 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions porespy/beta/_dns_tools.py → src/porespy/beta/_dns_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def flux(c, axis, k=None):
"""
k = np.ones_like(c) if k is None else np.array(k)
# Compute the gradient of the concentration field using forward diff
dcdX = convolve1d(c, weights=np.array([-1, 1]), axis=axis)
dcdX = convolve1d(c, weights=np.array([-1.0, 1.0]), axis=axis)
# dcdX @ outlet is incorrect due to forward diff -> use backward
_fix_gradient_outlet(dcdX, axis)
# Compute the conductivity at the faces using resistors in series
Expand Down Expand Up @@ -83,10 +83,11 @@ def _fix_gradient_outlet(J, axis):
J_outlet[:] = J_penultimate_layer


def _slice_view(a, i, axis):
def _slice_view(a, idx, axis):
"""Returns a slice view of the array along the given axis."""
# Example: _slice_view(a, i=5, axis=1) -> a[:, 5, :]
sl = [slice(None)] * a.ndim
sl[axis] = i
sl[axis] = idx
return a[tuple(sl)]


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 7 additions & 5 deletions porespy/io/_funcs.py → src/porespy/io/_funcs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os
import subprocess

import numpy as np
import scipy.ndimage as nd
import skimage.measure as ms
from porespy.tools import sanitize_filename
from porespy.networks import generate_voxel_image
from porespy.filters import reduce_peaks
from skimage.morphology import ball
from edt import edt
from skimage.morphology import ball

from porespy.filters import reduce_peaks
from porespy.networks import generate_voxel_image
from porespy.tools import sanitize_filename


def dict_to_vtk(data, filename, voxel_size=1, origin=(0, 0, 0)):
Expand Down Expand Up @@ -289,7 +291,7 @@ def _save_stl(im, vs, filename):
from stl import mesh
except ModuleNotFoundError:
msg = 'numpy-stl can be installed with pip install numpy-stl'
ModuleNotFoundError(msg)
raise ModuleNotFoundError(msg)
im = np.pad(im, pad_width=10, mode="constant", constant_values=True)
vertices, faces, norms, values = ms.marching_cubes(im)
vertices *= vs
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 13 additions & 11 deletions porespy/simulations/_dns.py → src/porespy/simulations/_dns.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import logging

import numpy as np
import openpnm as op

from porespy.filters import trim_nonpercolating_paths
from porespy.tools import Results
from porespy.generators import faces

from porespy.tools import Results

logger = logging.getLogger(__name__)
ws = op.Workspace()


__all__ = ['tortuosity_fd']
__all__ = ["tortuosity_fd"]


def tortuosity_fd(im, axis, solver=None):
Expand Down Expand Up @@ -56,7 +57,7 @@ def tortuosity_fd(im, axis, solver=None):
"""
if axis > (im.ndim - 1):
raise Exception(f"'axis' must be <= {im.ndim}")
openpnm_v3 = op.__version__.startswith('3')
openpnm_v3 = op.__version__.startswith("3")

# Obtain original porosity
eps0 = im.sum(dtype=np.int64) / im.size
Expand All @@ -68,17 +69,17 @@ def tortuosity_fd(im, axis, solver=None):
# Check if porosity is changed after trimmimg floating pores
eps = im.sum(dtype=np.int64) / im.size
if not eps:
raise Exception('No pores remain after trimming floating pores')
raise Exception("No pores remain after trimming floating pores")
if eps < eps0: # pragma: no cover
logger.warning('Found non-percolating regions, were filled to percolate')
logger.warning("Found non-percolating regions, were filled to percolate")

# Generate a Cubic network to be used as an orthogonal grid
net = op.network.CubicTemplate(template=im, spacing=1.0)
if openpnm_v3:
phase = op.phase.Phase(network=net)
else:
phase = op.phases.GenericPhase(network=net)
phase['throat.diffusive_conductance'] = 1.0
phase["throat.diffusive_conductance"] = 1.0
# Run Fickian Diffusion on the image
fd = op.algorithms.FickianDiffusion(network=net, phase=phase)
# Choose axis of concentration gradient
Expand All @@ -94,9 +95,9 @@ def tortuosity_fd(im, axis, solver=None):
fd._update_A_and_b()
fd.x, info = solver.solve(fd.A.tocsr(), fd.b)
if info:
raise Exception(f'Solver failed to converge, exit code: {info}')
raise Exception(f"Solver failed to converge, exit code: {info}")
else:
fd.settings.update({'solver_family': 'scipy', 'solver_type': 'cg'})
fd.settings.update({"solver_family": "scipy", "solver_type": "cg"})
fd.run()

# Calculate molar flow rate, effective diffusivity and tortuosity
Expand All @@ -108,7 +109,7 @@ def tortuosity_fd(im, axis, solver=None):
L = im.shape[axis]
A = np.prod(im.shape) / L
# L-1 because BCs are put inside the domain, see issue #495
Deff = r_in * (L-1)/A / dC
Deff = r_in * (L - 1) / A / dC
tau = eps / Deff

# Attach useful parameters to Results object
Expand All @@ -119,8 +120,9 @@ def tortuosity_fd(im, axis, solver=None):
result.original_porosity = eps0
result.effective_porosity = eps
conc = np.zeros(im.size, dtype=float)
conc[net['pore.template_indices']] = fd['pore.concentration']
conc[net["pore.template_indices"]] = fd["pore.concentration"]
result.concentration = conc.reshape(im.shape)
result.sys = fd.A, fd.b

# Free memory
ws.close_project(net.project)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e0b3e02

Please sign in to comment.