Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
fix: Restore access to HDF5 file
Browse files Browse the repository at this point in the history
  • Loading branch information
esavary committed Mar 27, 2024
1 parent 82a557e commit d45ec01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/eddymotion/data/dmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class DWI:
)
"""A path to an HDF5 file to store the whole dataset."""

def get_filename(self):
"""Get the filepath of the HDF5 file."""
return self._filepath

def __len__(self):
"""Obtain the number of high-*b* orientations."""
return self.dataobj.shape[-1]
Expand Down
13 changes: 12 additions & 1 deletion src/eddymotion/data/splitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
# https://www.nipreps.org/community/licensing/
#
"""Data splitting helpers."""
from pathlib import Path
import numpy as np
import h5py


def lovo_split(data, index):
Expand All @@ -46,14 +48,23 @@ def lovo_split(data, index):
"""

if not Path(data.get_filename()).exists():
data.to_filename(data.get_filename())

# if the size of the mask does not match data, cache is stale
mask = np.zeros(len(data), dtype=bool)
mask[index] = True

# read original DWI data & b-vector
with h5py.File(data.get_filename(), "r") as in_file:
root = in_file["/0"]
dwframe = np.asanyarray(root["dataobj"][..., mask])
bframe = np.asanyarray(root["gradients"][..., mask])

train_data = data.dataobj[..., ~mask]
train_gradients = data.gradients[..., ~mask]

return (
(train_data, train_gradients),
(data.dataobj[..., mask], data.gradients[..., mask]),
(dwframe, bframe),
)

0 comments on commit d45ec01

Please sign in to comment.