NPZInputOutput#
- class pybrops.core.io.NPZInputOutput.NPZInputOutput[source]#
Bases:
object
Abstract class for defining NPZ input/output functionality.
This abstract class defines two functions with the following purposes:
to_npz
- write an object to a.npz
file.from_npz
- load an object from a.npz
file.
Methods
Read an object from a
.npz
file.Write an object to a
.npz
file.- abstract classmethod from_npz(filename, mmap_mode, allow_pickle, fix_imports, encoding, max_header_size, **kwargs)[source]#
Read an object from a
.npz
file.- Parameters:
filename (str, Sequence of str) –
.npz
file name from which to load object field(s).mmap_mode (str, None, default = None) – Options are
{None, "r+", "r", "w+", "c"}
If notNone
, then memory-map the file, using the given mode (seenumpy.memmap
for a detailed description of the modes). A memory-mapped array is kept on disk. However, it can be accessed and sliced like anyndarray
. Memory mapping is especially useful for accessing small fragments of large files without reading the entire file into memory. Default:None
allow_pickle (bool, default = False) – Allow loading pickled object arrays stored in
.npz
files. Reasons for disallowing pickles include security, as loading pickled data can execute arbitrary code. If pickles are disallowed, loading object arrays will fail. Default:False
fix_imports (bool, default = True) – Only useful when loading Python 2 generated pickled files on Python 3, which includes
.npz
/.npz
files containing object arrays. Iffix_imports
isTrue
, pickle will try to map the old Python 2 names to the new names used in Python 3. Default:True
encoding (str, default = "ASCII") – What encoding to use when reading Python 2 strings. Only useful when loading Python 2 generated pickled files in Python 3, which includes
.npz
/.npz
files containing object arrays. Values other than"latin1"
,"ASCII"
, and"bytes"
are not allowed, as they can corrupt numerical data. Default:"ASCII"
max_header_size (int, optional) – Maximum allowed size of the header. Large headers may not be safe to load securely and thus require explicitly passing a larger value. See
ast.literal_eval
for details. This option is ignored whenallow_pickle
is passed. In that case the file is by definition trusted and the limit is unnecessary. Default:10000
kwargs (dict) – Additional keyword arguments to use for dictating importing from a
.npz
file(s).
- Returns:
out – An object read from a
.npz
file.- Return type: