stimupy.utils.utils#
Functions#
Round array to provided values (vals) |
|
All integer factors of integer n |
|
Get all argument names for a given function |
|
Bessel function of the first kind of real order and complex argument. |
|
Return a copy of an array, resized by the given factor. |
|
Return a copy of an array, resized by the given factor. |
|
Return a dict with resized key-arrays by the given factor. |
|
Return a dict with key-arrays rotated by nrots*90 degrees. |
|
Return a dict with key-arrays rotated by nrots*90 degrees. |
|
Return a dict with key-arrays rolled by shift in axes. |
|
Create a dictionary by stripping it from all keys that are not also an argument to the provided function |
|
Create two-sided version of a stimulus function |
|
|
|
|
- round_to_vals(arr, vals)[source]#
Round array to provided values (vals)
- Parameters:
arr (np.ndarray) – Numpy array which values will be rounded
vals (Sequence(float, ...)) – Values to which array will be rounded
- Returns:
out_arr – Rounded output array
- Return type:
np.ndarray
- int_factorize(n)[source]#
All integer factors of integer n
All integer factors, i.e., all integers that n is integer-divisible by. Also not a very efficient algorithm (brute force trial division), so should only be used as a helpter function.
- get_function_argument_names(func)[source]#
Get all argument names for a given function
- Parameters:
func (function) – Get argument names from this function
- Returns:
names – Tuple containing all argument names of given function
- Return type:
- apply_bessel(arr, order=0)[source]#
Bessel function of the first kind of real order and complex argument.
- Parameters:
arr (np.ndarray) – Input array
order (float) – Order of the bessel function. Default is 0.
- Returns:
out – Output array
- Return type:
np.ndarray
- resize_array(arr, factor)[source]#
Return a copy of an array, resized by the given factor. Every value is repeated factor[d] times along dimension d.
- Parameters:
arr (2D array) – the array to be resized
factor (tuple of 2 ints) – the resize factor in the y and x dimensions
- Return type:
An array of shape (arr.shape[0] * factor[0], arr.shape[1] * factor[1])
- resize_dict(dct, factor, keys=('img', '*mask'))[source]#
Return a copy of an array, resized by the given factor. Every value is repeated factor[d] times along dimension d.
- Parameters:
dct (dict) – dict containing arrays to be resized
factor (tuple of 2 ints) – the resize factor in the y and x dimensions
keys (Sequence[String, String] or String) – keys in dict for images to be padded
- Returns:
same as input dict but with larger key-arrays according to “(arr.shape[0] * factor[0], arr.shape[1] * factor[1])” and updated keys for “visual_size” and “shape”
- Return type:
- stack_dicts(dct1, dct2, direction='horizontal', keys=('img', '*mask'), keep_mask_indices=False)[source]#
Return a dict with resized key-arrays by the given factor. Every value is repeated factor[d] times along dimension d.
- Parameters:
- Returns:
same as input dict1 but with stacked key-arrays and updated keys for “visual_size” and “shape”
- Return type:
- rotate_dict(dct, nrots=1, keys=('img', '*mask'))[source]#
Return a dict with key-arrays rotated by nrots*90 degrees.
- Parameters:
- Returns:
same as input dict but with rotated key-arrays and updated keys for “visual_size” and “shape”
- Return type:
- flip_dict(dct, direction='lr', keys=('img', '*mask'))[source]#
Return a dict with key-arrays rotated by nrots*90 degrees.
- roll_dict(dct, shift, axes, keys=('img', '*mask'))[source]#
Return a dict with key-arrays rolled by shift in axes.
- Parameters:
- Returns:
same as input dict but with rolled key-arrays
- Return type:
- strip_dict(dct, func)[source]#
Create a dictionary by stripping it from all keys that are not also an argument to the provided function
- make_two_sided(func, two_sided_params)[source]#
Create two-sided version of a stimulus function
Where (some) parameters can be specified separately for each side. These parameters should then be specified as a 2-Sequence (2-ple, list of len=2), where entry [0] is the parameter value for left side, and [1] for right side. This means that if the kwarg takes a Sequence itself, e.g., intensities, then the two-sided specification must be, e.g., ((int_left_0, int_left_1), (int_right_0, int_right_1))
Will be left- and right-sided.
- Parameters:
func (function) – stimulus function to double
two_sided_params (Sequence[str]) – names of parameters (kwargs) of func that can be specified separately for each side of the display.
- Returns:
two-sided version of stimulus function
- Return type:
function