# We can apply preprocessing steps to the dataset. It is also possible to skip
# this step and not apply any preprocessing.
preprocess(
    concat_ds=ds,
    preprocessors=[MNEPreproc(fn='resample', sfreq=10)]
)

###############################################################################
# We save the dataset to a an existing directory. It will create a '.fif' file 
# for every dataset in the concat dataset. Additionally it will create two 
# JSON files, the first holding the description of the dataset, the second 
# holding the name of the target. If you want to store to the same directory 
# several times, for example due to trying different preprocessing, you can 
# choose to overwrite the existing files.
ds.save(
    path='./',
    overwrite=False,
)

##############################################################################
# We load the saved dataset from a directory. Signals can be preloaded in 
# compliance with mne. Optionally, only specific '.fif' files can be loaded 
# by specifying their ids. The target name can be changed, if the dataset 
# supports it (TUHAbnormal for example supports 'pathological', 'age', and 
# 'gender'. If you stored a preprocessed version with target 'pathological' 
# it is possible to change the target upon loading).
ds_loaded = load_concat_dataset(
    path='./',
    preload=True,
    ids_to_load=[1,3],
    target_name=None,
)
preprocess(
    concat_ds=dataset,
    preprocessors=[MNEPreproc(fn='resample', sfreq=10)]
)

###############################################################################
# We save the dataset to a an existing directory. It will create a '.fif' file
# for every dataset in the concat dataset. Additionally it will create two
# JSON files, the first holding the description of the dataset, the second
# holding the name of the target. If you want to store to the same directory
# several times, for example due to trying different preprocessing, you can
# choose to overwrite the existing files.

tmpdir = tempfile.mkdtemp()  # write in a temporary directory
dataset.save(
    path=tmpdir,
    overwrite=False,
)

##############################################################################
# We load the saved dataset from a directory. Signals can be preloaded in
# compliance with mne. Optionally, only specific '.fif' files can be loaded
# by specifying their ids. The target name can be changed, if the dataset
# supports it (TUHAbnormal for example supports 'pathological', 'age', and
# 'gender'. If you stored a preprocessed version with target 'pathological'
# it is possible to change the target upon loading).
dataset_loaded = load_concat_dataset(
    path=tmpdir,
    preload=True,
    ids_to_load=[1, 3],
    target_name=None,
)