Fourier
coef_conversion(amp_coef=None, phase_coef=None, cos_coef=None, sin_coef=None, pos_amp=False, neg_amp=False, take_cos_sign=False)
The term for the \(n^{th}\) harmonic of a Fourier expansion can be written in two ways:
- \(F_n\cos(2n\pi ft - \Phi_n)\)
- \(F_{n, cos}\cos(2n\pi ft) + F_{n, sin}\sin(2n\pi ft)\)
Given the coefficients of one form, this returns the coefficients in the other form. Note \(\sin(x) = \cos(x - \pi /2)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amp_coef
|
Optional[Union[float, ndarray, DataArray]]
|
|
None
|
phase_coef
|
Optional[Union[float, ndarray, DataArray]]
|
|
None
|
cos_coef
|
Optional[Union[float, ndarray, DataArray]]
|
|
None
|
sin_coef
|
Optional[Union[float, ndarray, DataArray]]
|
|
None
|
pos_amp
|
bool
|
If pos_amp=True: amp_coef >= 0, phase in (\([-\pi, \pi]\) (via atan2). If pos_amp=False: allow signed amp_coef and shift phase by +/-pi so that phase is constrained to \([-\pi/2, \pi/2]\) (minimize |phase|). |
False
|
neg_amp
|
bool
|
Force amplitude to be negative. |
False
|
take_cos_sign
|
bool
|
Will make amp_coef take sign of provided cos_coef. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
coef1 |
Union[float, ndarray, DataArray]
|
|
coef2 |
Union[float, ndarray, DataArray]
|
|
Source code in isca_tools/utils/fourier.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
fourier_series(time, coefs_amp, coefs_phase, pad_coefs_phase=False)
For \(N\) harmonics, the fourier series with frequency \(f\) is:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
ndarray
|
|
required |
coefs_amp
|
Union[List[float], ndarray]
|
|
required |
coefs_phase
|
Union[List[float], ndarray]
|
|
required |
pad_coefs_phase
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in isca_tools/utils/fourier.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
fourier_series_deriv(time, coefs_amp, coefs_phase, day_seconds=86400)
For \(N\) harmonics, the derivative of a fourier series with frequency \(f\) is:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
ndarray
|
|
required |
coefs_amp
|
Union[ndarray, List[float]]
|
|
required |
coefs_phase
|
Union[ndarray, List[float]]
|
|
required |
day_seconds
|
float
|
Duration of a day in seconds. |
86400
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Source code in isca_tools/utils/fourier.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
get_fourier_coef(time, var, n, integ_method='spline', pos_amp=False)
This calculates the analytic solution for the amplitude and phase coefficients for the nth harmonic
🔗
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
ndarray
|
|
required |
var
|
ndarray
|
|
required |
n
|
int
|
Harmonic to find coefficients for, if 0, will just return amplitude coefficient. Otherwise, will return an amplitude and phase coefficient. |
required |
integ_method
|
str
|
How to perform the integration.
If |
'spline'
|
pos_amp
|
bool
|
If |
False
|
Returns:
amp_coef: The amplitude fourier coefficient \(F_n\).
phase_coef: The phase fourier coefficient \(\Phi_n\). Will not return if \(n=0\).
Source code in isca_tools/utils/fourier.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_fourier_fit(time, var, n_harmonics, integ_method='spline', pad_coefs_phase=False)
Obtains the Fourier series solution for \(F=\)var, using \(N=\)n_harmonics:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
ndarray
|
|
required |
var
|
ndarray
|
|
required |
n_harmonics
|
int
|
Number of harmonics to use to fit fourier series, \(N\). |
required |
integ_method
|
str
|
How to perform the integration when obtaining Fourier coefficients.
If |
'spline'
|
pad_coefs_phase
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
|
ndarray
|
|
Source code in isca_tools/utils/fourier.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |