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

[ENH] rudimentary support for nimads #763

Merged
merged 38 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
edc3521
Create nimads.py
tsalo Dec 21, 2021
562731c
Add in method skeleton and start on docstrings.
tsalo Dec 21, 2021
83cbdc8
Update nimads.py
tsalo Dec 21, 2021
485faac
Improve the docstrings a bit.
tsalo Feb 3, 2022
b42c89d
Describe how Condition Annotations should be stored.
tsalo Feb 9, 2022
1b0072f
Merge branch 'main' of github.com:neurostuff/NiMARE into nimads
jdkent Mar 30, 2022
0d1fbb3
add some basic structure for loading studysets
jdkent Mar 31, 2022
5262c61
wip: convert nimads to nimare object
jdkent Apr 21, 2022
6aa9788
wip: adding workflow run command
jdkent Apr 25, 2022
cbe57cd
run black/isort
jdkent Apr 26, 2022
9f13241
Merge branch 'main' of github.com:neurostuff/NiMARE into nimads
jdkent Jun 8, 2022
910037e
fix workflows
jdkent Jun 9, 2022
f8a1377
Merge branch 'main' of github.com:neurostuff/NiMARE into nimads
jdkent Sep 23, 2022
3684e89
wip: change name of function
jdkent Oct 7, 2022
69cb840
Merge branch 'main' of github.com:neurostuff/NiMARE into nimads
jdkent Dec 20, 2022
56d935b
add workflow
jdkent Jan 4, 2023
9dc93b3
change io names
jdkent Jan 5, 2023
612b595
fix black style
jdkent Jan 5, 2023
fab9c4f
handle corrector_init better
jdkent Jan 5, 2023
7f01880
Merge branch 'main' of github.com:neurostuff/NiMARE into nimads
jdkent Jan 19, 2023
7d8394e
remove workflow from this pull request
jdkent Jan 26, 2023
fb5f05c
add more nimads annotation structure
jdkent Feb 16, 2023
2051086
begin to test slicing
jdkent Feb 16, 2023
3ef5eb1
formatting
jdkent Feb 16, 2023
3993cb6
wip: add to_dict
jdkent Feb 24, 2023
4f08818
fix slicing of the studyset
jdkent Mar 10, 2023
afae242
refactor io code to prevent circular import
jdkent Mar 13, 2023
4092e52
support reading in more types
jdkent Mar 13, 2023
e87e46c
add more to tests
jdkent Mar 13, 2023
c691c37
wip: add example
jdkent Mar 13, 2023
586f603
fix indentation and style
jdkent Mar 13, 2023
6bac7db
refactor to prevent circular import
jdkent Mar 14, 2023
39f91ec
did not fix circular import
jdkent Mar 14, 2023
833bf2f
add little more detail to example
jdkent Mar 14, 2023
3145965
allow studyset to be passed
jdkent Mar 14, 2023
e27edc7
complete merge
jdkent Mar 14, 2023
3b55549
remove accidental fixture
jdkent Mar 14, 2023
7d2a540
download files from url instead of reading local
jdkent Mar 14, 2023
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
60 changes: 60 additions & 0 deletions examples/01_datasets/05_plot_nimads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""

.. _nimads_object:

========================
Using NIMADS with NiMARE
========================

How to use the NeuroImaging Meta-Analysis Data Structure
`(NIMADS) <https://neurostuff.github.io/NIMADS/>`_ with NiMARE.
"""
from requests import request

from nimare.io import convert_nimads_to_dataset
from nimare.nimads import Studyset

###############################################################################
# Download Data from NeuroStore
# -----------------------------------------------------------------------------


def download_file(url):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: I'm not sure this function is that useful since you only use it twice (below).

Maybe you could make this more useful and use it throughout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, my threshold for wanting to write a function was pretty low, it's possible other examples could be downloaded down the line using this function.

"""Download a file from NeuroStore."""
response = request("GET", url)
return response.json()


nimads_studyset = download_file(
"https://neurostore.org/api/studysets/Cv2LLUqG76W9?nested=true"
)
nimads_annotation = download_file(
"https://neurostore.org/api/annotations/76PyNqoTNEsE"
)


###############################################################################
# Load Data
# -----------------------------------------------------------------------------
# Load the json files into a NiMADS Studyset object.

studyset = Studyset(nimads_studyset, nimads_annotation)


###############################################################################
# Convert to NiMARE Dataset
# -----------------------------------------------------------------------------
# Convert the NiMADS Studyset object to a NiMARE Dataset object.
# Then you can run NiMARE analyses on the Dataset object.

nimare_dset = studyset.to_dataset()
nimare_dset.coordinates.head()

###############################################################################
# Directly to NiMARE Dataset
# -----------------------------------------------------------------------------
# Alternatively, you can convert the NiMADS json files directly to a NiMARE Dataset object
# if you wish to skip using the nimads studyset object directly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does it make sense to use the Studyset object directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this the first step towards replacing the nimare dataset object with the nimads studyset object, right now there is not much benefit besides the representation/terms being more consistent (e.g., analysis is called contrast in a nimare dset). but eventually, a user should be able to use a studyset object with all the estimators and have it work.


nimare_dset_2 = convert_nimads_to_dataset(nimads_studyset, nimads_annotation)
nimare_dset_2.coordinates.head()
42 changes: 42 additions & 0 deletions nimare/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from nimare.dataset import Dataset
from nimare.extract.utils import _get_dataset_dir
from nimare.utils import _create_name, load_nimads

LGR = logging.getLogger(__name__)

Expand All @@ -26,6 +27,47 @@
}


def convert_nimads_to_dataset(studyset, annotation=None):
"""Convert nimads studyset to a dataset."""

def _analysis_to_dict(study, analysis):
result = {
"metadata": {
"authors": study.name,
"journal": study.publication,
"title": study.name,
"sample_sizes": [study.metadata.get("sample_size")],
},
"coords": {
"space": analysis.points[0].space,
"x": [p.x for p in analysis.points],
"y": [p.y for p in analysis.points],
"z": [p.z for p in analysis.points],
},
}

if analysis.annotations:
result["labels"] = {}
for annotation in analysis.annotations.values():
result["labels"].update(annotation)

return result

def _study_to_dict(study):
return {
"metadata": {
"authors": study.authors,
"journal": study.publication,
"title": study.name,
},
"contrasts": {_create_name(a): _analysis_to_dict(study, a) for a in study.analyses},
}

# load nimads studyset
studyset = load_nimads(studyset, annotation)
return Dataset({_create_name(s): _study_to_dict(s) for s in list(studyset.studies)})


def convert_neurosynth_to_dict(
coordinates_file,
metadata_file,
Expand Down
Loading