Skip to content

Commit 71d7799

Browse files
authored
[ENH] implement methods and test the nimads methods (#921)
* implement methods and test the nimads methods * formatting * show more functionality * remove useless test
1 parent ce11992 commit 71d7799

File tree

4 files changed

+631
-61
lines changed

4 files changed

+631
-61
lines changed

examples/01_datasets/05_plot_nimads.py

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
Using NIMADS with NiMARE
77
========================
88
9-
How to use the NeuroImaging Meta-Analysis Data Structure
10-
`(NIMADS) <https://neurostuff.github.io/NIMADS/>`_ with NiMARE.
9+
This example demonstrates the key functionality of the NeuroImaging Meta-Analysis Data Structure
10+
(NIMADS) with NiMARE, including working with StudySets, annotations, coordinates, and metadata.
1111
"""
12+
13+
from pprint import pprint
1214
from requests import request
1315

14-
from nimare.io import convert_nimads_to_dataset
1516
from nimare.nimads import Studyset
1617

18+
1719
###############################################################################
1820
# Download Data from NeuroStore
1921
# -----------------------------------------------------------------------------
@@ -25,32 +27,103 @@ def download_file(url):
2527
return response.json()
2628

2729

30+
# Download a studyset and its annotation
2831
nimads_studyset = download_file("https://neurostore.org/api/studysets/Cv2LLUqG76W9?nested=true")
2932
nimads_annotation = download_file("https://neurostore.org/api/annotations/76PyNqoTNEsE")
3033

3134

3235
###############################################################################
33-
# Load Data
36+
# Create and Explore StudySet
3437
# -----------------------------------------------------------------------------
35-
# Load the json files into a NiMADS Studyset object.
38+
# Load the data into a NiMADS Studyset object and explore its contents
3639

3740
studyset = Studyset(nimads_studyset, annotations=nimads_annotation)
3841

42+
# Display basic information about the studyset
43+
print("\nStudySet Information:")
44+
print("-" * 50)
45+
print(f"ID: {studyset.id}")
46+
print(f"Name: {studyset.name}")
47+
print(f"Number of studies: {len(studyset.studies)}")
48+
print(f"Number of annotations: {len(studyset.annotations)}")
49+
3950

4051
###############################################################################
41-
# Convert to NiMARE Dataset
52+
# Explore Studies and Analyses
4253
# -----------------------------------------------------------------------------
43-
# Convert the NiMADS Studyset object to a NiMARE Dataset object.
44-
# Then you can run NiMARE analyses on the Dataset object.
54+
# Look at the first study and its analyses in detail
55+
56+
first_study = studyset.studies[0]
57+
print("\nFirst Study Details:")
58+
print("-" * 50)
59+
print(f"Study ID: {first_study.id}")
60+
print(f"Title: {first_study.name}")
61+
print(f"Authors: {first_study.authors}")
62+
print(f"Publication: {first_study.publication}")
63+
print(f"Number of analyses: {len(first_study.analyses)}")
64+
65+
# Show details of the first analysis
66+
first_analysis = first_study.analyses[0]
67+
print("\nFirst Analysis Details:")
68+
print("-" * 50)
69+
print(f"Analysis ID: {first_analysis.id}")
70+
print(f"Analysis Name: {first_analysis.name}")
71+
print(f"Number of coordinates: {len(first_analysis.points)}")
72+
print(f"Number of conditions: {len(first_analysis.conditions)}")
73+
74+
75+
###############################################################################
76+
# Working with Coordinates
77+
# -----------------------------------------------------------------------------
78+
# Demonstrate coordinate-based queries
79+
80+
# Example coordinate in MNI space
81+
example_coord = [-42, -58, -15] # MNI coordinates
82+
print("\nCoordinate Search Results:")
83+
print("-" * 50)
84+
print(f"Searching near coordinate: {example_coord}")
85+
86+
# Find analyses with coordinates within 10mm
87+
nearby_analyses = studyset.get_analyses_by_coordinates(example_coord, r=10)
88+
print(f"\nFound {len(nearby_analyses)} analyses within 10mm")
89+
90+
# Find 5 closest analyses
91+
closest_analyses = studyset.get_analyses_by_coordinates(example_coord, n=5)
92+
print(f"\nClosest 5 analyses: {closest_analyses}")
4593

46-
nimare_dset = studyset.to_dataset()
47-
nimare_dset.coordinates.head()
4894

4995
###############################################################################
50-
# Directly to NiMARE Dataset
96+
# Working with Annotations
5197
# -----------------------------------------------------------------------------
52-
# Alternatively, you can convert the NiMADS json files directly to a NiMARE Dataset object
53-
# if you wish to skip using the nimads studyset object directly.
98+
# Demonstrate how to work with study annotations
5499

55-
nimare_dset_2 = convert_nimads_to_dataset(nimads_studyset, nimads_annotation)
56-
nimare_dset_2.coordinates.head()
100+
print("\nAnnotation Information:")
101+
print("-" * 50)
102+
for annotation in studyset.annotations:
103+
print(f"\nAnnotation ID: {annotation.id}")
104+
print(f"Annotation Name: {annotation.name}")
105+
print(f"Number of notes: {len(annotation.notes)}")
106+
107+
108+
###############################################################################
109+
# Query Metadata
110+
# -----------------------------------------------------------------------------
111+
# Show how to query analyses based on metadata
112+
113+
# Get all analyses that have a specific metadata field
114+
metadata_results = studyset.get_analyses_by_metadata("contrast_type")
115+
print("\nAnalyses with contrast_type metadata:")
116+
print("-" * 50)
117+
pprint(metadata_results)
118+
119+
120+
###############################################################################
121+
# Convert to NiMARE Dataset
122+
# -----------------------------------------------------------------------------
123+
# Convert the NiMADS Studyset to a NiMARE Dataset for further analysis
124+
125+
nimare_dset = studyset.to_dataset()
126+
print("\nNiMARE Dataset Information:")
127+
print("-" * 50)
128+
print("Coordinates DataFrame Preview:")
129+
print(nimare_dset.coordinates.head())

0 commit comments

Comments
 (0)