Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearest node #241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pymaid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,10 @@ def _get_node_labels_url(self, **GET):
"""Generate url for retrieving node infos (POST)."""
return self.make_url(self.project_id, 'labels-for-nodes', **GET)

def _get_nearest_node_url(self, **GET):
"""Generate url for retrieving nearest node."""
return self.make_url(self.project_id, 'nodes', 'nearest', **GET)

def _get_skeleton_nodes_url(self, skid, **GET):
"""Generate url for retrieving skeleton nodes.

Expand Down
39 changes: 39 additions & 0 deletions pymaid/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
'get_landmarks',
'get_landmark_groups',
'get_skeleton_ids',
'get_nearest_node'
]

# Set up logging
Expand Down Expand Up @@ -4726,3 +4727,41 @@ def get_skeleton_change(x, chunk_size=50, remote_instance=None):
pbar.update(len(ch))

return change




@cache.undo_on_error
def get_nearest_node(x, y, z, skeleton_id=None, neuron_id=None, remote_instance=None):
"""Get the node nearest to a query point. Optionally restricted to a single skeleton.

Parameters
----------
x : X coordinate of query location.
y : Y coordinate of query location.
z : Z coordinate of query location.
skeleton_id : Result treenode has to be in this skeleton. (optional)
neuron_id : Result treenode has to be in this neuron. (optional, altenrate to skeleton_id)
remote_instance : CatmaidInstance, optional
If not passed directly, will try using global.

Returns
-------
node
Nearest node.

"""
remote_instance = utils._eval_remote_instance(remote_instance)

GET = {'x': x, 'y': y, 'z': z}

if skeleton_id:
GET['skeleton_id'] = skeleton_id
if neuron_id:
GET['neuron_id'] = neuron_id

url = remote_instance._get_nearest_node_url(**GET)

resp = remote_instance.fetch(url, disable_pbar=True)

return resp
Loading