NPZInputOutput#
- class pybrops.core.io.NPZInputOutput.NPZInputOutput[source]#
Bases:
objectAbstract class for defining NPZ input/output functionality.
This abstract class defines two functions with the following purposes:
to_npz- write an object to a.npzfile.from_npz- load an object from a.npzfile.
Methods
Read an object from a
.npzfile.Write an object to a
.npzfile.- abstract classmethod from_npz(filename, mmap_mode, allow_pickle, fix_imports, encoding, max_header_size, **kwargs)[source]#
Read an object from a
.npzfile.- Parameters:
filename (str, Sequence of str) –
.npzfile 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.memmapfor 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:Noneallow_pickle (bool, default = False) – Allow loading pickled object arrays stored in
.npzfiles. Reasons for disallowing pickles include security, as loading pickled data can execute arbitrary code. If pickles are disallowed, loading object arrays will fail. Default:Falsefix_imports (bool, default = True) – Only useful when loading Python 2 generated pickled files on Python 3, which includes
.npz/.npzfiles containing object arrays. Iffix_importsisTrue, pickle will try to map the old Python 2 names to the new names used in Python 3. Default:Trueencoding (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/.npzfiles 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_evalfor details. This option is ignored whenallow_pickleis passed. In that case the file is by definition trusted and the limit is unnecessary. Default:10000kwargs (dict) – Additional keyword arguments to use for dictating importing from a
.npzfile(s).
- Returns:
out – An object read from a
.npzfile.- Return type: