Utilities
korvax.util
autocorrelate
autocorrelate(x, /, max_size=None, axis=-1)
Compute the autocorrelation of the input array along the specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[ArrayLike, ...]
|
Input array. |
required |
max_size
|
int | None
|
Maximum size of the autocorrelation lags. If |
None
|
axis
|
int
|
Axis along which to compute the autocorrelation. Default: |
-1
|
Returns:
| Type | Description |
|---|---|
Float[Array, ...]
|
Autocorrelated array. |
Source code in src/korvax/util.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
frame
frame(x, /, frame_length, hop_length)
Slice a JAX array into overlapping frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, '*channels n_samples']
|
Input array. |
required |
frame_length
|
int
|
Length of each frame. |
required |
hop_length
|
int
|
Number of samples between adjacent frame starts. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '*channels {frame_length} n_frames=1+(n_samples-{frame_length})//{hop_length}']
|
Array with the last axis sliced into overlapping frames. |
Source code in src/korvax/util.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
overlap_and_add
overlap_and_add(x, hop_length)
Construct a signal from overlapping frames with overlap-and-add.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, '*channels frame_length n_frames']
|
Input array containing overlappinig frames. |
required |
hop_length
|
int
|
Number of samples between adjacent frame starts. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '*channels n_samples']
|
Constructed time-domain signal. |
Source code in src/korvax/util.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
pad_center
pad_center(x, /, size, pad_kwargs=dict())
Pad the input array on both sides to center it in a new array of given size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, '*channels n_samples']
|
Input array. |
required |
size
|
int
|
Desired size of the last axis after padding. |
required |
pad_kwargs
|
dict[str, Any]
|
Additional keyword arguments forwarded to |
dict()
|
Returns:
| Type | Description |
|---|---|
Float[Array, '*channels {size}']
|
Array with the last axis center-padded to the desired size. |
Source code in src/korvax/util.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
fix_length
fix_length(x, /, size, **pad_kwargs)
Fix the length of the input array to a given size by either trimming or padding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, '*channels n_samples']
|
Input array. |
required |
size
|
int
|
Desired size of the last axis after fixing length. |
required |
**pad_kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Float[Array, '*channels {size}']
|
Array with the last axis fixed to the desired size. |
Source code in src/korvax/util.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
get_window
get_window(window, Nx=None, fftbins=True, dtype=None)
Return the passed array, or the output of scipy.signal.get_window as a JAX array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
_WindowSpec
|
Window specification. |
required |
Nx
|
int | None
|
Length of the returned window. |
None
|
fftbins
|
bool
|
If |
True
|
dtype
|
DTypeLike | None
|
Desired data type of the returned array. If none, uses the default JAX
floating point type, which might be |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, ' {Nx}']
|
The window as a JAX array. |
Source code in src/korvax/util.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
is_array
is_array(x)
Check if the input is a JAX or NumPy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Input value to check. |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[Array | ndarray]
|
True if the input is a JAX or NumPy array, False otherwise. |
Source code in src/korvax/util.py
167 168 169 170 171 172 173 174 175 176 | |
feps
feps(x)
Get the machine epsilon for the data type of the input array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Inexact[ArrayLike, ...]
|
Input array. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Machine epsilon as a float. |
Source code in src/korvax/util.py
179 180 181 182 183 184 185 186 187 188 | |
normalize
normalize(x, /, ord=None, axis=None, threshold=None)
Normalize an array by its norm along the specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Inexact[Array, '*dims']
|
Input array. |
required |
ord
|
float | str | None
|
Order of the norm. See |
None
|
axis
|
int | tuple[int, ...] | None
|
Axis or axes along which to compute the norm. If None, normalizes over all axes. |
None
|
threshold
|
float | None
|
Minimum norm value below which normalization is skipped. If None, uses machine epsilon. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '*dims']
|
Normalized array. |
Source code in src/korvax/util.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
expand_to
expand_to(x, /, ndim, axes)
Expand the dimensions of an array to a given number of dimensions by adding singleton dimensions at specified axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Shaped[ArrayLike, '*']
|
Input array. |
required |
ndim
|
int
|
Desired number of dimensions after expansion. |
required |
axes
|
int | tuple[int, ...]
|
Axes at which to add singleton dimensions. |
required |
Returns:
| Type | Description |
|---|---|
Shaped[Array, '*expanded_shape']
|
Expanded array. |
Source code in src/korvax/util.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
parabolic_peak_shifts
parabolic_peak_shifts(x, /, axis)
Compute subpixel peak positions using parabolic interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, '*dims']
|
Input array containing peaks. |
required |
axis
|
int
|
Axis along which to compute peak shifts. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '*dims']
|
Array of fractional shifts for each position, where each shift indicates |
Float[Array, '*dims']
|
the subpixel offset from the integer position to the interpolated peak. |
Source code in src/korvax/util.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
localmin
localmin(x, /, axis)
Identify local minima in an array along the specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, '*dims']
|
Input array. |
required |
axis
|
int
|
Axis along which to find local minima. |
required |
Returns:
| Type | Description |
|---|---|
Bool[Array, '*dims']
|
Boolean array where True indicates a local minimum. |
Source code in src/korvax/util.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |