apollon.io.io module¶
apollon/io.py – General I/O functionallity.
Licensed under the terms of the BSD-3-Clause license. Copyright (C) 2019 Michael Blaß, mblass@posteo.net
- Classes:
FileAccessControl Descriptor for file name attributes.
- Functions:
array_print_opt Set format for printing numpy arrays. files_in_folder Iterate over all files in given folder. generate_outpath Compute path for feature output. load_from_pickle Load pickled data. repath Change path but keep file name. save_to_pickle Pickle some data.
-
class
apollon.io.io.
PoissonHmmEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶ Bases:
apollon.io.json.ArrayEncoder
JSON encoder for PoissonHmm.
-
default
(o)¶ Custon default JSON encoder. Properly handles <class ‘PoissonHMM’>.
Note: Falls back to
ArrayEncoder
for all types that do not implement ato_dict()
method.- Params:
o (any) Object to encode.
- Returns
(dict)
-
-
class
apollon.io.io.
WavFileAccessControl
¶ Bases:
object
Control initialization and access to the
file
attribute of class:AudioData
.This assures that the path indeed points to a file, which has to be a .wav file. Otherwise an error is raised. The path to the file is saved as absolute path and the attribute is read-only.
-
apollon.io.io.
array_print_opt
(*args, **kwargs)¶ Set print format for numpy arrays.
Thanks to unutbu: https://stackoverflow.com/questions/2891790/how-to-pretty-print-a- numpy-array-without-scientific-notation-and-with-given-pre
-
apollon.io.io.
generate_outpath
(in_path: Union[str, pathlib.Path], out_path: Optional[Union[str, pathlib.Path]], suffix: Optional[str] = None) → Union[str, pathlib.Path]¶ Generates file paths for feature und HMM output files.
If
out_path
isNone
, the basename ofin_path
is taken with the extension replaced bysuffix
.- Parameters
in_path – Path to file under analysis.
out_path – Commandline argument.
suffix – File extension.
- Returns
Valid output path.
-
apollon.io.io.
load_from_npy
(path: Union[str, pathlib.Path]) → numpy.ndarray¶ Load data from numpy’s binary format.
- Parameters
path – File path.
- Returns
Data as numpy array.
-
apollon.io.io.
load_from_pickle
(path: Union[str, pathlib.Path]) → Any¶ Load a pickled file.
- Parameters
path – Path to file.
- Returns
Unpickled object
-
apollon.io.io.
repath
(current_path: Union[str, pathlib.Path], new_path: Union[str, pathlib.Path], ext: Optional[str] = None) → Union[str, pathlib.Path]¶ Change the path and keep the file name. Optinally change the extension, too.
- Parameters
current_path – The path to change.
new_path – The new path.
ext – Change file extension if
ext
is not None.
- Returns
New path.
-
apollon.io.io.
save_to_npy
(data: numpy.ndarray, path: Union[str, pathlib.Path]) → None¶ Save an array to numpy binary format without using pickle.
- Parameters
data – Numpy array.
path – Path to save the file.
-
apollon.io.io.
save_to_pickle
(data: Any, path: Union[str, pathlib.Path]) → None¶ Pickles data to path.
- Parameters
data – Pickleable object.
path – Path to save the file.