Skip to content

Splitter

openseize.file_io.edf.splitter(path, mapping, outdir=None)

Creates separate EDFs from a multichannel EDF.

This tool is useful for partitioning an EDF with channels from different subjects into multiple single subject EDFs. The original 'unsplit' EDF is left unmodified.

Parameters:

Name Type Description Default
path Path

Path to an EDF file to be split.

required
mapping Dict

A mapping of filenames and channel indices for each disjoined EDF file to be written.

required
outdir Optional[Union[str, Path]]

Directory where each file in mapping should be written. If None provided, the directory of the unsplit edf path will be used.

None
Source code in openseize/file_io/edf.py
def splitter(path: Path,
             mapping: Dict,
             outdir: Optional[Union[str, Path]] = None,
) -> None:
    """Creates separate EDFs from a multichannel EDF.

    This tool is useful for partitioning an EDF with channels from different
    subjects into multiple single subject EDFs. The original 'unsplit' EDF
    is left unmodified.

    Args:
        path:
            Path to an EDF file to be split.
        mapping:
            A mapping of filenames and channel indices for each disjoined
            EDF file to be written.
        outdir:
            Directory where each file in mapping should be written. If None
            provided, the directory of the unsplit edf path will be used.
    """

    reader = Reader(path)
    outdir = Path(outdir) if outdir else reader.path.parent
    for fname, indices in mapping.items():
        target = outdir.joinpath(Path(fname).with_suffix('.edf'))
        with Writer(target) as outfile:
            outfile.write(reader.header, reader, indices)
    reader.close()