pyselfi.utils module¶
Generic infrastructure routines.
- pyselfi.utils.ExecuteBashCommand(commandString)[source]¶
Prints and executes a bash command.
- Parameters
commandString (
str
) – command line
- pyselfi.utils.ExecuteBashCommandMute(commandString)[source]¶
Executes a bash command without printing it.
- Parameters
commandString (
str
) – command line
- pyselfi.utils.ExecuteBashCommandOutput(commandString)[source]¶
Prints and executes a bash command, returns the output.
- Parameters
commandString (
str
) – command line- Returns
output – the result of subprocess.check_output
- Return type
str
- pyselfi.utils.FatalError(message)[source]¶
Prints an error to screen and ends the script.
- Parameters
message (
str
) – message
- pyselfi.utils.PrintCommandLine(message)[source]¶
Prints a bash command line to screen.
- Parameters
message (
str
) – message
- pyselfi.utils.PrintDiagnostic(verbosity, message)[source]¶
Prints a diagnostic to screen.
- Parameters
verbosity (int) – verbosity of the message
message (
str
) – message
- pyselfi.utils.PrintError(message)[source]¶
Prints an error to screen.
- Parameters
message (
str
) – message
- pyselfi.utils.PrintInfo(message)[source]¶
Prints an information to screen.
- Parameters
message (
str
) – message
- pyselfi.utils.PrintLeftType(message_type, FONT_COLOR)[source]¶
Prints the type of output to screen.
- Parameters
message_type (
str
) – type of messageFONT_COLOR (
str
) – font color for this type of message
- pyselfi.utils.PrintMessage(verbosity, message)[source]¶
Prints a message to screen.
- Parameters
verbosity (int) – verbosity of the message
message (
str
) – message
- pyselfi.utils.PrintPythonCommand()[source]¶
Prints a python command to screen.
- Parameters
message (
str
) – message
- pyselfi.utils.PrintValue(name, value)[source]¶
Prints the value of a variable to screen.
- Parameters
name (
str
) – name of variable to be printedvalue (
str
) – value of variable to be printed
- pyselfi.utils.PrintWarning(message)[source]¶
Prints a warning to screen.
- Parameters
message (
str
) – message
- pyselfi.utils.get_index(i, j, k, N1, N2=None, N0=None)[source]¶
Gets 1D index from 3D indices. Assumes row-major ordering. WARNING: N0 is passed last when all of N0,N1,N2 are specified!
- Parameters
i (int) – 3D index x
j (int) – 3D index y
k (int) – 3D index z
N1 (int) – size of the array y
N2 (int, optional, default=N1) – size of the array z
N0 (int, optional, default=N1) – size of the array x
- Returns
Id – corresponding 1D index
- Return type
int
- pyselfi.utils.get_indices(Id, N0, N1=None, N2=None)[source]¶
Gets 3D indices from 1D index. Assumes row-major ordering.
- Parameters
Id (int) – 1D index
N0 (int) – size of the array x
N1 (int, optional, default=N0) – size of the array y
N2 (int, optional, default=N0) – size of the array z
Returns
(i,j,k) (array, int, dimension=3) – corresponding 3D indices
- pyselfi.utils.p_load(file, mmap_mode=None, allow_pickle=True, fix_imports=True, encoding='ASCII')[source]¶
Loads arrays or pickled objects from
.npy
,.npz
or pickled files. (Replacement of numpy.load, see its documentation).
- pyselfi.utils.p_loadtxt(file, dtype=None, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=True, ndmin=0, encoding='bytes')[source]¶
Loads data from a text file. Each row in the text file must have the same number of values. (Replacement of numpy.loadtxt, see its documentation). WARNING: contrary to numpy.loadtxt, unpack is set to True by default.
- pyselfi.utils.p_save(file, arr, allow_pickle=True, fix_imports=True)[source]¶
Saves an array to a binary file in NumPy
.npy
format. (Replacement of numpy.save, see its documentation).
- pyselfi.utils.p_savetxt(file, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ', encoding=None)[source]¶
Saves an array to a text file. (Replacement of numpy.savetxt, see its documentation).
- pyselfi.utils.p_savez(file, *args, **kwds)[source]¶
Saves several arrays into a single file in uncompressed
.npz
format. (Replacement of numpy.savez, see its documentation).
- pyselfi.utils.regular_inv(A, EPS_A=1e-07, EPS_residual=0.001)[source]¶
Computes the inverse of a matrix. Attempts a regularization by adding an epsilon to the diagonal, if the matrix is ill-conditioned.
- Parameters
A (array-like, square) – input matrix
EPS_A (double, optional, default=1e-7) – epsilon to be added to the diagonal of A, if necessary
EPS_residual (double, optional, default=1e-3) – maximum residual in A*A^{-1} before attempting regularization
- Returns
A^{-1} – numerical inverse of A
- Return type
array-like, square
- pyselfi.utils.save_replace_attr(hf, address, attr, dtype)[source]¶
Saves or replaces an attribute in a hdf5 file.
- Parameters
hf (
h5py.File
) – hdf5 file (already opened with writing permission)address (
str
) – address of the attribute to be written/replacedattr (array) – attribute to be saved
dtype (array) – data type
- pyselfi.utils.save_replace_dataset(hf, address, data, maxshape, dtype)[source]¶
Saves or replaces a dataset in a hdf5 file. The dataset must be resizable (see the HDF5 manual).
- Parameters
hf (
h5py.File
) – hdf5 file (already opened with writing permission)address (
str
) – address of the dataset to be written/replaceddata (array) – data to be saved
maxshape (array or None) – maximum size of the array
dtype (array) – data type