diff --git a/pymaid/client.py b/pymaid/client.py index 0148daa..7546fc7 100644 --- a/pymaid/client.py +++ b/pymaid/client.py @@ -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. diff --git a/pymaid/fetch/__init__.py b/pymaid/fetch/__init__.py index c70e3f8..d156a58 100644 --- a/pymaid/fetch/__init__.py +++ b/pymaid/fetch/__init__.py @@ -91,6 +91,7 @@ 'get_landmarks', 'get_landmark_groups', 'get_skeleton_ids', + 'get_nearest_node' ] # Set up logging @@ -4909,3 +4910,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 split and merge history of skeletons. + + 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