Utils
Utils
filesys
create_dirs_on_path(f, create_parent_if_file=True)
function to create directories on given path if don't exist. Can be file or directory. If file needs create_parent_if_file flag
Parameters:
-
f
(Path or str
) –path to create dict on. can be dictionary or file
-
create_parent_if_file
(bool
, default:True
) –if f is a file create parent directory. Defaults to True.
Raises:
-
NotADirectoryError
–raises and error if f is file that has no suffix
Returns:
-
–
pathlib.Path: path with all directories created
Source code in src/simnetpy/utils/filesys.py
create_experiment_folder(path, timestamp=True, config_path=None, copysrc=True, src=SRCDIR)
Create experiment folder. Append timestamp to make name unique, copy src code to folder. copy config to folder
Parameters:
-
path
(str or Path
) –name/path for experiment output
-
src
(_type_
, default:SRCDIR
) –location of source code that generated the model. Defaults to HOME/phd/phd-year2/src/phd_year2.
-
config
(str or Path
) –location of config file.
Source code in src/simnetpy/utils/filesys.py
json_numpy_obj_hook(dct)
Decodes a previously encoded numpy ndarray with proper shape and dtype.
:param dct: (dict) json encoded ndarray :return: (ndarray) if input was an encoded ndarray
Source code in src/simnetpy/utils/filesys.py
plotting
sci_funcs
nanmean(x, allnanvalue=np.nan, **npkwds)
Function to compute np.nanmean and replace empty slice with user value. Defaults to np.nan i.e. np.nanmean([np.nan,np.nan]) = np.nan.
Parameters:
-
x
(ndarray
) –array to apply np.nanmean to.
-
allnanvalue
(int
, default:nan
) –Value in case of empty slice. Defaults to np.nan.
-
**npkwds
–keywords for np.nanmean function. e.g. axis=0 etc.
Returns: type: nan mean of array or allnanvalue in case of empty slice in array
Source code in src/simnetpy/utils/sci_funcs.py
non_nan_indices(X, offset=0)
Find indices that do not have all nan values. Amount of nans needed to be classified as a nan index can be adjusted with offset.
Parameters:
-
X
(ndarray
) –two dimensional (Nxd) array. nan counted per row.
-
offset
(int
, default:0
) –amount of columns with values to still be considered nan. i.e. a row with (d - offset) values missing is nan
Returns:
-
–
np.ndarray: 1d array of indices in range [0,N-1]