Skip to content

Commit

Permalink
Merge pull request #211 from jhlegarreta/AddPyBIDSLeadingDotWarning
Browse files Browse the repository at this point in the history
ENH: Add PyBIDS leading dot warning
  • Loading branch information
jhlegarreta authored Jun 2, 2022
2 parents deb63f8 + b6249eb commit 567bc8f
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 82 deletions.
12 changes: 4 additions & 8 deletions _episodes/constrained_spherical_deconvolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,27 @@ import os
import nibabel as nib
import numpy as np
import bids
from bids.layout import BIDSLayout
from dipy.core.gradients import gradient_table
from dipy.data import default_sphere
from dipy.io.gradients import read_bvals_bvecs
from dipy.io.image import load_nifti
bids.config.set_option('extension_initial_dot', True)
dwi_layout = BIDSLayout('../../data/ds000221/derivatives/uncorrected_topup_eddy/', validate=False)
t1_layout = BIDSLayout('../../data/ds000221/derivatives/uncorrected_topup_eddy_regT1/', validate=False)
gradient_layout = BIDSLayout('../../data/ds000221/sub-010006/ses-01/dwi/', validate=False)
subj = '010006'
# Get the diffusion files
dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='nii.gz', return_type='file')[0]
bvec_fname = dwi_layout.get(subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]
bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='bval', return_type='file')[0]
dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='.nii.gz', return_type='file')[0]
bvec_fname = dwi_layout.get(subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]
bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]
# Get the anatomical file
t1w_fname = t1_layout.get(subject=subj, extension='nii.gz', return_type='file')[0]
t1w_fname = t1_layout.get(subject=subj, extension='.nii.gz', return_type='file')[0]
data, affine = load_nifti(dwi_fname)
Expand Down
16 changes: 6 additions & 10 deletions _episodes/deterministic_tractography.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,19 @@ import os
import nibabel as nib
import numpy as np
import bids
from bids.layout import BIDSLayout
from dipy.io.gradients import read_bvals_bvecs
from dipy.core.gradients import gradient_table
bids.config.set_option('extension_initial_dot', True)
dwi_layout = BIDSLayout("../../data/ds000221/derivatives/uncorrected_topup_eddy", validate=False)
gradient_layout = BIDSLayout("../../data/ds000221/", validate=False)
subj = '010006'
dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='nii.gz', return_type='file')[0]
bvec_fname = dwi_layout.get(subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]
bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='bval', return_type='file')[0]
dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='.nii.gz', return_type='file')[0]
bvec_fname = dwi_layout.get(subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]
bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]
dwi_img = nib.load(dwi_fname)
affine = dwi_img.affine
Expand Down Expand Up @@ -274,9 +270,9 @@ plt.show()
> >
> > # Get subject data
> > subj = '010006'
> > dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='nii.gz', return_type='file')[0]
> > bvec_fname = dwi_layout.get(subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]
> > bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='bval', return_type='file')[0]
> > dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='.nii.gz', return_type='file')[0]
> > bvec_fname = dwi_layout.get(subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]
> > bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]
> >
> > dwi_img = nib.load(dwi_fname)
> > affine = dwi_img.affine
Expand Down
7 changes: 2 additions & 5 deletions _episodes/diffusion_tensor_imaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,16 @@ and load them! We will also load in the anatomical image to use as a reference
later on.

~~~
import bids
from bids.layout import BIDSLayout
from dipy.io.gradients import read_bvals_bvecs
from dipy.core.gradients import gradient_table
from nilearn import image as img
bids.config.set_option('extension_initial_dot', True)
deriv_layout = BIDSLayout("../data/ds000221/derivatives", validate=False)
subj="010006"
# Grab the transformed t1 file for reference
t1 = deriv_layout.get(subject=subj, space="dwi", extension='nii.gz', return_type='file')[0]
t1 = deriv_layout.get(subject=subj, space="dwi", extension='.nii.gz', return_type='file')[0]
# Recall the preprocessed data is no longer in BIDS - we will directly grab these files
dwi = f"../data/ds000221/derivatives/uncorrected_topup_eddy/sub-{subj}/ses-01/dwi/dwi.nii.gz"
Expand Down Expand Up @@ -322,7 +319,7 @@ data!
> > deriv_layout = BIDSLayout("../data/ds000221/derivatives", validate=False)
> > subj="010006"
> >
> > t1 = deriv_layout.get(subject=subj, space="dwi", extension='nii.gz', return_type='file')[0]
> > t1 = deriv_layout.get(subject=subj, space="dwi", extension='.nii.gz', return_type='file')[0]
> > dwi = f"../data/ds000221/derivatives/uncorrected_topup_eddy/sub-{subj}/ses-01/dwi/dwi.nii.gz"
> > bval = f"../data/ds000221/sub-{subj}/ses-01/dwi/sub-{subj}_ses-01_dwi.bval"
> > bvec = f"../data/ds000221/derivatives/uncorrected_topup_eddy/sub-{subj}/ses-01/dwi/dwi.eddy_rotated_bvecs"
Expand Down
7 changes: 2 additions & 5 deletions _episodes/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ Let's first pull the metadata from its associated JSON file using the
<code>get_metadata()</code> function for the first run.

