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
Add data with multiple parameter groups.
  • Loading branch information
mattcieslak committed Oct 9, 2020
commit c7ed6004fa9a5c156afafc120fcf120d8b2199fe
56 changes: 54 additions & 2 deletions bond/bond.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Main module."""
from pathlib import Path
import bids
bids.config.set_option('extension_initial_dot', True)
from bids.util import parse_file_entities

NON_KEY_ENTITIES = set(["subject", "session", "extension"])

class BOnD(object):

Expand All @@ -11,12 +15,14 @@ def fieldmaps_ok(self):
pass

def rename_files(self, pattern, replacement):
"""
# @Params
# - path: a string contianing the path to the bids directory inside which we want to change files
# - pattern: the substring of the file we would like to replace
# - replacement: the substring that will replace "pattern"
# @Returns
# - None
"""
files_and_dirs = Path(self.path).rglob('*')
for path in files_and_dirs:
old_name = path.stem
Expand All @@ -25,9 +31,55 @@ def rename_files(self, pattern, replacement):
new_name = old_name.replace(pattern, replacement) + old_ext
path.rename(Path(directory, new_name))

def find_param_sets(self, pattern):
pass
def get_param_groups(self, key_group):
key_entities = _key_group_to_entities(key_group)
matching_files = self.layout.get(return_type="file", scope="self",
**key_entities)
return _get_param_groups(matching_files)

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),)
return sorted(key_groups)

def fill_metadata(self, pattern, metadata):
pass


def _key_group_to_entities(key_group):
return dict([group.split("-") for group in key_group.split("_")])


def _entities_to_key_group(entities):
group_keys = sorted(entities.keys() - NON_KEY_ENTITIES)
return "_".join(
["{}-{}".format(key, entities[key]) for key in group_keys])


def _file_to_key_group(filename):
entities = parse_file_entities(str(filename))
return _entities_to_key_group(entities)


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

Parameters:
-----------

files : list
List of file names

Returns:
--------

parameter_groups : list
A list of unique parameter groups

For each file in `files`, find critical parameters for metadata. Then find
unique sets of these critical parameters.
"""
pass
3 changes: 2 additions & 1 deletion bond/testdata/complete/README
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Heavily downsampled CS-DSI testing datasets
Heavily downsampled CS-DSI testing datasets.
This dataset is valid BIDS.
10 changes: 10 additions & 0 deletions bond/testdata/inconsistent/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Heavily downsampled CS-DSI testing datasets

This data has had some parameters changed so that there are different
parameter groups in the same key groups.

## Changes

