Skip to content

Commit 270a84c

Browse files
authored
Merge pull request #328 from jhlegarreta/sty/gradients-misc-changes
STY: Miscellaneous changes to gradients indexing and variable naming
2 parents c729280 + 2cf9e2c commit 270a84c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/notebooks/data_structures.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
"data, _, grad = dwi[b2000_gradientmask]\n",
220220
"\n",
221221
"# Check correct filtering\n",
222-
"data.shape[-1] == b2000_gradientmask.sum(), set(grad[-1, ...]) == {2000.0}"
222+
"data.shape[-1] == b2000_gradientmask.sum(), set(grad[-1, :]) == {2000.0}"
223223
]
224224
},
225225
{
@@ -240,7 +240,7 @@
240240
],
241241
"source": [
242242
"# Plot volume 10 of b=2000 shell\n",
243-
"plot_dwi(data[..., 10], dwi.affine, gradient=grad[..., 10]);"
243+
"plot_dwi(data[..., 10], dwi.affine, gradient=grad[:, 10]);"
244244
]
245245
}
246246
],

src/nifreeze/data/dmri.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ def from_filename(cls, filename: Path | str) -> Self:
157157

158158
@property
159159
def bvals(self):
160-
return self.gradients[..., -1]
160+
return self.gradients[:, -1]
161161

162162
@property
163163
def bvecs(self):
164-
return self.gradients[..., :-1]
164+
return self.gradients[:, :-1]
165165

166166
def get_shells(
167167
self,

src/nifreeze/data/filtering.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,21 +254,21 @@ def dwi_select_shells(
254254
Shell mask.
255255
"""
256256

257-
bvalues = gradients[:, -1]
258-
bcenter = bvalues[index]
257+
bvals = gradients[:, -1]
258+
bcenter = bvals[index]
259259

260-
shellmask = np.ones(len(bvalues), dtype=bool)
260+
shellmask = np.ones(len(bvals), dtype=bool)
261261
shellmask[index] = False # Drop the held-out index
262262

263263
if atol_low is None and atol_high is None:
264264
return shellmask
265265

266266
atol_low = 0 if atol_low is None else atol_low
267-
atol_high = gradients[:, -1].max() if atol_high is None else atol_high
267+
atol_high = bvals.max() if atol_high is None else atol_high
268268

269269
# Keep only b-values within the range defined by atol_high and atol_low
270-
shellmask[bvalues > (bcenter + atol_high)] = False
271-
shellmask[bvalues < (bcenter - atol_low)] = False
270+
shellmask[bvals > (bcenter + atol_high)] = False
271+
shellmask[bvals < (bcenter - atol_low)] = False
272272

273273
if not shellmask.sum():
274274
raise RuntimeError(f"Shell corresponding to index {index} (b={bcenter}) is empty.")

0 commit comments

Comments
 (0)