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] Create BOnD class and implement major use cases #13

Merged
merged 49 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
93d0694
add initial testing
mattcieslak Oct 7, 2020
8576f73
first proof
TinasheMTapera Oct 7, 2020
0dec958
Merge branch 'use_cases' of https://github.com/PennLINC/BOnD into use…
TinasheMTapera Oct 7, 2020
e721e3b
add tests
mattcieslak Oct 7, 2020
0ede65d
Merge branch 'use_cases' of github.com:PennLINC/BOnD into use_cases
mattcieslak Oct 7, 2020
14e80f8
add nipype as dependency
mattcieslak Oct 7, 2020
1886891
Add testing data
mattcieslak Oct 8, 2020
ff54f28
rename_files function
scovitz1 Oct 8, 2020
04e8386
update tests
mattcieslak Oct 8, 2020
3477bbc
rename_files now performs find/replace onall path names in a BIDS dir…
scovitz1 Oct 8, 2020
3dad960
function has been tested on testdata
scovitz1 Oct 8, 2020
841ac75
using member var
scovitz1 Oct 8, 2020
2c4f357
add import to init
mattcieslak Oct 8, 2020
7283fdf
Merge branch 'use_cases' of github.com:PennLINC/BOnD into use_cases
mattcieslak Oct 8, 2020
c361129
test commit
mattcieslak Oct 8, 2020
c5e6fd3
should be here now
scovitz1 Oct 8, 2020
95e2d26
passes a test!!!
mattcieslak Oct 8, 2020
5f41043
closes #8
scovitz1 Oct 8, 2020
92ae019
remove hidden files
mattcieslak Oct 8, 2020
88ae1e3
Add files via upload
krmurtha Oct 8, 2020
ddd6c0a
basma's notebook to work with json metadata
jaberbasma Oct 8, 2020
eddd31d
fieldmaps PofC
TinasheMTapera Oct 8, 2020
2f2a684
Merge pull request #9 from PennLINC/usecases
TinasheMTapera Oct 8, 2020
23ac422
re-adding testdata
TinasheMTapera Oct 9, 2020
c7ed600
Add data with multiple parameter groups.
mattcieslak Oct 9, 2020
a3ca59a
Update docs
mattcieslak Oct 9, 2020
15a2d6f
use pybids filters
mattcieslak Oct 9, 2020
a98096b
Add files via upload
jaberbasma Oct 9, 2020
c561582
added pandas df
Oct 9, 2020
d184e70
`change_metadata` functional
TinasheMTapera Oct 9, 2020
a569d68
Merge branch 'use_cases' of https://github.com/PennLINC/BOnD into use…
TinasheMTapera Oct 9, 2020
7b204b3
removing testdata from `notebooks/testdata`
TinasheMTapera Oct 9, 2020
24c5d74
Added imaging params
mattcieslak Oct 9, 2020
3d61e6a
Add SliceTiming
mattcieslak Oct 9, 2020
a329af6
Add files via upload
jaberbasma Oct 9, 2020
906a6a5
Add files via upload
jaberbasma Oct 9, 2020
b6f27a9
Merge branch 'use_cases' of github.com:PennLINC/BOnD into use_cases
mattcieslak Oct 10, 2020
c16a500
key groups and param groups work!
mattcieslak Oct 10, 2020
4ab6edd
rounding slice timing
scovitz1 Oct 12, 2020
1503ddd
testing Key and Param Groups
scovitz1 Oct 12, 2020
c8e1c95
new notebooks
scovitz1 Oct 15, 2020
869e307
Update bond.py
scovitz Oct 15, 2020
279d5df
Update bond.py
scovitz Oct 15, 2020
7f6072c
Update bond.py
scovitz Oct 15, 2020
d4347aa
Many additions to bond.py, pull requested!
scovitz Oct 15, 2020
044b317
Add files via upload
scovitz Oct 15, 2020
5636b6c
Merge branch 'use_cases' into sydney-testing
TinasheMTapera Oct 15, 2020
a064e7d
Merge pull request #11 from PennLINC/sydney-testing
TinasheMTapera Oct 15, 2020
ff9e5b0
Added fieldmaps to param groups
mattcieslak Oct 16, 2020
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
Prev Previous commit
Next Next commit
key groups and param groups work!
  • Loading branch information
