lezargus.library.convolution module#
Convolution functions and kernel producing functions.
Here, we group all convolution functions and kernel functions. A lot of the convolution functions are brief wrappers around Astropy’s convolution. All three dimensionalities are covered.
- lezargus.library.convolution.convolve_1d_array_by_1d_kernel(array: ndarray, kernel: ndarray) ndarray [source]#
Convolve a 1D array using a 1D kernel.
- Parameters:
array (ndarray) – The 1D array data which we will convolve.
kernel (ndarray) – The 1D kernel that we are using to convolve.
- Returns:
convolved_array – The convolved 1D array data.
- Return type:
ndarray
- lezargus.library.convolution.convolve_2d_array_by_2d_kernel(array: ndarray, kernel: ndarray) ndarray [source]#
Convolve a 2D array using a 2D kernel.
- Parameters:
array (ndarray) – The 2D array data which we will convolve.
kernel (ndarray) – The 2D kernel that we are using to convolve.
- Returns:
convolved_array – The convolved 2D array data.
- Return type:
ndarray
- lezargus.library.convolution.convolve_3d_array_by_1d_kernel(array: ndarray, kernel: ndarray) ndarray [source]#
Convolve a 3D array using a 1D kernel, looping 2 dimensions.
This convolution convolves 1D slices of the 3D array. The convolution itself then is a 1D array being convolved with a 1D kernel. We take slices of the last dimension, iterating over the 1st and 2nd dimension. A full 3D array and 3D kernel convolution is not done here.
- Parameters:
array (ndarray) – The 3D array data which we will convolve.
kernel (ndarray) – The 1D kernel that we are using to convolve.
- Returns:
convolved_array – The convolved 3D array data.
- Return type:
ndarray
- lezargus.library.convolution.convolve_3d_array_by_2d_kernel(array: ndarray, kernel: ndarray) ndarray [source]#
Convolve a 3D array using a 2D kernel, looping over the 3rd dimension.
This convolution convolves 2D slices of the 3D array. The convolution itself then is a 2D array being convolved with a 3D kernel. A full 3D array and 3D kernel convolution is not done here.
- Parameters:
array (ndarray) – The 3D array data which we will convolve.
kernel (ndarray) – The 2D kernel that we are using to convolve.
- Returns:
convolved_array – The convolved 3D array data.
- Return type:
ndarray
- lezargus.library.convolution.kernel_1d_gaussian(shape: tuple | int, stddev: float) ndarray [source]#
Return a 1D Gaussian convolution kernel.
We normalize the kernel via the amplitude of the Gaussian function as a whole for maximal precision: volume = 1. The stddev must be expressed in pixels.
- Parameters:
shape (tuple | int) – The shape of the 1D kernel, in pixels. If a single value (i.e. a size value instead), we attempt convert it to a shape-like value.
stddev (float) – The standard deviation of the Gaussian, in pixels.
- Returns:
gaussian_kernel – The discrete kernel array.
- Return type:
ndarray
- lezargus.library.convolution.kernel_1d_gaussian_resolution(shape: tuple | int, template_wavelength: ndarray | float, base_resolution: float | None = None, target_resolution: float | None = None, base_resolving_power: float | None = None, target_resolving_power: float | None = None, reference_wavelength: float | None = None) ndarray [source]#
Gaussian 1D kernel adapted for resolution convolution conversions.
This function is a wrapper around a normal 1D Gaussian kernel. Instead of specifying the standard deviation, we calculate the approximate required standard deviation needed to down-sample a base resolution to some target resolution. We accept both resolution values or resolving power values for the calculation; but we default to resolution based determination if possible.
- Parameters:
shape (tuple | int) – The shape of the 1D kernel, in pixels. If a single value (i.e. a size value instead), we attempt convert it to a shape-like value.
template_wavelength (ndarray or float) – An example wavelength array which this kernel will be applied to. This is required to convert the physical standard deviation value calculated from the resolution/resolving power to one of length in pixels/points. If an array, we try and compute the conversion factor. If a float, that is the conversion factor of wavelength per pixel.
base_resolution (float, default = None) – The base resolution that we are converting from. Must be provided along with target_resolution for the resolution mode.
target_resolution (float, default = None) – The target resolution we are converting to. Must be provided along with base_resolution for the resolution mode.
base_resolving_power (float, default = None) – The base resolving power that we are converting from. Must be provided along with target_resolving_power and reference_wavelength for the resolving power mode.
target_resolving_power (float, default = None) – The target resolving power that we are converting from. Must be provided along with base_resolving_power and reference_wavelength for the resolving power mode.
reference_wavelength (float, default = None) – The reference wavelength used to convert from resolving power to resolution. Must be provided along with base_resolving_power and target_resolving_power for the resolving power mode.
- Returns:
resolution_kernel – The Gaussian kernel with the appropriate parameters to convert from the base resolution to the target resolution with a convolution.
- Return type:
ndarray
- lezargus.library.convolution.kernel_2d_gaussian(shape: tuple, x_stddev: float, y_stddev: float, rotation: float) ndarray [source]#
Return a 2D Gaussian convolution kernel.
We normalize the kernel via the amplitude of the Gaussian function as a whole for maximal precision: volume = 1. We require the input of the shape of the kernel to allow for x_stddev and y_stddev to be expressed in pixels to keep it general. By definition, the center of the Gaussian kernel is in the center of the array.
- Parameters:
shape (tuple) – The shape of the 2D kernel, in pixels.
x_stddev (float) – The standard deviation of the Gaussian in the x direction, in pixels.
y_stddev (float) – The standard deviation of the Gaussian in the y direction, in pixels.
rotation (float) – The rotation angle, increasing counterclockwise, in radians.
- Returns:
gaussian_kernel – The discrete kernel array.
- Return type:
ndarray