rapidity.utils module¶
Utility functions for the rapidity package.
- rapidity.utils.make_kernel(f, grid)¶
Construct a 2D convolution kernel Field from a difference kernel function.
- Parameters:
f (
callable) – A function of one variable representing K(theta - theta’).grid (
Grid1D) – The quadrature grid on which the kernel is defined.
- Returns:
A 2D Field representing K(theta, theta’) = f(theta - theta’).
- Return type:
Examples
>>> grid = Grid1D.gauss_legendre(-10, 10, 200, "theta") >>> kernel = make_kernel(lambda x: 1 / (2 * np.pi) / (1 + x**2), grid)
- rapidity.utils.plot(field, ax=None, value='real', **kwargs)¶
Plot a 1D or 2D Field using matplotlib.
- Parameters:
field (
Field) – The Field to plot.ax (
Axes) – The axes on which to plot. If None, the current axes are used.value (
str) – The type of the field to plot. Can be “real”, “imag”, or “abs”.**kwargs – Additional keyword arguments passed to plt.plot (for 1D) or plt.imshow (for 2D).
- Raises:
ValueError – If the Field is not 1D or 2D. If the value argument is not one of “real”, “imag”, or “abs”.
Examples
>>> grid = Grid1D.uniform(-10, 10, 200, "theta") >>> f = Field.from_function(lambda t: np.exp(-t**2), [grid]) >>> plot(f) >>> plt.show()
- rapidity.utils.sine_kernel(grid)¶
The sine kernel as a Field on a product grid.
\[K(x, y) = \frac{\sin(\pi(x-y))}{\pi(x-y)}\]The diagonal singularity at x = y is handled analytically via numpy.sinc, which is defined as sin(πx)/(πx) with sinc(0) = 1.
- Parameters:
grid (
Grid1D) – The quadrature grid on which the kernel is defined.- Returns:
A 2D Field representing the sine kernel on the product grid.
- Return type:
Examples
>>> grid = Grid1D.gauss_legendre(0.0, 1.0, 50, "x") >>> kernel = sine_kernel(grid) >>> det = fredholm_det(kernel)