Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ features \ weights \ taper_weight_kernel.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
1"""
2Module with a compound kernel, mixing multiple monotonic kernels.
3"""
5from typing import Annotated, Tuple
7import numpy as np
8from pydantic import computed_field, Field
10from mt_metadata.features.weights.taper_monotonic_weight_kernel import (
11 TaperMonotonicWeightKernel,
12)
13from mt_metadata.processing.window import TypeEnum
15from .base import Base
18class TaperWeightKernel(Base):
19 """
20 A composite weight kernel that multiplies a low-cut and a high-cut monotonic taper kernel.
22 Parameters
23 ----------
24 low_cut : tuple[float, float]
25 (lower_bound, upper_bound) for the low-cut transition region.
26 high_cut : tuple[float, float]
27 (lower_bound, upper_bound) for the high-cut transition region.
28 style : str, optional
29 The taper style to use (default is 'hann').
30 **kwargs
31 Additional keyword arguments passed to BaseWeightKernel.
32 """
34 low_cut: Annotated[
35 Tuple[float, float],
36 Field(
37 description="Low cut transition bounds",
38 json_schema_extra={
39 "units": None,
40 "required": True,
41 "examples": [[0.1, 0.5]],
42 },
43 ),
44 ]
45 high_cut: Annotated[
46 Tuple[float, float],
47 Field(
48 description="High cut transition bounds",
49 json_schema_extra={
50 "units": None,
51 "required": True,
52 "examples": [[0.5, 1.0]],
53 },
54 ),
55 ]
57 style: Annotated[
58 TypeEnum,
59 Field(
60 description="Taper style",
61 json_schema_extra={
62 "units": None,
63 "required": True,
64 "examples": ["hann", "hamming", "blackman"],
65 },
66 ),
67 ]
69 @computed_field
70 @property
71 def low_kernel(self) -> TaperMonotonicWeightKernel:
72 """The low-cut taper kernel."""
73 return TaperMonotonicWeightKernel( # type: ignore
74 threshold="low cut",
75 transition_lower_bound=self.low_cut[0],
76 transition_upper_bound=self.low_cut[1],
77 half_window_style=self.style,
78 )
80 @computed_field
81 @property
82 def high_kernel(self) -> TaperMonotonicWeightKernel:
83 """The high-cut taper kernel."""
84 return TaperMonotonicWeightKernel( # type: ignore
85 threshold="high cut",
86 transition_lower_bound=self.high_cut[0],
87 transition_upper_bound=self.high_cut[1],
88 half_window_style=self.style,
89 )
91 def evaluate(self, values: np.ndarray) -> np.ndarray:
92 """
93 Evaluate the composite taper weight kernel on the input values.
95 Parameters
96 ----------
97 values : np.ndarray
98 Input values to evaluate the kernel on.
100 Returns
101 -------
102 np.ndarray
103 The product of the low-cut and high-cut kernel evaluations.
104 """
105 return self.low_kernel.evaluate(values) * self.high_kernel.evaluate(values)