lisa_noise.spline ================= .. py:module:: lisa_noise.spline Functions --------- .. autoapisummary:: lisa_noise.spline.knots lisa_noise.spline.eval_spline_from_basis lisa_noise.spline.spline_basis lisa_noise.spline.spline lisa_noise.spline.spline_plus_inverse_lorentzian Module Contents --------------- .. py:function:: knots(minimum, maximum, n_knots, ghost_knots=None, log_knots=True, ghost_minimum=None, ghost_maximum=None) Add functionality to return equally spaced knots in either log or linear spaces. By default, n_knots are placed between the specified minimum and maximum values, ghost_knots/2 are placed between ghost_minimum and minimum, and ghost_knots/2 are placed between maximum and ghost_maximum. :param minimum: minimum value to start real knot placement :type minimum: float :param maximum: maximum value to end real knot placement :type maximum: float :param n_knots: number of knots to use for the real knot placement :type n_knots: int :param ghost_knots: number of ghost knots to place :type ghost_knots: int, optional :param ghost_minimum: minimum value to start the ghost knot placement. If None, minimum / 10 is used. Default None :type ghost_minimum: float, optional :param ghost_maximum: maximum value to start the ghost knot placement. If None, maximum * 10 is used. Default None :type ghost_maximum: float, optional :param log_knots: if True, space the knots evenly in log space :type log_knots: Bool, optional .. py:function:: eval_spline_from_basis(B_free, b_ghost, params) Evaluate a spline at pre-computed frequencies via the design matrix. Equivalent to calling the spline directly with the full knot values but performs only a matmul — no scipy calls. Intended for use inside MCMC hot loops with any array backend. :param B_free: Basis columns for the free (non-ghost) knots, from :func:`spline_basis`. :type B_free: (N_eval, N_free) array :param b_ghost: Pre-computed contribution of the fixed ghost knots. :type b_ghost: (N_eval,) array :param params: Current knot values (e.g. log10 PSD at the free knots). :type params: (N_free,) array :returns: Spline values at the evaluation frequencies. :rtype: (N_eval,) array .. py:function:: spline_basis(knot_x, eval_x, log=True) Build a cubic spline design matrix. Converts spline evaluation into a pure matrix-vector multiply with no scipy calls at evaluation time: y(eval_x) ≈ B @ y_knots :param knot_x: Knot positions. :type knot_x: (N_knots,) array :param eval_x: Positions at which to evaluate the spline. :type eval_x: (N_eval,) array :param log: If True, work in log10 space (both axes). Recommended for quantities spanning many decades such as PSDs. Default True. :type log: bool, optional :returns: **B** -- Design matrix. ``B @ y_knots`` gives spline values at ``eval_x``. :rtype: (N_eval, N_knots) ndarray .. py:function:: spline(frequency_array, data, knots, bounds=None, kind='cubic', **kwargs) Evaluate a spline that fits the provided data. By default a cubic spline is used. :param frequency_array: array of frequencies to evaluate the spline :type frequency_array: np.ndarray :param data: data to interpolate :type data: np.ndarray :param knots: knot locations for the spline :type knots: np.ndarray :param bounds: frequency bounds to evaluate the interpolant. Default None :type bounds: np.ndarray, optional :param kind: spline type to use. Must be an option for the `scipy.interpolate.interp1d` function. Default 'cubic' :type kind: str, optional :param kwargs: all kwargs passed to the `scipy.interpolate.interp1d` function :type kwargs: dict, optional .. py:function:: spline_plus_inverse_lorentzian(frequency_array, data, knots, n_lorentz, kind='cubic', min_val=1e-16, smoothing_window=5, smoothing_poly=2, alpha=0.7, log=True) Evaluate a spline plus a series of inverse lorentzians that fits the provided data. By default a cubic spline is used. :param frequency_array: array of frequencies to evaluate the spline :type frequency_array: np.ndarray :param data: data to interpolate :type data: np.ndarray :param knots: knot locations for the spline :type knots: np.ndarray :param n_lorentz: number of lorentzians to include in the fit :type n_lorentz: int :param kind: spline type to use. Must be an option for the `scipy.interpolate.interp1d` function. Default 'cubic' :type kind: str, optional :param min_val: minimum value for the inverse lorentzian. Default 1e-16 :type min_val: float, optional :param smoothing_window: The length of the filter window used to smooth the final PSD. Default 5 :type smoothing_window: int, optional :param smoothing_poly: The order of the polynomial used to smooth the final PSD. Default 2 :type smoothing_poly: int, optional :param alpha: The smoothing used in a sine-squared taper when connecting the lorentzians to the base spline :type alpha: float, optional :param log: If True, return the log of the spline plus lorentzian :type log: bool, optional