Skip to content

Data

module for loading fMRI data and features and the like

Functions

load_fmri(story, subject)

Load fMRI data. Return ndarray with shape [time, voxels].

Source code in src/data.py
208
209
210
211
212
213
214
215
216
217
218
219
220
def load_fmri(story: str, subject: str) -> np.ndarray:
    """Load fMRI data. Return ndarray with shape [time, voxels]."""

    subject_dir = Path(DATADIR, f"derivative/preprocessed_data/{subject}")
    resp_path = Path(subject_dir, f"{story}.hf5")
    hf = h5py.File(resp_path, "r")
    log.info(
        f"{story}.hf5"
        f" | {subject}"
        f" | time: {hf['data'].shape[0]}"
        f" | voxels: {hf['data'].shape[1]}"
    )
    return np.array(hf["data"][:])  # type: ignore

load_wav(story)

Load wav file. Return ndarray with shape [samples, channels].

Source code in src/data.py
30
31
32
33
34
35
36
37
38
39
40
def load_wav(story: str) -> Tuple[int, np.ndarray]:
    """Load wav file. Return ndarray with shape [samples, channels]."""

    wav_path = Path(DATADIR, WAV_DIR, f"{story}.wav")
    sample_rate, wav = wavfile.read(wav_path)
    log.info(
        f"{story}.wav"
        f" | channels: {wav.shape[1]}"
        f" | length {wav.shape[0] / sample_rate}s"
    )
    return sample_rate, wav