gwsnr.numba.njit_interpolators
Module Contents
Functions
|
Find the index for cubic spline interpolation in 1D. |
|
Evaluate a cubic function at a given point using 4-point interpolation. |
|
Perform cubic spline interpolation in 4D for the given arrays and new values. |
|
Perform cubic spline interpolation in 4D for a batch of new values. |
|
|
|
|
|
|
|
- gwsnr.numba.njit_interpolators.find_index_1d_numba(x_array, x_new)[source]
Find the index for cubic spline interpolation in 1D. Returns the index and a condition for edge handling.
- Parameters:
- x_arraynp.ndarray
The array of x values for interpolation. Must be sorted in ascending order.
- x_newfloat or np.ndarray
The new x value(s) to find the index for.
- Returns:
- iint
The index in x_array such that x_array[i-1] <= x_new < x_array[i+1].
- condition_iint
An integer indicating the condition for edge handling: - 1: x_new is less than or equal to the first element of x_array. - 2: x_new is between the first and last elements of x_array. - 3: x_new is greater than or equal to the last element of x_array.
Notes
Uses binary search with clipped indices to ensure valid 4-point stencils. The condition parameter determines linear vs cubic interpolation at boundaries.
- gwsnr.numba.njit_interpolators.spline_interp_4pts_numba(x_eval, x_pts, y_pts, condition_i)[source]
Evaluate a cubic function at a given point using 4-point interpolation.
- Parameters:
- x_evalfloat
The x value at which to evaluate the cubic function.
- x_ptsnp.ndarray
The x values of the 4 points used for interpolation. Must be sorted in ascending order
- y_ptsnp.ndarray
The y values corresponding to the x_pts. Must have the same length as x_pts.
- condition_iint
An integer indicating the condition for edge handling: - 1: x_eval is less than or equal to the first element of x_pts. - 2: x_eval is between the first and last elements of x_pts. - 3: x_eval is greater than or equal to the last element of x_pts.
- Returns:
- float
The interpolated value at x_eval.
Notes
This function uses cubic Hermite interpolation for the main case (condition_i == 2). For edge cases (condition_i == 1 or 3), it uses linear interpolation between the first two or last two points, respectively. The x_pts and y_pts must be of length 4, and x_pts must be sorted in ascending order. The function assumes that the input arrays are valid and does not perform additional checks. If the input arrays are not of length 4, or if x_pts is not sorted, the behavior is undefined. The function is designed to be used with Numba’s JIT compilation for performance. It is optimized for speed and does not include error handling or input validation. The cubic Hermite interpolation is based on the tangents calculated from the y values at the four points. The tangents are computed using the differences between the y values and the x values to ensure smoothness and continuity of the interpolated curve.
- gwsnr.numba.njit_interpolators.spline_interp_4x4x4x4pts_numba(q_array, mtot_array, a1_array, a2_array, snrpartialscaled_array, q_new, mtot_new, a1_new, a2_new, int_q, int_m, int_a1, int_a2)[source]
Perform cubic spline interpolation in 4D for the given arrays and new values.
- Parameters:
- q_arraynp.ndarray
The array of q values for interpolation. Must be sorted in ascending order.
- mtot_arraynp.ndarray
The array of mtot values for interpolation. Must be sorted in ascending order.
- a1_arraynp.ndarray
The array of a1 values for interpolation. Must be sorted in ascending order.
- a2_arraynp.ndarray
The array of a2 values for interpolation. Must be sorted in ascending order.
- snrpartialscaled_arraynp.ndarray
The 4D array of snrpartialscaled values with shape (4, 4, 4, 4). This array contains the values to be interpolated.
- q_newfloat
The new q value at which to evaluate the cubic spline.
- mtot_newfloat
The new mtot value at which to evaluate the cubic spline.
- a1_newfloat
The new a1 value at which to evaluate the cubic spline.
- a2_newfloat
The new a2 value at which to evaluate the cubic spline.
- int_qint
edge condition for q interpolation. Refer to find_index_1d_numba for details.
- int_mint
edge condition for mtot interpolation. Refer to find_index_1d_numba for details.
- int_a1int
edge condition for a1 interpolation. Refer to find_index_1d_numba for details.
- int_a2int
edge condition for a2 interpolation. Refer to find_index_1d_numba for details.
- Returns:
- float
The interpolated value at the new coordinates (q_new, mtot_new, a1_new, a2_new).
Notes
This function uses cubic Hermite interpolation for the main case (int_q == 2, int_m == 2, int_a1 == 2, int_a2 == 2). For edge cases (int_q == 1 or 3, int_m == 1 or 3, int_a1 == 1 or 3, int_a2 == 1 or 3), it uses linear interpolation between the first two or last two points, respectively.
- gwsnr.numba.njit_interpolators.spline_interp_4x4x4x4pts_batched_numba(q_array, mtot_array, a1_array, a2_array, snrpartialscaled_array, q_new_batch, mtot_new_batch, a1_new_batch, a2_new_batch)[source]
Perform cubic spline interpolation in 4D for a batch of new values.
- Parameters:
- q_arraynp.ndarray
The array of q values for interpolation. Must be sorted in ascending order.
- mtot_arraynp.ndarray
The array of mtot values for interpolation. Must be sorted in ascending order.
- a1_arraynp.ndarray
The array of a1 values for interpolation. Must be sorted in ascending order.
- a2_arraynp.ndarray
The array of a2 values for interpolation. Must be sorted in ascending order.
- snrpartialscaled_arraynp.ndarray
The 4D array of snrpartialscaled values.
- q_new_batchnp.ndarray
The new q values at which to evaluate the cubic spline. Must be a 1D array.
- mtot_new_batchnp.ndarray
The new mtot values at which to evaluate the cubic spline. Must be a 1 The new a1 values at which to evaluate the cubic spline. Must be a 1D array.
- a1_new_batchnp.ndarray
The new a1 values at which to evaluate the cubic spline. Must be a 1D array.
- a2_new_batchnp.ndarray
The new a2 values at which to evaluate the cubic spline. Must be a 1D array.
- Returns:
- np.ndarray
A 1D array of interpolated values at the new coordinates (q_new_batch, mtot_new_batch, a1_new_batch, a2_new_batch).
- gwsnr.numba.njit_interpolators.get_interpolated_snr_aligned_spins_numba(mass_1, mass_2, luminosity_distance, theta_jn, psi, geocent_time, ra, dec, a_1, a_2, detector_tensor, snr_partialscaled, ratio_arr, mtot_arr, a1_arr, a_2_arr, batch_size=100000)[source]
- gwsnr.numba.njit_interpolators.spline_interp_4x4pts_numba(q_array, mtot_array, snrpartialscaled_array, q_new, mtot_new, int_q, int_m)[source]