~~~
import bids
from bids.layout import BIDSLayout
?BIDSLayout
bids.config.set_option('extension_initial_dot', True)
layout = BIDSLayout("../data/ds000221", validate=False)
~~~
{: .language-python}
Expand All @@ -148,7 +145,7 @@ Now that we have a layout object, we can work with a BIDS dataset! Let's
extract the metadata from the dataset.

~~~
dwi = layout.get(subject='010006', suffix='dwi', extension='nii.gz', return_type='file')[0]
dwi = layout.get(subject='010006', suffix='dwi', extension='.nii.gz', return_type='file')[0]
layout.get_metadata(dwi)
~~~
{: .language-python}
Expand Down Expand Up @@ -377,7 +374,7 @@ axonal trajectories via tractography.
> > ## Solution
> >
> > ~~~
> > dwi_data = layout.get(suffix='dwi', extension='nii.gz', return_type='file')
> > dwi_data = layout.get(suffix='dwi', extension='.nii.gz', return_type='file')
> > ~~~
> > {: .language-python}
> {: .solution}
Expand Down
7 changes: 2 additions & 5 deletions _episodes/preprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,17 @@ image to use later on, as well as the second inversion from the anatomical
acquisition for brainmasking purposes.

~~~
import bids
from bids.layout import BIDSLayout
bids.config.set_option('extension_initial_dot', True)
layout = BIDSLayout("../../data/ds000221", validate=False)
subj='010006'
# Diffusion data
dwi = layout.get(subject=subj, suffix='dwi', extension='nii.gz', return_type='file')[0]
dwi = layout.get(subject=subj, suffix='dwi', extension='.nii.gz', return_type='file')[0]
# Anatomical data
t1w = layout.get(subject=subj, suffix='T1w', extension='nii.gz', return_type='file')[0]
t1w = layout.get(subject=subj, suffix='T1w', extension='.nii.gz', return_type='file')[0]
~~~
{: .language-python}

