Input/Output

Input/Output operations.

All the loading functions have the interface load(path, **kwargs) where kwargs are loader-specific keyword arguments.

Similarly, all the saving functions have the interface save(value, path, **kwargs).

class dpipe.io.ConsoleArguments[source]

Bases: object

A class that simplifies access to console arguments.

dpipe.io.load_or_create(path: ~typing.Union[~pathlib.Path, str], create: ~typing.Callable, *args, save: ~typing.Callable = <function save>, load: ~typing.Callable = <function load>, **kwargs)[source]

load a file from path if it exists. Otherwise create the value, save it to path, and return it.

args and kwargs are passed to create as additional arguments.

dpipe.io.choose_existing(*paths: Union[Path, str]) Path[source]

Returns the first existing path from a list of paths.

dpipe.io.load(path: Union[Path, str], ext: Optional[str] = None, **kwargs)[source]

Load a file located at path. kwargs are format-specific keyword arguments.

The following extensions are supported:

npy, tif, png, jpg, bmp, hdr, img, csv, dcm, nii, nii.gz, json, mhd, csv, txt, pickle, pkl, config

dpipe.io.save(value, path: Union[Path, str], **kwargs)[source]

Save value to a file located at path. kwargs are format-specific keyword arguments.

The following extensions are supported:

npy, npy.gz, tif, png, jpg, bmp, hdr, img, csv nii, nii.gz, json, mhd, csv, txt, pickle, pkl

dpipe.io.load_json(path: Union[Path, str])[source]

Load the contents of a json file.

dpipe.io.save_json(value, path: Union[Path, str], *, indent: Optional[int] = None)[source]

Dump a json-serializable object to a json file.

dpipe.io.load_pickle(path: Union[Path, str])[source]

Load a pickled value from path.

dpipe.io.save_pickle(value, path: Union[Path, str])[source]

Pickle a value to path.

dpipe.io.load_numpy(path: Union[Path, str], *, allow_pickle: bool = True, fix_imports: bool = True, decompress: bool = False)[source]

A wrapper around np.load with allow_pickle set to True by default.

dpipe.io.save_numpy(value, path: Union[Path, str], *, allow_pickle: bool = True, fix_imports: bool = True, compression: Optional[int] = None, timestamp: Optional[int] = None)[source]

A wrapper around np.save that matches the interface save(what, where).

dpipe.io.load_csv(path: Union[Path, str], **kwargs)[source]
dpipe.io.save_csv(value, path: Union[Path, str], *, compression: Optional[int] = None, **kwargs)[source]
dpipe.io.load_text(path: Union[Path, str])[source]
dpipe.io.save_text(value: str, path: Union[Path, str])[source]