Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ processing \ short_time_fourier_transform.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-10 00:11 -0800

1# ===================================================== 

2# Imports 

3# ===================================================== 

4from typing import Annotated, Union 

5 

6from pydantic import Field 

7 

8from mt_metadata.base import MetadataBase 

9from mt_metadata.common.enumerations import StrEnumerationBase 

10from mt_metadata.processing.window import Window 

11 

12 

13# ===================================================== 

14class MethodEnum(StrEnumerationBase): 

15 fft = "fft" 

16 wavelet = "wavelet" 

17 other = "other" 

18 

19 

20class PerWindowDetrendTypeEnum(StrEnumerationBase): 

21 linear = "linear" 

22 constant = "constant" 

23 null = "" 

24 

25 

26class PreFftDetrendTypeEnum(StrEnumerationBase): 

27 linear = "linear" 

28 other = "other" 

29 null = "" 

30 

31 

32class PrewhiteningTypeEnum(StrEnumerationBase): 

33 first_difference = "first difference" 

34 other = "other" 

35 

36 

37class ShortTimeFourierTransform(MetadataBase): 

38 harmonic_indices: Annotated[ 

39 Union[int, list[int], None], 

40 Field( 

41 default=None, 

42 description="List of harmonics indices kept, if all use -1", 

43 alias=None, 

44 json_schema_extra={ 

45 "units": None, 

46 "required": True, 

47 "examples": [[0, 4, 8]], 

48 }, 

49 ), 

50 ] 

51 

52 method: Annotated[ 

53 MethodEnum, 

54 Field( 

55 default=MethodEnum.fft, 

56 description="Fourier transform method", 

57 alias=None, 

58 json_schema_extra={ 

59 "units": None, 

60 "required": True, 

61 "examples": ["fft"], 

62 }, 

63 ), 

64 ] 

65 

66 min_num_stft_windows: Annotated[ 

67 int, 

68 Field( 

69 default=0, 

70 description="How many FFT windows must be available for the time series to valid for STFT.", 

71 alias=None, 

72 json_schema_extra={ 

73 "units": None, 

74 "required": True, 

75 "examples": [4], 

76 }, 

77 ), 

78 ] 

79 

80 per_window_detrend_type: Annotated[ 

81 PerWindowDetrendTypeEnum, 

82 Field( 

83 default=PerWindowDetrendTypeEnum.null, 

84 description="Additional detrending applied per window. Not available for standard scipy spectrogram -- placholder for ARMA prewhitening.", 

85 alias=None, 

86 json_schema_extra={ 

87 "units": None, 

88 "required": True, 

89 "examples": ["linear"], 

90 }, 

91 ), 

92 ] 

93 

94 pre_fft_detrend_type: Annotated[ 

95 PreFftDetrendTypeEnum, 

96 Field( 

97 default=PreFftDetrendTypeEnum.linear, 

98 description="Pre FFT detrend method to be applied", 

99 alias=None, 

100 json_schema_extra={ 

101 "units": None, 

102 "required": True, 

103 "examples": ["linear"], 

104 }, 

105 ), 

106 ] 

107 

108 prewhitening_type: Annotated[ 

109 PrewhiteningTypeEnum, 

110 Field( 

111 default=PrewhiteningTypeEnum.first_difference, 

112 description="Prewhitening method to be applied", 

113 alias=None, 

114 json_schema_extra={ 

115 "units": None, 

116 "required": True, 

117 "examples": ["first difference"], 

118 }, 

119 ), 

120 ] 

121 

122 recoloring: Annotated[ 

123 bool, 

124 Field( 

125 default=True, 

126 description="Whether the data are recolored [True] or not [False].", 

127 alias=None, 

128 json_schema_extra={ 

129 "units": None, 

130 "required": True, 

131 "examples": [True], 

132 }, 

133 ), 

134 ] 

135 

136 window: Annotated[ 

137 Window, 

138 Field( 

139 default_factory=Window, # type: ignore 

140 description="Window settings", 

141 alias=None, 

142 json_schema_extra={ 

143 "units": None, 

144 "required": False, 

145 "examples": ["Window()"], 

146 }, 

147 ), 

148 ] 

149 

150 

151# what is the point of this main function? 

152# def main(): 

153# stft = ShortTimeFourierTransform() 

154 

155 

156# if __name__ == "__main__": 

157# main()