- sub-01_ses-phdiff_acq-HASC55AP_dwi: EchoTime set to 0.04 from 0.089
- sub-02_ses-phdiff_task-rest_bold: Fieldmap has been removed
- sub-03_ses-phdiff_task-rest_bold: FlipAngle set to 70 from 90
7 changes: 7 additions & 0 deletions bond/testdata/inconsistent/dataset_description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"BIDSVersion": "1.0.0",
"License": "BSD 3-clause",
"Name": "Heavily downsampled CS-DSI simulated data",
"ReferencesAndLinks": [],
"Authors": ["PennLINC", "PennBBL"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Manufacturer": "Siemens",
"ManufacturersModelName": "Prisma_fit",
"AcquisitionNumber": 1,
"InstitutionName": "HUP",
"InstitutionAddress": "Spruce_Street_3400_Philadelphia_Pennsylvania_US_19104",
"DeviceSerialNumber": "167024",
"SoftwareVersions": "syngo_MR_E11",
"ProcedureStepDescription": "MR_HEAD_WO_IV_CONTRAST",
"ScanningSequence": "GR_IR",
"SequenceVariant": "SK_SP_MP",
"SeriesDescription": "ABCD_T1w_MPR_vNav",
"BodyPartExamined": "BRAIN",
"ProtocolName": "ABCD_T1w_MPR_vNav",
"SequenceName": "tfl3d1_16ns",
"ImageType": [
"ORIGINAL",
"PRIMARY",
"M",
"ND",
"NORM"
],
"AcquisitionTime": "16:15:31.770000",
"MagneticFieldStrength": 3,
"FlipAngle": 8,
"EchoTime": 0.0029,
"RepetitionTime": 2.5,
"InversionTime": 1.07,
"PhaseEncodingLines": 256,
"PhaseEncodingDirection": "i-",
"ConversionSoftware": "dcm2niix",
"ConversionSoftwareVersion": "v1.0.20170724 (OpenJPEG build) GCC6.1.0"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0 2000 3780 3800 4380 2195 2205 4200 3570 1005 2800 3790 3390 0 3605 3980 2575 3605 4195 3570 4175 3385 3395 4185 2395 4985 0 1800 1800 3780 1610 4000 4170 1190 2785 3215 200 1985 3980 0 3385 4385 4955 395 3975 3390 3965 3395 205 3385 4385 5015 990 1800 1010 1190 2605 2195 4380 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 0 0.947306 -0.689491 -0.687391 -0.640236 0.904801 0.301134 0.218033 0.236237 -0.00045876 -0.267232 -0.229644 0.727918 0 -0.235344 -0.895859 0.556585 -0.235344 -0.872345 0.236237 0.218536 -0.485657 -0.969313 0.873651 0.577663 0.999993 0 -0.665829 0.665829 -0.689491 0.704677 -0.00022427 -0.437403 0.409502 0.26769 -0.00031134 0.999772 -0.00016233 0.895859 0 0.971029 0.426584 0 -0.712479 -0.00011346 -0.727918 -0.448521 -0.484877 -0.00487633 -0.485657 -0.426584 -0.00019956 -0.00045946 0.665829 -0.445079 0.409502 -0.830354 -0.904801 0.640236 0
0 0 -0.320301 -0.233031 0.690471 -0.429664 -0.305819 -0.906545 0.874886 0.239537 0.898412 0.804939 0.691594 0.488404 0 -0.943991 -0.00303821 -0.00388069 0.943991 -0.439269 -0.239537 0.439998 0.488955 -0.245811 0.221429 -0.581525 -0.00280889 0 0.670455 -0.670455 0.233031 -0.709514 -0.896432 0.221712 -0.414997 -0.538836 -0.999995 -0.0151408 0.32154 -0.00303821 0 -0.00329842 0.642719 -0.00262411 -0.0090312 -0.450857 0.488404 -0.00293403 -0.730564 -0.999882 -0.488955 -0.642719 -0.999997 -0.454441 0.670455 -0.895473 0.414997 -0.557225 -0.305819 -0.429664 0
0 0 -0.00426696 -0.685783 -0.225265 -0.636779 -0.296327 -0.295796 -0.432477 -0.941708 -0.439154 -0.529773 -0.684807 -0.481245 0 -0.231289 -0.444328 -0.830781 -0.231289 -0.214611 -0.941708 -0.871001 -0.724611 -0.00307126 -0.433248 -0.57283 -0.00260781 0 -0.327355 -0.327355 -0.685783 -0.00439859 -0.443181 -0.871506 -0.812457 -0.798748 -0.00311231 -0.0150655 -0.946896 -0.444328 0 -0.238939 -0.636348 -0.999997 -0.701635 -0.892596 -0.481245 -0.893768 -0.480802 -0.014558 -0.724611 -0.636348 -0.00259323 -0.890777 -0.327355 -0.00576167 -0.812457 -0.00362001 -0.296327 -0.636779 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"ProcedureStepDescription": "MR_HEAD_WO_IV_CONTRAST",
"DeviceSerialNumber": "167024",
"EffectiveEchoSpacing": 0.000689998,
"TotalReadoutTime": 0.0717598,
"ManufacturersModelName": "Prisma_fit",
"ProtocolName": "ABCD_dMRI",
"BandwidthPerPixelPhaseEncode": 10.352,
"PhaseEncodingLines": 140,
"RepetitionTime": 4.2,
"EchoTrainLength": 105,
"MagneticFieldStrength": 3,
"AcquisitionNumber": 1,
"InstitutionName": "HUP",
"BodyPartExamined": "BRAIN",
"ConversionSoftware": "dcm2niix",
"ScanningSequence": "EP",
"Manufacturer": "Siemens",
"FlipAngle": 90,
"ConversionSoftwareVersion": "v1.0.20170724 (OpenJPEG build) GCC6.1.0",
"SeriesDescription": "ABCD_dMRI",
"InstitutionAddress": "Spruce_Street_3400_Philadelphia_Pennsylvania_US_19104",
"AcquisitionTime": "16:31:6.145000",
"SequenceName": "ep_b0",
"ImageType": [
"ORIGINAL",
"PRIMARY",
"DIFFUSION",
"NONE",
"ND",
"MOSAIC"
],
"EchoTime": 0.04,
"SequenceVariant": "SK_SP",
"SliceTiming": [
0.0,
0.11666666666666667,
0.23333333333333334,
0.35,
0.4666666666666667,
0.5833333333333334,
0.7,
0.8166666666666667,
0.9333333333333333,
1.05,
1.1666666666666667,
1.2833333333333334,
1.4,
1.5166666666666666,
1.6333333333333333,
1.75,
1.8666666666666667,
1.9833333333333334,
2.1,
2.216666666666667,
2.3333333333333335,
2.45,
2.566666666666667,
2.6833333333333336,
2.8,
2.9166666666666665,
3.033333333333333,
3.15,
3.2666666666666666,
3.3833333333333333,
3.5,
3.6166666666666667,
3.7333333333333334,
3.85,
3.966666666666667,
4.083333333333333
],
"PhaseEncodingDirection": "j",
"SoftwareVersions": "syngo_MR_E11"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"AcquisitionMatrixPE": 64,
"AcquisitionNumber": 1,
"BaseResolution": 64,
"BodyPartExamined": "BRAIN",
"ConsistencyInfo": "N4_VE11C_LATEST_20160120",
"ConversionSoftware": "dcm2niix",
"ConversionSoftwareVersion": "v1.0.20180622 GCC6.3.0",
"EchoTime": 0.004,
"FlipAngle": 60,
"ImageOrientationPatientDICOM": [
1,
0,
0,
0,
1,
0
],
"ImageType": [
"ORIGINAL",
"PRIMARY",
"M",
"ND"
],
"InPlanePhaseEncodingDirectionDICOM": "COL",
"InstitutionName": "HUP6",
"MRAcquisitionType": "2D",
"MagneticFieldStrength": 3,
"Manufacturer": "Siemens",
"ManufacturersModelName": "Prisma_fit",
"Modality": "MR",
"PartialFourier": 0.75,
"PatientPosition": "HFS",
"PercentPhaseFOV": 100,
"PhaseEncodingDirection": "j-",
"PhaseEncodingSteps": 48,
"PhaseResolution": 1,
"PixelBandwidth": 500,
"ProtocolName": "B0map_v4",
"PulseSequenceDetails": "%SiemensSeq%_gre_field_mapping",
"ReceiveCoilActiveElements": "HEA;HEP",
"ReceiveCoilName": "Head_32",
"ReconMatrixPE": 64,
"RepetitionTime": 1.5,
"SAR": 0.0935879,
"ScanOptions": "PFP_FS",
"ScanningSequence": "GR",
"SequenceName": "_fm2d2",
"SequenceVariant": "SP",
"SeriesDescription": "B0map_v4",
"SeriesNumber": 7,
"ShimSetting": [
1747,
-3883,
-285,
583,
125,
-23,
-45,
-40
],
"SliceThickness": 4,
"SoftwareVersions": "syngo_MR_E11",
"SpacingBetweenSlices": 4,
"StationName": "HUP_FNDBA_MR2",
"TxRefAmp": 220.327
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"AcquisitionMatrixPE": 64,
"AcquisitionNumber": 1,
"BaseResolution": 64,
"BodyPartExamined": "BRAIN",
"ConsistencyInfo": "N4_VE11C_LATEST_20160120",
"ConversionSoftware": "dcm2niix",
"ConversionSoftwareVersion": "v1.0.20180622 GCC6.3.0",
"EchoNumber": 2,
"EchoTime": 0.00646,
"FlipAngle": 60,
"ImageOrientationPatientDICOM": [
1,
0,
0,
0,
1,
0
],
"ImageType": [
"ORIGINAL",
"PRIMARY",
"M",
"ND"
],
"InPlanePhaseEncodingDirectionDICOM": "COL",
"InstitutionName": "HUP6",
"MRAcquisitionType": "2D",
"MagneticFieldStrength": 3,
"Manufacturer": "Siemens",
"ManufacturersModelName": "Prisma_fit",
"Modality": "MR",
"PartialFourier": 0.75,
"PatientPosition": "HFS",
"PercentPhaseFOV": 100,
"PhaseEncodingDirection": "j-",
"PhaseEncodingSteps": 48,
"PhaseResolution": 1,
"PixelBandwidth": 500,
"ProtocolName": "B0map_v4",
"PulseSequenceDetails": "%SiemensSeq%_gre_field_mapping",
"ReceiveCoilActiveElements": "HEA;HEP",
"ReceiveCoilName": "Head_32",
"ReconMatrixPE": 64,
"RepetitionTime": 1.5,
"SAR": 0.0935879,
"ScanOptions": "PFP_FS",
"ScanningSequence": "GR",
"SequenceName": "_fm2d2",
"SequenceVariant": "SP",
"SeriesDescription": "B0map_v4",
"SeriesNumber": 7,
"ShimSetting": [
1747,
-3883,
-285,
583,
125,
-23,
-45,
-40
],
"SliceThickness": 4,
"SoftwareVersions": "syngo_MR_E11",
"SpacingBetweenSlices": 4,
"StationName": "HUP_FNDBA_MR2",
"TxRefAmp": 220.327
}
Binary file not shown.
Loading