mattcieslak committed Oct 10, 2020
commit c16a500f280aa1999e811073a21ce9da3bfbd29d
42 changes: 31 additions & 11 deletions bond/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import json
from pathlib import Path
from bids.layout import parse_file_entities
from bids.layout import BIDSFile
import pandas as pd

bids.config.set_option('extension_initial_dot', True)

NON_KEY_ENTITIES = set(["subject", "session", "extension"])
# Multi-dimensional keys SliceTiming
IMAGING_PARAMS = set(["ParallelReductionFactorInPlane", "ParallelAcquisitionTechnique",
IMAGING_PARAMS = set([
"ParallelReductionFactorInPlane", "ParallelAcquisitionTechnique",
"ParallelAcquisitionTechnique", "PartialFourier", "PhaseEncodingDirection",
"EffectiveEchoSpacing", "TotalReadoutTime", "EchoTime", "SliceEncodingDirection",
"DwellTime", "FlipAngle", "MultibandAccelerationFactor", "RepetitionTime", "SliceTiming",
"VolumeTiming", "NumberOfVolumesDiscardedByScanner", "NumberOfVolumesDiscardedByUser"])
"EffectiveEchoSpacing", "TotalReadoutTime", "EchoTime",
"SliceEncodingDirection", "DwellTime", "FlipAngle",
"MultibandAccelerationFactor", "RepetitionTime", "SliceTiming",
"VolumeTiming", "NumberOfVolumesDiscardedByScanner",
"NumberOfVolumesDiscardedByUser"])


class BOnD(object):

Expand Down Expand Up @@ -49,16 +53,17 @@ def rename_files(self, filters, pattern, replacement):

def get_param_groups(self, key_group):
key_entities = _key_group_to_entities(key_group)
key_entities["extension"] = ".nii[.gz]*"
matching_files = self.layout.get(return_type="file", scope="self",
**key_entities)
return _get_param_groups(matching_files)
regex_search=True, **key_entities)
return _get_param_groups(matching_files, self.layout)

def get_key_groups(self):
key_groups = set()
for path in Path(self.path).rglob("*.*"):
if path.suffix == ".json":
continue
key_groups.update(_file_to_key_group(path),)
key_groups.update((_file_to_key_group(path),))
return sorted(key_groups)

def change_metadata(self, filters, pattern, metadata):
Expand All @@ -81,7 +86,7 @@ def change_metadata(self, filters, pattern, metadata):

json_file = [x for x in bidsjson_file if 'json' in x.filename]

if len(json_file) is not 1:
if not len(json_file) == 1:

print("FOUND IRREGULAR ASSOCIATIONS")

Expand Down Expand Up @@ -135,7 +140,7 @@ def _file_to_key_group(filename):
return _entities_to_key_group(entities)


def _get_param_groups(files):
def _get_param_groups(files, layout):
"""Finds a list of *parameter groups* from a list of files.

Parameters:
Expand All @@ -153,4 +158,19 @@ def _get_param_groups(files):
For each file in `files`, find critical parameters for metadata. Then find
unique sets of these critical parameters.
"""
pass
dfs = []
for path in files:
metadata = layout.get_metadata(path)
wanted_keys = metadata.keys() & IMAGING_PARAMS
example_data = {key: metadata[key] for key in wanted_keys}

# Expand slice timing to multiple columns
SliceTime = example_data.get('SliceTiming')
if SliceTime:
example_data.update(
{"SliceTime%03d" % SliceNum: time for
SliceNum, time in enumerate(SliceTime)})
del example_data['SliceTiming']
dfs.append(example_data)

return pd.DataFrame(dfs).drop_duplicates()
Loading