prysm.util¶
Utility functions.
-
prysm.util.
is_odd
(int)¶ Determine if an interger is odd using binary operations.
- Parameters
int (int) – an integer
- Returns
true if odd, False if even
- Return type
bool
-
prysm.util.
is_power_of_2
(value)¶ Check if a value is a power of 2 using binary operations.
- Parameters
value (number) – value to check
- Returns
true if the value is a power of two, False if the value is no
- Return type
bool
Notes
c++ inspired implementation, see SO: https://stackoverflow.com/questions/29480680/finding-if-a-number-is-a-power-of-2-using-recursion
-
prysm.util.
fold_array
(array, axis=1)¶ Fold an array in half over the given axis and averages.
- Parameters
array (numpy.ndarray) – ndarray
axis (int, optional) – axis to fold over
- Returns
folded array
- Return type
numpy.ndarray
Reurns the given figure and/or axis if given one. If they are None, creates a new fig/ax.
- Parameters
fig (matplotlib.figure.Figure, optional) – figure
ax (matplotlib.axes.Axis) – axis or array of axes
numax (int) – number of axes in the desired figure, 1 for most plots, 3 for plot_fourier_chain
sharex (bool, optional) – whether to share the x axis
sharey (bool, optional) – whether to share the y axis
- Returns
matplotlib.figure.Figure – A figure object
matplotlib.axes.Axis – An axis object
-
prysm.util.
mean
(array)¶ Return the mean value of the valid elements of an array.
- Parameters
array (numpy.ndarray) – array of values
- Returns
mean value
- Return type
float
-
prysm.util.
pv
(array)¶ Return the PV value of the valid elements of an array.
- Parameters
array (numpy.ndarray) – array of values
- Returns
PV of the array
- Return type
float
-
prysm.util.
rms
(array)¶ Return the RMS value of the valid elements of an array.
- Parameters
array (numpy.ndarray) – array of values
- Returns
RMS of the array
- Return type
float
-
prysm.util.
Sa
(array)¶ Return the Ra value for the valid elements of an array.
- Parameters
array (numpy.ndarray) – array of values
- Returns
Ra of the array
- Return type
float
-
prysm.util.
std
(array)¶ Return the standard deviation of the valid elements of an array.
- Parameters
array (numpy.ndarray) – array of values
- Returns
std of the array
- Return type
float
-
prysm.util.
guarantee_array
(variable)¶ Guarantee that a varaible is a numpy ndarray and supports -, *, +, and other operators.
- Parameters
variable (number or numpy.ndarray) – variable to coalesce
- Returns
an object that supports * / and other operations with ndarrays
- Return type
object
- Raises
ValueError – non-numeric type
-
prysm.util.
ecdf
(x)¶ Compute the empirical cumulative distribution function of a dataset.
- Parameters
x (iterable) – Data
- Returns
xs (numpy.ndarray) – sorted data
ys (numpy.ndarray) – cumulative distribution function of the data
-
prysm.util.
sort_xy
(x, y)¶ Sorts a pair of x and y iterables, returning arrays in order of ascending x.
- Parameters
x (iterable) – a list, numpy ndarray, or other iterable to sort by
y (iterable) – a list, numpy ndarray, or other iterable that is y=f(x)
- Returns
sorted_x (iterable) – an iterable containing the sorted x elements
sorted_y (iterable) – an iterable containing the sorted y elements