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 frompath
if it exists. Otherwisecreate
the value,save
it topath
, and return it.args
andkwargs
are passed tocreate
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 atpath
.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.save_json(value, path: Union[Path, str], *, indent: Optional[int] = None)[source]¶
Dump a json-serializable object to a json file.
- 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
withallow_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 interfacesave(what, where)
.