Skip to content

Commit

Permalink
Merge pull request #2931 from PMEAL/patch-1
Browse files Browse the repository at this point in the history
Fixed deprecation error coming from new Scipy and Numpy versions #maint
  • Loading branch information
jgostick authored Aug 7, 2024
2 parents c6c2d5c + 18d004e commit 81d7c64
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions openpnm/_skgraph/generators/tools/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_centroid(pts, mode='rigorous'):
if mode == 'rigorous':
tri = sptl.Delaunay(pts)
CoM = center_of_mass(simplices=tri.simplices.astype(np.int_),
points=tri.points.astype(np.float_))
points=tri.points.astype(float))
elif mode == 'fast':
CoM = pts.mean(axis=0)
return CoM
Expand All @@ -99,11 +99,11 @@ def get_centroid(pts, mode='rigorous'):
# @njit
def center_of_mass(simplices, points):
A = []
centroids = np.zeros((simplices.shape[0], points.shape[1]), dtype=np.float_)
centroids = np.zeros((simplices.shape[0], points.shape[1]), dtype=float)
for i, s in enumerate(simplices):
xy = points[s]
cen = np.sum(points[s], axis=0)/simplices.shape[1]
centroids[i, :] = cen.astype(np.float_)
centroids[i, :] = cen.astype(float)
if xy.shape[1] == 2: # In 2D
# Use Heron's formula to find area of arbitrary triangle
a = np.sqrt((xy[0, 0] - xy[1, 0])**2 + (xy[0, 1] - xy[1, 1])**2)
Expand All @@ -117,9 +117,9 @@ def center_of_mass(simplices, points):
temp = np.abs(np.linalg.det(d))/6.0
# temp = 0
A.append(temp)
A = np.array(A, dtype=np.float_)
A = np.array(A, dtype=float)
CoM = np.array([(centroids[:, i]*A/A.sum()*len(A)).mean()
for i in range(centroids.shape[1])], dtype=np.float_)
for i in range(centroids.shape[1])], dtype=float)
return CoM


Expand Down
8 changes: 5 additions & 3 deletions openpnm/algorithms/_reactive_transport.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import logging
import sys

import numpy as np
from numpy.linalg import norm
from scipy.optimize.nonlin import TerminationCondition
try: # For scipy < 1.14
from scipy.optimize.nonlin import TerminationCondition
except ImportError: # For newer Scipy
from scipy.optimize._nonlin import TerminationCondition
from tqdm.auto import tqdm

from openpnm.algorithms import Transport
from openpnm.utils import Docorator, TypedList


__all__ = ["ReactiveTransport"]


Expand Down
5 changes: 4 additions & 1 deletion openpnm/solvers/_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ def solve(self, A, b, **kwargs):
if not isinstance(A, (csr_matrix, csc_matrix)):
A = A.tocsr()
atol = self._get_atol(b)
return cg(A, b, tol=self.tol, atol=atol, **kwargs)
try:
return cg(A, b, tol=self.tol, atol=atol, **kwargs)
except TypeError:
return cg(A, b, rtol=self.tol, atol=atol, **kwargs)
4 changes: 2 additions & 2 deletions openpnm/visualization/_plottools.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def plot_tutorial(network,
fig = plt.gcf()
fig.tight_layout()
dims = op.topotools.dimensionality(network)
xy_range = network.coords.ptp(axis=0)[dims]
xy_range = np.ptp(network.coords, axis=0)[dims]
aspect_ratio = xy_range[0] / xy_range[1]
fig.set_size_inches(5, 5 / aspect_ratio)

Expand Down Expand Up @@ -781,7 +781,7 @@ def _generate_voxel_image(network, pore_shape, throat_shape, max_dim=200):
# Transform points to satisfy origin at (0, 0, 0)
xyz0 = xyz.min(axis=0) - delta
xyz += -xyz0
res = (xyz.ptp(axis=0).max() + 2 * delta) / max_dim
res = (np.ptp(xyz, axis=0).max() + 2 * delta) / max_dim
shape = np.rint((xyz.max(axis=0) + delta) / res).astype(int) + 2 * extra_clearance

# Transforming from real coords to matrix coords
Expand Down

0 comments on commit 81d7c64

Please sign in to comment.