LazyInterval#

class torch_brain.data.LazyInterval(**kwargs)[source]#

Bases: torch_brain.data.interval.Interval

Lazy variant of Interval. The data is not loaded until it is accessed. This class is meant to be used when the data is too large to fit in memory, and is intended to be intantiated via. LazyInterval.from_hdf5.

Note

To access an attribute without triggering the in-memory loading use self.__dict__[key] otherwise using self.key or getattr(self, key) will trigger the lazy loading and will automatically convert the h5py dataset to a numpy array as well as apply any outstanding masks.

select_by_mask(mask)[source]#

Index all arrays with a boolean mask and return a copy.

Lazy attributes will remain lazy, and masking will be applied to them upon access.

Parameters:

mask (ndarray) – Boolean array used for masking. The mask needs to be 1-dimensional, and of equal length as the object itself.

slice(start, end, reset_origin=True)[source]#

Returns a new Interval object that contains the data between the start and end times. An interval is included if it has any overlap with the slicing window.

to_hdf5(file)[source]#

Saves the data object to an HDF5 file.

Parameters:

file – HDF5 file.

import h5py
from torch_brain.data import Interval

interval = Interval(
    start=[0, 1, 2],
    end=[1, 2, 3],
    go_cue_time=[0.5, 1.5, 2.5],
    drifting_gratins_dir=[0, 45, 90],
    timekeys=["start", "end", "go_cue_time"],
)

with h5py.File("data.h5", "w") as f:
    interval.to_hdf5(f)
classmethod from_hdf5(file)[source]#

Loads the data object from an HDF5 file.

Parameters:

file – HDF5 file.

import h5py
from torch_brain.data import ArrayDict

with h5py