- pecans.utilities.general_utils.ensure_n_args_to_return(n_args, args_iterable, fill_val=None)[source]
Create a tuple of arguments to return that is guaranteed to have a certain number of elements
Since Python does tuple expansion, you can return a tuple from a function and have each element of the tuple expanded into individual return values. For example:
def return_tuple(): return ('a','b','c') x, y, z = return_tuple()
would put
'a'intox,'b'intoy, and'c'intoz. However, this means that there must be exactly one or three variables to receive the output of return_tuple(), i.e.x, y = return_tuple()would fail. This can be a problem if a function is trying to return a dynamic number of values, since it means the call would have to account for that. This function will create a tuple with a guaranteed number of values.- Parameters:
n_args (int) – how many return values you want the tuple to contain
args_iterable (list or tuple) – an iterable (currently only tuples and lists supported) that contains <= n_args elements to return.
fill_val (any) – optional, the value to append to the returned tuple to fill it out. Default is None.
- Returns:
the tuple form of args_iterable with exactly n_args elements
- Return type:
tuple
- pecans.utilities.general_utils.gaussian(center_x, sigma_x, x, center_y=None, sigma_y=None, y=None, center_z=None, sigma_z=None, z=None, normalized=True)[source]
Compute a Gaussian curve. Currently only implemented for 1D
- Parameters:
center (float) – the center point in the same coordinates as x, y, and z
sigma (float) – the sigma width in the same units as x, y, and z
x (
numpy.ndarray) – the x-coordinate to compute the Gaussian along.y (
numpy.ndarray) – the y-coordinate to compute the Gaussian along.z (
numpy.ndarray) – the z-coordinate to compute the Gaussian along.normalized (bool) – whether or not to normalize the gaussian so that its area is 1. Default is True.
- Returns:
an array of size nx-by-ny-by-nz.
- Return type:
numpy.ndarray.