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

Numpy operations on CircuitNodeIds #169

Open
HDictus opened this issue Oct 4, 2022 · 2 comments
Open

Numpy operations on CircuitNodeIds #169

HDictus opened this issue Oct 4, 2022 · 2 comments

Comments

@HDictus
Copy link
Contributor

HDictus commented Oct 4, 2022

When CircuitNodeIds is converted to a numpy array it turns into a (N, 2) array rather than an array of N unique identifiers.
This causes issues when using e.g. np.isin, np.intersect1d.

I propose defining a custom dtype https://numpy.org/devdocs/reference/arrays.dtypes.html with both population name and id contained within it. This does mean specifying a maximum number of bytes for the population names.
We could potentially have multiple dtypes occupying different amounts of space, allowing long population names to be recast to the longer version if necessary.

There may be a way to ensure that CircuitNodeIds are automatically converted to the appropriate dtype when np.array is called on them, though I am not aware of it.
Otherwise, I guess a .toarray() method would do.

I can implement this in the next month or two, if others think it is a good idea.

@mgeplf
Copy link
Contributor

mgeplf commented Oct 4, 2022

CircuitNodeIds is converted to a numpy array it turns into

Interesting. When you say converted, do you mean np.array(some_node_ids), or implicitly like in np.isin(foo, some_node_ids) or in some other case? I think an example of what you're doing would be helpful.

@HDictus
Copy link
Contributor Author

HDictus commented Oct 5, 2022

When I do np.array(some_node_ids) I get an (N, 2) array.
when I use np.isin I just get strange results - explainable by isin interpereting the population names and ids as distinct values.
This comes up if I have some custom way of constraining a cell sample (e.g. relative position within a layer) and want to further restrict this by something else.
e.g. np.intersect1d(ids_in_depth_bin, martiotti_cells)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants