7.13. Adding Data Dump Assets¶
junifer supports dumping nibabel.Nifti1Image and pandas.DataFrame which should cover most fMRI use cases. But, in case you work with other modalities like EEG, you can register your own data dump asset.
7.13.1. How to add a data dump asset¶
This example shows how to create a data dump asset for mne.io.Raw.
Check extending junifer on how to create a junifer extension if you have not done so.
Create the data registry in the extension script like so:
from pathlib import Path from junifer.api.decorators import register_data_dump_asset from junifer.pipeline import BaseDataDumpAsset import mne @register_data_dump_asset([mne.io.Raw], [".fif", ".fif.gz"]) class RawAsset(BaseDataDumpAsset): """Class for ``mne.io.Raw`` dumper.""" def dump(self) -> None: self.data.save(self.path_without_ext.with_suffix(".raw.fif.gz")) @classmethod def load(cls: "RawAsset", path: Path) -> mne.io.Raw: return mne.io.Raw(path)
register_data_dump_asset()registers a class. The first argument is a list of types that the class is responsible for saving and the second argument is a list of file extensions that the class is responsible for loading.Inheriting from
junifer.pipeline.BaseDumpAssettakes care of the class acting as a data dump asset.Method
junifer.pipeline.BaseDumpAsset.dumpand class methodjunifer.pipeline.BaseDumpAsset.loadneed to be implemented.