Skip to content

Commit

Permalink
Int replaced by floor to accept negative coordinates. (#3264)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Robert A McDougal <[email protected]>
  • Loading branch information
ceciliaromaro and ramcdougal authored Dec 3, 2024
1 parent 5fe797a commit 95b14c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 8 additions & 6 deletions share/lib/python/neuron/rxd/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
_concentration_node = 0
_molecule_node = 1

_floor = numpy.floor


def _get_data():
return (_volumes, _surface_area, _diffs)
Expand Down Expand Up @@ -650,9 +652,9 @@ def satisfies(self, condition):
x, y, z = condition
mesh = self._r._mesh_grid
return (
int((x - mesh["xlo"]) / mesh["dx"]) == self._i
and int((y - mesh["ylo"]) / mesh["dy"]) == self._j
and int((z - mesh["zlo"]) / mesh["dz"]) == self._k
_floor((x - mesh["xlo"]) / mesh["dx"]) == self._i
and _floor((y - mesh["ylo"]) / mesh["dy"]) == self._j
and _floor((z - mesh["zlo"]) / mesh["dz"]) == self._k
)
# check for a position condition so as to provide a more useful error
checked_for_normalized_position = False
Expand Down Expand Up @@ -885,8 +887,8 @@ def satisfies(self, condition):
x, y, z = condition
r = self._regionref()
return (
int((x - r._xlo) / r._dx[0]) == self._i
and int((y - r._ylo) / r._dx[1]) == self._j
and int((z - r._zlo) / r._dx[2]) == self._k
_floor((x - r._xlo) / r._dx[0]) == self._i
and _floor((y - r._ylo) / r._dx[1]) == self._j
and _floor((z - r._zlo) / r._dx[2]) == self._k
)
raise RxDException(f"unrecognized node condition: {condition}")
7 changes: 7 additions & 0 deletions test/rxd/3d/test_node_selection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import weakref


def test_node_selection(neuron_instance):
"""Test selection of 3D nodes"""

Expand All @@ -16,4 +19,8 @@ def test_node_selection(neuron_instance):
assert nodes((5.2, 0.1, 0.3))[0].x3d == 5.125
assert nodes((5.2, 0.1, 0.3))[0].y3d == 0.125
assert nodes((5.2, 0.1, 0.3))[0].z3d == 0.375

nodes.append(rxd.node.Node3D(0, -1, 0, 0, cyt, 0, dend(0.5), weakref.ref(c)))

assert len(nodes((5, 0, 0))) == 1
assert nodes[-1] in nodes((nodes[-1].x3d, nodes[-1].y3d, nodes[-1].z3d))

0 comments on commit 95b14c9

Please sign in to comment.