Expand Down
11 changes: 3 additions & 8 deletions _episodes/probabilistic_tractography.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,19 @@ import os
import nibabel as nib
import numpy as np
import bids
from bids.layout import BIDSLayout
from dipy.core.gradients import gradient_table
from dipy.data import get_fnames
from dipy.io.gradients import read_bvals_bvecs
bids.config.set_option('extension_initial_dot', True)
dwi_layout = BIDSLayout('../../data/ds000221/derivatives/uncorrected_topup_eddy/', validate=False)
gradient_layout = BIDSLayout('../../data/ds000221/', validate=False)
subj = '010006'
dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='nii.gz', return_type='file')[0]
bvec_fname = dwi_layout.get(subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]
bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='bval', return_type='file')[0]
dwi_fname = dwi_layout.get(subject=subj, suffix='dwi', extension='.nii.gz', return_type='file')[0]
bvec_fname = dwi_layout.get(subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]
bval_fname = gradient_layout.get(subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]
dwi_img = nib.load(dwi)
affine = dwi_img.affine
Expand Down
12 changes: 4 additions & 8 deletions code/constrained_spherical_deconvolution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@
"import nibabel as nib\n",
"import numpy as np\n",
"\n",
"import bids\n",
"from bids.layout import BIDSLayout\n",
"\n",
"from dipy.core.gradients import gradient_table\n",
"from dipy.data import default_sphere\n",
"from dipy.io.gradients import read_bvals_bvecs\n",
"from dipy.io.image import load_nifti\n",
"\n",
"\n",
"bids.config.set_option('extension_initial_dot', True)\n",
"\n",
"dwi_layout = BIDSLayout(\n",
" '../data/ds000221/derivatives/uncorrected_topup_eddy/', validate=False)\n",
"t1_layout = BIDSLayout(\n",
Expand All @@ -61,16 +57,16 @@
"\n",
"# Get the diffusion files\n",
"dwi_fname = dwi_layout.get(subject=subj, suffix='dwi',\n",
" extension='nii.gz', return_type='file')[0]\n",
" extension='.nii.gz', return_type='file')[0]\n",
"bvec_fname = dwi_layout.get(\n",
" subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]\n",
" subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]\n",
"bval_fname = gradient_layout.get(\n",
" subject=subj, suffix='dwi', extension='bval', return_type='file')[0]\n",
" subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]\n",
"\n",
"\n",
"# Get the anatomical file\n",
"t1w_fname = t1_layout.get(\n",
" subject=subj, extension='nii.gz', return_type='file')[0]\n",
" subject=subj, extension='.nii.gz', return_type='file')[0]\n",
"\n",
"data, affine = load_nifti(dwi_fname)\n",
"\n",
Expand Down
16 changes: 6 additions & 10 deletions code/deterministic_tractography.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,23 @@
"import nibabel as nib\n",
"import numpy as np\n",
"\n",
"import bids\n",
"from bids.layout import BIDSLayout\n",
"\n",
"from dipy.io.gradients import read_bvals_bvecs\n",
"from dipy.core.gradients import gradient_table\n",
"\n",
"\n",
"bids.config.set_option('extension_initial_dot', True)\n",
"\n",
"dwi_layout = BIDSLayout(\n",
" \"../data/ds000221/derivatives/uncorrected_topup_eddy\", validate=False)\n",
"gradient_layout = BIDSLayout(\"../data/ds000221/\", validate=False)\n",
"\n",
"subj = '010006'\n",
"\n",
"dwi_fname = dwi_layout.get(subject=subj, suffix='dwi',\n",
" extension='nii.gz', return_type='file')[0]\n",
" extension='.nii.gz', return_type='file')[0]\n",
"bvec_fname = dwi_layout.get(\n",
" subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]\n",
" subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]\n",
"bval_fname = gradient_layout.get(\n",
" subject=subj, suffix='dwi', extension='bval', return_type='file')[0]\n",
" subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]\n",
"\n",
"dwi_img = nib.load(dwi_fname)\n",
"affine = dwi_img.affine\n",
Expand Down Expand Up @@ -333,11 +329,11 @@
"# Get subject data\n",
"subj = '010006'\n",
"dwi_fname = dwi_layout.get(subject=subj, suffix='dwi',\n",
" extension='nii.gz', return_type='file')[0]\n",
" extension='.nii.gz', return_type='file')[0]\n",
"bvec_fname = dwi_layout.get(\n",
" subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]\n",
" subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]\n",
"bval_fname = gradient_layout.get(\n",
" subject=subj, suffix='dwi', extension='bval', return_type='file')[0]\n",
" subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]\n",
"\n",
"dwi_img = nib.load(dwi_fname)\n",
"affine = dwi_img.affine\n",
Expand Down
7 changes: 2 additions & 5 deletions code/diffusion_tensor_imaging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,17 @@
"cell_type": "code",
"execution_count": null,
"source": [
"import bids\n",
"from bids.layout import BIDSLayout\n",
"from dipy.io.gradients import read_bvals_bvecs\n",
"from dipy.core.gradients import gradient_table\n",
"from nilearn import image as img\n",
"\n",
"bids.config.set_option('extension_initial_dot', True)\n",
"\n",
"deriv_layout = BIDSLayout(\"../data/ds000221/derivatives\", validate=False)\n",
"subj = \"010006\"\n",
"\n",
"# Grab the transformed t1 file for reference\n",
"t1 = deriv_layout.get(subject=subj, space=\"dwi\",\n",
" extension='nii.gz', return_type='file')[0]\n",
" extension='.nii.gz', return_type='file')[0]\n",
"\n",
"# Recall the preprocessed data is no longer in BIDS - we will directly grab these files\n",
"dwi = f\"../data/ds000221/derivatives/uncorrected_topup_eddy/sub-{subj}/ses-01/dwi/dwi.nii.gz\"\n",
Expand Down Expand Up @@ -291,7 +288,7 @@
"subj = \"010006\"\n",
"\n",
"t1 = deriv_layout.get(subject=subj, space=\"dwi\",\n",
" extension='nii.gz', return_type='file')[0]\n",
" extension='.nii.gz', return_type='file')[0]\n",
"dwi = f\"../data/ds000221/derivatives/uncorrected_topup_eddy/sub-{subj}/ses-01/dwi/dwi.nii.gz\"\n",
"bval = f\"../data/ds000221/sub-{subj}/ses-01/dwi/sub-{subj}_ses-01_dwi.bval\"\n",
"bvec = f\"../data/ds000221/derivatives/uncorrected_topup_eddy/sub-{subj}/ses-01/dwi/dwi.eddy_rotated_bvecs\"\n",
Expand Down
7 changes: 2 additions & 5 deletions code/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,10 @@
"cell_type": "code",
"execution_count": null,
"source": [
"import bids\n",
"from bids.layout import BIDSLayout\n",
"\n",
"?BIDSLayout\n",
"\n",
"bids.config.set_option('extension_initial_dot', True)\n",
"\n",
"layout = BIDSLayout(\"../data/ds000221\", validate=False)"
],
"outputs": [],
Expand All @@ -140,7 +137,7 @@
"cell_type": "code",
"execution_count": null,
"source": [
"dwi = layout.get(subject='010006', suffix='dwi', extension='nii.gz', return_type='file')[0]\n",
"dwi = layout.get(subject='010006', suffix='dwi', extension='.nii.gz', return_type='file')[0]\n",
"layout.get_metadata(dwi)"
],
"outputs": [],
Expand Down Expand Up @@ -336,7 +333,7 @@
"cell_type": "code",
"execution_count": null,
"source": [
"dwi_data = layout.get(suffix='dwi', extension='nii.gz', return_type='file')"
"dwi_data = layout.get(suffix='dwi', extension='.nii.gz', return_type='file')"
],
"outputs": [],
"metadata": {
Expand Down
7 changes: 2 additions & 5 deletions code/preprocessing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,17 @@
"cell_type": "code",
"execution_count": null,
"source": [
"import bids\n",
"from bids.layout import BIDSLayout\n",
"\n",
"bids.config.set_option('extension_initial_dot', True)\n",
"\n",
"layout = BIDSLayout(\"../data/ds000221\", validate=False)\n",
"\n",
"subj='010006'\n",
"\n",
"# Diffusion data\n",
"dwi = layout.get(subject=subj, suffix='dwi', extension='nii.gz', return_type='file')[0]\n",
"dwi = layout.get(subject=subj, suffix='dwi', extension='.nii.gz', return_type='file')[0]\n",
"\n",
"# Anatomical data\n",
"t1w = layout.get(subject=subj, suffix='T1w', extension='nii.gz', return_type='file')[0]"
"t1w = layout.get(subject=subj, suffix='T1w', extension='.nii.gz', return_type='file')[0]"
],
"outputs": [],
"metadata": {}
Expand Down
10 changes: 3 additions & 7 deletions code/probabilistic_tractography.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@
"import nibabel as nib\n",
"import numpy as np\n",
"\n",
"import bids\n",
"from bids.layout import BIDSLayout\n",
"\n",
"from dipy.core.gradients import gradient_table\n",
"from dipy.io.gradients import read_bvals_bvecs\n",
"\n",
"\n",
"bids.config.set_option('extension_initial_dot', True)\n",
"\n",
"# Get the diffusion files\n",
"dwi_layout = BIDSLayout(\n",
" '../data/ds000221/derivatives/uncorrected_topup_eddy/', validate=False)\n",
Expand All @@ -63,11 +59,11 @@
"subj = '010006'\n",
"\n",
"dwi_fname = dwi_layout.get(subject=subj, suffix='dwi',\n",
" extension='nii.gz', return_type='file')[0]\n",
" extension='.nii.gz', return_type='file')[0]\n",
"bval_fname = gradient_layout.get(\n",
" subject=subj, suffix='dwi', extension='bval', return_type='file')[0]\n",
" subject=subj, suffix='dwi', extension='.bval', return_type='file')[0]\n",
"bvec_fname = dwi_layout.get(\n",
" subject=subj, extension='eddy_rotated_bvecs', return_type='file')[0]\n",
" subject=subj, extension='.eddy_rotated_bvecs', return_type='file')[0]\n",
"\n",
"dwi_img = nib.load(dwi_fname)\n",
"affine = dwi_img.affine\n",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ fury==0.6.1
matplotlib
nilearn==0.7.0
osfclient==0.0.5
pybids==0.12.4
pybids==0.14.0

0 comments on commit 567bc8f

Please sign in to comment.