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

Add coordinate-based coactivation-based parcellation class #533

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08ae309
Add n option to get_studies_by_coordinate
tsalo Jun 30, 2021
88d5c05
Mock up maybe passable CoordCBP class.
tsalo Jun 30, 2021
3ce90f1
Fix docstrings.
tsalo Jun 30, 2021
40f4585
Don't calculate distances.
tsalo Jul 1, 2021
530048f
Remove extra newline.
tsalo Jul 1, 2021
8382704
Clustering should be fairly good. Still need to implement metrics.
tsalo Jul 1, 2021
c79b251
Add empty methods for the different metrics.
tsalo Jul 1, 2021
3e2d580
Work on filter-selection metric. Far from done.
tsalo Jul 1, 2021
3365d5c
Add a couple of metrics.
tsalo Jul 1, 2021
7081604
Improve metric documentation.
tsalo Jul 2, 2021
12cddec
VI should be fairly good now.
tsalo Jul 2, 2021
7023291
Merge branch 'main' into coord-cbp
tsalo Jul 9, 2021
f37751a
Draft voxel misclassification metric.
tsalo Jul 9, 2021
f555790
Merge branch 'main' into coord-cbp
tsalo Jul 12, 2021
0896745
Draft another metric.
tsalo Jul 14, 2021
f9611db
Little cleanup.
tsalo Jul 14, 2021
909c822
Move ratio calculations to main fit method.
tsalo Jul 14, 2021
65857d1
More cleanup.
tsalo Jul 14, 2021
65b9675
More work and debugging.
tsalo Jul 14, 2021
118e718
Mention re-labeling (not implemented).
tsalo Jul 15, 2021
267a135
Merge branch 'main' into coord-cbp
tsalo Dec 21, 2021
530a4de
Remove added line.
tsalo Dec 21, 2021
e58a9d9
Merge branch 'main' into coord-cbp
tsalo Apr 20, 2022
a1bcf0f
Merge remote-tracking branch 'upstream/main' into jperaza-coord-cbp
JulioAPeraza Jul 25, 2022
1c352f7
Update test_dataset.py
JulioAPeraza Oct 4, 2022
917e943
Merge branch 'main' into coord-cbp
JulioAPeraza Oct 4, 2022
0c60dd5
Update utils.py
JulioAPeraza Oct 4, 2022
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
41 changes: 32 additions & 9 deletions nimare/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ def get_studies_by_label(self, labels=None, label_threshold=0.001):
the labels above the threshold, it will be returned.
Default is None.
label_threshold : :obj:`float`, optional
Default is 0.5.
Default is 0.001, which corresponds to terms appearing at least once in abstracts
for the commonly-used Neurosynth TF-IDF feature set.

Returns
-------
Expand Down Expand Up @@ -657,27 +658,49 @@ def get_studies_by_mask(self, mask):
found_ids = list(self.coordinates.loc[distances, "id"].unique())
return found_ids

def get_studies_by_coordinate(self, xyz, r=20):
def get_studies_by_coordinate(self, xyz, r=None, n=None):
"""Extract list of studies with at least one focus within radius of requested coordinates.

.. versionchanged:: 0.0.9

New option (n) supported to identify closest n studies to coordinate.
Default value for r changed to None.

Parameters
----------
xyz : (X x 3) array_like
List of coordinates against which to find studies.
r : :obj:`float`, optional
Radius (in mm) within which to find studies. Default is 20mm.
Radius (in mm) within which to find studies. Mutually exclusive with ``n``.
Default is None.
n : :obj:`int`, optional
Number of closest studies to identify. Mutually exclusive with ``r``.
Default is None.

Returns
-------
found_ids : :obj:`list`
A list of IDs from the Dataset with at least one focus within
radius r of requested coordinates.
A list of IDs from the Dataset matching the search criterion.
"""
if n and r:
raise ValueError("Only one of 'r' and 'n' may be provided.")
elif not n and not r:
raise ValueError("Either 'r' or 'n' must be provided.")

from scipy.spatial.distance import cdist

xyz = np.array(xyz)
temp_coords = self.coordinates.copy()

xyz = np.atleast_2d(xyz)
assert xyz.shape[1] == 3 and xyz.ndim == 2
distances = cdist(xyz, self.coordinates[["x", "y", "z"]].values)
distances = np.any(distances <= r, axis=0)
found_ids = list(self.coordinates.loc[distances, "id"].unique())
distances = cdist(xyz, temp_coords[["x", "y", "z"]].values)
distances = np.min(distances, axis=0)
temp_coords["distance"] = distances
min_dist_ser = temp_coords.groupby("id")["distance"].min()

if r:
found_ids = min_dist_ser.loc[min_dist_ser <= r].index.tolist()
elif n:
found_ids = min_dist_ser.nsmallest(n).index.tolist()

return found_ids
Loading