Utility Functions¶
General utility functions.
-
autolab_core.
gen_experiment_id
(n=10)¶ Generate a random string with n characters.
- Parameters
n (int) – The length of the string to be generated.
- Returns
A string with only alphabetic characters.
- Return type
str
-
autolab_core.
histogram
(values, num_bins, bounds, normalized=True, plot=False, color='b')¶ Generate a histogram plot.
- Parameters
values (
numpy.ndarray
) – An array of values to put in the histogram.num_bins (int) – The number equal-width bins in the histogram.
bounds (
tuple
of float) – Two floats - a min and a max - that define the lower and upper ranges of the histogram, respectively.normalized (bool) – If True, the bins will show the percentage of elements they contain rather than raw counts.
plot (bool) – If True, this function uses pyplot to plot the histogram.
color (
str
) – The color identifier for the plotted bins.
- Returns
The values of the histogram and the bin edges as ndarrays.
- Return type
tuple of `:obj:`numpy.ndarray
-
autolab_core.
skew
(xi)¶ Return the skew-symmetric matrix that can be used to calculate cross-products with vector xi.
Multiplying this matrix by a vector v gives the same result as xi x v.
- Parameters
xi (
numpy.ndarray
of float) – A 3-entry vector.- Returns
The 3x3 skew-symmetric cross product matrix for the vector.
- Return type
numpy.ndarray
of float
-
autolab_core.
deskew
(S)¶ Converts a skew-symmetric cross-product matrix to its corresponding vector. Only works for 3x3 matrices.
- Parameters
S (
numpy.ndarray
of float) – A 3x3 skew-symmetric matrix.- Returns
A 3-entry vector that corresponds to the given cross product matrix.
- Return type
numpy.ndarray
of float
-
autolab_core.
pretty_str_time
(dt)¶ Get a pretty string for the given datetime object.
- Parameters
dt (
datetime
) – A datetime object to format.- Returns
The datetime formatted as {year}_{month}_{day}_{hour}_{minute}.
- Return type
str
-
autolab_core.
filenames
(directory, tag='', sorted=False, recursive=False)¶ Reads in all filenames from a directory that contain a specified substring.
- Parameters
directory (
str
) – the directory to read fromtag (
str
) – optional tag to match in the filenamessorted (bool) – whether or not to sort the filenames
recursive (bool) – whether or not to search for the files recursively
- Returns
filenames to read from
- Return type
list
ofstr