navis-org / pymaid

Python library to interface with CATMAID servers. Fully interoperable with navis.
https://pymaid.readthedocs.io/en/latest/
GNU General Public License v3.0
23 stars 11 forks source link

get_node_list in delete_nodes sometimes fails to get connector link IDs #207

Closed jasper-tms closed 3 years ago

jasper-tms commented 3 years ago

This is me troubleshooting what seems to be a pretty narrow corner case, but thought I'd share because at the end of the day I do have a small code change to recommend that may help avoid this corner case for other users.

When attempting to pymaid.delete_nodes on some connectors, something was going wrong resulting an

HTTPError: 1 errors encountered: 400 Server Error: Bad Request for url: https://radagast.hms.harvard.edu/catmaidvnc/59/connector/delete`.

I printed out a bunch of stuff to see what was going on. I saw that posts that result in successful connector deletion look something like

[{'connector_id': 16613852, 'state': '{"edition_time": "2020-11-25T02:21:25.108606+00:00", "c_links": [[1137789, "2020-12-22T08:27:05.373530+00:00"], [1140118, "2020-12-22T08:36:07.226915+00:00"]]}'}]

but for the attempt that was failing, the post looked like

[{'connector_id': 16597757, 'state': '{"edition_time": "2020-11-25T02:20:31.963324+00:00", "c_links": []}'}]

Clearly the difference is that c_links is empty, when I guess it shouldn't be. I see your comment here indicating that your method of getting connector link IDs is somewhat hacky because the catmaid API doesn't provide a clean way of getting these. I worked a few steps backwards and saw that indeed the server response here that was supposed to contain connector link IDs instead didn't. Here's the connectors part of one such response returned by that fetch command:

[16989778, 211049.25, 109958.305, 62340.824, 5, 1608625570.107799, 4, [[17188227, 488714, 5, 1608626159.764512, 1140031]]], [16896854, 212393.66, 112210.16, 62555.81, 5, 1608625223.608904, 4, [[16896420, 488713, 5, 1608625225.131714, 1135691]]], [16989801, 208964.06, 113048.88, 62459.54, 5, 1608625570.215746, 4, [[16989414, 488713, 5, 1608625571.797913, 1137380]]], [16597757, 210124.06, 112086.64, 62370.844, 5, 1606270831.963324, 4, []], [17423908, 210123.78, 112087.39, 62370.766, 5, 1608626846.909781, 4, [[17423795, 488713, 5, 1608626847.57475, 1143193]]]

You can see that connector ID 16597757 is in this response, but there are no links associated with it. I didn't investigate why sometimes connector IDs fail to be returned by this API endpoint, but I found a workaround that worked at least in this one instance: change this line from 'z1': n.z to 'z1': n.z - 40. After making this change, the connector link IDs were returned for this connector, and therefore connector deletion command succeeded. So yea, I don't know what exactly is going on here, but perhaps it would be good to make this small change in pymaid to possibly eliminate some corner case where the connector link IDs don't get returned. Or, if you know more about what's happening, perhaps you can see a better fix that deals with what's going on more appropriately.

Unfortunately I may not be able to reproduce this bug anymore since I've now deleted this connector, and it's a rare occurrence.

schlegelp commented 3 years ago

Hi Jasper. Good catch! Perhaps there is a floating point issue with the coordinates for some node/connector links? 'z1': n.z - 40 makes the search window larger but I doubt that will slow things down - happy to make that change! A similar query is also made in push_new_root - I will add the -40 for good measure there too.

schlegelp commented 3 years ago

Fixed with f6aa8c06429a0bf85f5894a667325a1f7368da0a. Will release a new version in the next couple days and close this issue afterwards.

schlegelp commented 3 years ago

Forgot about this. New version 2.0.4 was released a week ago.