CAVEconnectome / CAVEclient

This is the python client for accessing REST APIs within the Connectome Annotation Versioning Engine.
https://caveconnectome.github.io/CAVEclient/
MIT License
19 stars 12 forks source link

Querying synapses with bounding box fails #137

Open javierhow opened 5 months ago

javierhow commented 5 months ago

Hello!

I tried to run

Load synapse table

datastack_name = 'minnie65_public' client = CAVEclient(datastack_name) synapse_table = client.info.get_datastack_info()['synapse_table'] df=client.materialize.query_table(synapse_table, bounding_box = [[0,0,0], [10, 10, 10]])

but this failed with error. TypeError: query_table() got an unexpected keyword argument 'bounding_box'

Any idea why?

Thanks! Javier

bdpedigo commented 5 months ago

Hey @javierhow!

I think you are looking for filter_spatial - see https://caveclient.readthedocs.io/en/latest/api/caveclient.html#caveclient.materializationengine.MaterializatonClientV2.query_table

javierhow commented 5 months ago

Hey Ben!

Hope you're having a good time.

I tried

dt = dict() dt['ctr_pt_position'] = [[0, 0, 0], [10, 10, 10]] df = client.materialize.query_table('synapse_table', filter_spatial=dt)

and it failed, too (TypeError: query_table() got an unexpected keyword argument 'filter_spatial').

Javi

bdpedigo commented 5 months ago

hi @javierhow - my mistake, the docs for that parameter are wrong (opened a PR to fix it) but it should be filter_spatial_dict. The following worked for me as an example:

import caveclient as cc

client = cc.CAVEclient("minnie65_public")

min_x = 208876 - 10000 / 4
min_y = 86590 - 10000 / 4
min_z = 24931 - 10000 / 40
max_x = 208876 + 10000 / 4
max_y = 86590 + 10000 / 4
max_z = 24931 + 10000 / 40
bounding_box = [[min_x, min_y, min_z], [max_x, max_y, max_z]]

synapse_table = client.info.get_datastack_info()["synapse_table"]

df = client.materialize.query_table(
    synapse_table,
    filter_equal_dict={"pre_pt_root_id": 864691135697251738},
    filter_spatial_dict={"pre_pt_position": bounding_box},
)

which found me 3 synapses.

Just a note: it was taking a while to run for me without filter_equal_dict set to something, I was too impatient to see how long it would really take

javierhow commented 5 months ago

Thanks! That worked.

I would like to look for everything in that bounding box without my request timing out – is that possible? Should I open a new issue?

ceesem commented 5 months ago

Javier, glad to see you using CAVE! There's very little we are doing other than passing the query off to PostGIS. It seems like these spatial queries are not particularly fast for large tables and are strongly limited by the performance of your SQL server (how much CPU and ram it's allocated, etc).

I would recommend chopping up your field of view into smaller regions and iterating over it. For a start, I would leave two of the dimensions in place and see how small you have to make the third before you start having reasonable performance.

We're starting to work on updated documentation, and a recipe along these lines would be a good one.

javierhow commented 5 months ago

Hello again Casey! :)

It looks like it always takes 8.6 minutes, no matter how large a field of view. It also looks like it always searches for locations in the native 4 x 4 x 40 nm resolution, even when I pass a desired_resolution parameter. Is that a mistake?