Skip to content

Commit 74e8404

Browse files
committed
Update to be compatible with newer versions of dolfinx and scipy
1 parent 505f8f1 commit 74e8404

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/neuron_morphology/transforms/streamline.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def solve_laplace_2d(V: fem.FunctionSpace,
3131
a = ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx
3232
L = f * v * ufl.dx
3333

34-
problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
34+
problem = LinearProblem(a, L, bcs=bcs,
35+
petsc_options_prefix="laplace_2d_linear_problem",
36+
petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
3537
uh = problem.solve()
3638

3739
return uh
@@ -48,7 +50,9 @@ def compute_gradient(uh, W, bcs=[]):
4850
a = ufl.inner(u, v) * dx
4951
L = ufl.inner(f, v) * dx
5052

51-
problem = LinearProblem(a, L, bcs=bcs, petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
53+
problem = LinearProblem(a, L, bcs=bcs,
54+
petsc_options_prefix="compute_gradient_linear_problem",
55+
petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
5256
grad_uh = problem.solve()
5357

5458
return grad_uh
@@ -132,8 +136,9 @@ def generate_laplace_field(top_line: List[Tuple],
132136
facet_markers = mesh_data.facet_tags
133137

134138
# Create variational space
135-
V = fem.FunctionSpace(domain, ("CG", 1))
136-
W = fem.VectorFunctionSpace(domain, ("CG", 1))
139+
V = fem.functionspace(domain, ("CG", 1))
140+
gdim = domain.geometry.dim
141+
W = fem.functionspace(domain, ("CG", 1, (gdim, )))
137142

138143
# Create boundary conditions
139144
top_ls = geo.LineString(top_line)

src/neuron_morphology/transforms/upright_angle/compute_angle.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import copy as cp
55

66
import numpy as np
7-
from scipy.interpolate import interp2d
7+
from scipy.interpolate import RectBivariateSpline
88
import xarray as xr
99

1010
from argschema.argschema_parser import ArgSchemaParser
@@ -53,14 +53,16 @@ def get_upright_angle(gradient: xr.DataArray,
5353
ny_idx - n_win:ny_idx + n_win,
5454
:]
5555

56-
# Also transpose because if x=m,y=n, interp2d requires z=(n,m)
57-
f_dx = interp2d(x_win, y_win, values_win[:, :, 0].T)
58-
f_dy = interp2d(x_win, y_win, values_win[:, :, 1].T)
56+
r_x = RectBivariateSpline(x_win, y_win, values_win[:, :, 0])
57+
f_dx = lambda xnew, ynew: r_x(xnew, ynew).T
58+
59+
r_y = RectBivariateSpline(x_win, y_win, values_win[:, :, 1])
60+
f_dy = lambda xnew, ynew: r_y(xnew, ynew).T
5961

6062
dx = f_dx(x_point, y_point)
6163
dy = f_dy(x_point, y_point)
6264

63-
return np.pi / 2 - np.arctan2(dy[0], dx[0])
65+
return np.pi / 2 - np.arctan2(dy[0, 0], dx[0, 0])
6466

6567
def calculate_transform(gradient_field: xr.DataArray,
6668
morph: Morphology,

0 commit comments

Comments
 (0)