Wavelet Analysis¶
Continuous wavelet transforms in 1-D (Torrence–Compo with Liu-rectified power) and 2-D (Morlet), plus scalograms, the cone of influence, dominant- period maps, and significance testing. The CWT of a signal \(x(t)\) at scale \(s\) and translation \(\tau\) is
Operators¶
WaveletPowerSpectrum
¶
WaveletPowerSpectrum(variable: str, scales: Sequence[float] | DataArray, *, dim: tuple[str, str] = ('y', 'x'), x0: float = 50000.0, ntheta: int = 16, k0: float = 1.0, isotropic: bool = True, output_var: str | None = None)
Bases: Operator
2-D Morlet wavelet power spectrum of one variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the variable to transform. |
required |
scales
|
Sequence[float] | DataArray
|
Wavelet scales (a sequence or DataArray). |
required |
dim
|
tuple[str, str]
|
The two spatial dims |
('y', 'x')
|
x0
|
float
|
Reference length scale (m). |
50000.0
|
ntheta
|
int
|
Number of orientation angles. |
16
|
k0
|
float
|
Morlet central wavenumber. |
1.0
|
isotropic
|
bool
|
Average over orientation when |
True
|
output_var
|
str | None
|
Name for the output variable (default
|
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with the wavelet power-spectrum variable added. |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/operators.py
WaveletScalogram
¶
WaveletScalogram(variable: str, *, dim: str = 'time', mother: str = 'morlet', param: float | None = None, s0: float | None = None, dj: float = 0.25, j_max: int | None = None, rectify: bool = True, output_prefix: str | None = None)
Bases: Operator
Compute a 1-D wavelet scalogram for one variable.
Adds six derived variables under a common prefix:
<prefix>_wave, <prefix>_power, <prefix>_power_rect,
<prefix>_scalogram, <prefix>_coi, <prefix>_coi_mask.
The prefix defaults to variable and is overridable via
output_prefix.
Source code in packages/xrtoolz-ops/src/xrops/wavelets/operators.py
WaveletSignificance
¶
WaveletSignificance(variable: str, *, dim_time: str = 'time', dim_scale: str = 'scale', null: Literal['red', 'white'] = 'red', alpha: float | None = None, confidence: float = 0.95, mother: str = 'morlet', param: float | None = None, output_var: str | None = None)
Bases: Operator
Torrence-Compo significance mask for a wavelet-power variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the wavelet-power variable to test. |
required |
dim_time
|
str
|
Time dimension name. |
'time'
|
dim_scale
|
str
|
Scale dimension name. |
'scale'
|
null
|
Literal['red', 'white']
|
Null spectrum — |
'red'
|
alpha
|
float | None
|
Lag-1 autocorrelation; |
None
|
confidence
|
float
|
Chi-square confidence level. |
0.95
|
mother
|
str
|
Mother wavelet name. |
'morlet'
|
param
|
float | None
|
Optional mother parameter. |
None
|
output_var
|
str | None
|
Name for the mask variable (default
|
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a boolean significance-mask variable added. |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/operators.py
BandpassWavelength
¶
BandpassWavelength(*, dim: str, lambda_min_km: float | None = None, lambda_max_km: float | None = None, spacing_km: float | None = None, method: str = 'lanczos', num_taps: int | None = None, attenuation_db: float | None = None, lon: str = 'lon', lat: str = 'lat')
Bases: Operator
Band-pass a field by wavelength with a windowed-sinc FIR filter.
Keeps along-dim structure with wavelengths between lambda_min_km
and lambda_max_km. When spacing_km is omitted it is derived from
the lon/lat ride-along coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim
|
str
|
Dimension to filter along (e.g. an along-track index). |
required |
lambda_min_km
|
float | None
|
Shortest wavelength to keep (km); |
None
|
lambda_max_km
|
float | None
|
Longest wavelength to keep (km); |
None
|
spacing_km
|
float | None
|
Sample spacing (km); |
None
|
method
|
str
|
FIR window — |
'lanczos'
|
num_taps
|
int | None
|
Filter length; |
None
|
attenuation_db
|
float | None
|
Stop-band attenuation for the Kaiser window. |
None
|
lon
|
str
|
Longitude coordinate name (used when |
'lon'
|
lat
|
str
|
Latitude coordinate name (used when |
'lat'
|
Returns:
| Type | Description |
|---|---|
|
The band-pass-filtered dataset (each numeric variable along |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/operators.py
Functional primitives (Layer 0)¶
These pure functions back the operators above; each takes xr.DataArray/xr.Dataset and a dim: argument.
cwt1d
¶
cwt1d(da: DataArray, *, dim: str = 'time', mother: str = 'morlet', param: float | None = None, s0: float | None = None, dj: float = 0.25, j_max: int | None = None, pad: bool = True) -> Dataset
Compute a 1-D continuous wavelet transform along one dimension.
The implementation follows Torrence and Compo (1998): zero-pad to the
next power of two, multiply the FFT of the signal by the analytic Fourier
transform of the selected mother wavelet, and strip the padding after the
inverse FFT. The returned power_rect variable is Liu et al. (2007)
rectified power, |W|² / scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
Input time series or array with one transform dimension. |
required |
dim
|
str
|
Dimension to transform. |
'time'
|
mother
|
str
|
Mother wavelet: |
'morlet'
|
param
|
float | None
|
Mother parameter. Defaults are Morlet |
None
|
s0
|
float | None
|
Smallest scale. Defaults to |
None
|
dj
|
float
|
Scale spacing in octaves. |
0.25
|
j_max
|
int | None
|
Largest scale index. Defaults to |
None
|
pad
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with |
Dataset
|
|
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet1d.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 65 66 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 119 120 121 122 123 | |
icwt1d
¶
icwt1d(wave: DataArray, *, band: tuple[float, float] | None = None, mother: str = 'morlet', param: float | None = None, dj: float | None = None, dt: float | None = None) -> DataArray
Reconstruct a signal from 1-D CWT coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
DataArray
|
Complex coefficients from :func: |
required |
band
|
tuple[float, float] | None
|
Optional |
None
|
mother
|
str
|
Mother wavelet name. |
'morlet'
|
param
|
float | None
|
Optional mother parameter. Reconstruction constants are available for the Torrence-Compo defaults. |
None
|
dj
|
float | None
|
Scale spacing used by :func: |
None
|
dt
|
float | None
|
Sample spacing. Defaults to the coefficient |
None
|
Returns:
| Type | Description |
|---|---|
DataArray
|
Reconstructed DataArray without the scale dimension. |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet1d.py
cwt2
¶
cwt2(da: DataArray, s: DataArray, dim: tuple[str, str] = ('y', 'x'), *, x0: float = 50000.0, ntheta: int = 16, k0: float = 1.0, a: float = 1.0) -> DataArray
Compute a 2-D directional Morlet CWT on a Cartesian grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
Two-dimensional field. |
required |
s
|
DataArray
|
One-dimensional positive scale coordinate. |
required |
dim
|
tuple[str, str]
|
Spatial dimensions as |
('y', 'x')
|
x0
|
float
|
Reference length scale in the same units as |
50000.0
|
ntheta
|
int
|
Number of evenly spaced angles in |
16
|
k0
|
float
|
Dimensionless Morlet central wavenumber. |
1.0
|
a
|
float
|
Fourier-domain amplitude multiplier. |
1.0
|
Returns:
| Type | Description |
|---|---|
DataArray
|
Complex coefficients with dims |
DataArray
|
boolean |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet.py
morlet2_ft
¶
morlet2_ft(kx: Float[ndarray, 'y x'], ky: Float[ndarray, 'y x'], s: float, theta: float, *, x0: float, k0: float = 1.0, a: float = 1.0) -> Complex[ndarray, 'y x']
Analytic Fourier transform of a rotated 2-D Morlet wavelet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kx
|
Float[ndarray, 'y x']
|
Zonal wavenumber grid in cycles per coordinate unit. |
required |
ky
|
Float[ndarray, 'y x']
|
Meridional wavenumber grid in cycles per coordinate unit. |
required |
s
|
float
|
Positive dimensionless scale. |
required |
theta
|
float
|
Wavelet orientation in radians. |
required |
x0
|
float
|
Reference length scale in coordinate units. |
required |
k0
|
float
|
Dimensionless central wavenumber. |
1.0
|
a
|
float
|
Amplitude multiplier. |
1.0
|
Returns:
| Type | Description |
|---|---|
Complex[ndarray, 'y x']
|
Complex Fourier-domain wavelet sampled on |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet.py
build_coi_mask
¶
build_coi_mask(da: DataArray, scales: DataArray, *, dim: tuple[str, str] = ('y', 'x'), x0: float) -> DataArray
Build a cone-of-influence mask for boundaries and NaN land cells.
A sample is trustworthy when its distance to the nearest boundary or
invalid cell exceeds scale * x0 in coordinate units.
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet_utils.py
dominant_period_map
¶
dominant_period_map(power_rect: DataArray, *, dim_time: str = 'time', dim_scale: str = 'scale', coi_mask: DataArray | None = None, signif_mask: DataArray | None = None, reduce: DominantReduce = 'argmax') -> DataArray
Return the dominant Fourier period after time-averaging rectified power.
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet1d.py
wvlt_power_spectrum
¶
wvlt_power_spectrum(da: DataArray, s: DataArray, *, dim: tuple[str, str] = ('y', 'x'), x0: float = 50000.0, ntheta: int = 16, k0: float = 1.0, isotropic: bool = True) -> DataArray
Return the 2-D Morlet wavelet power spectrum of da.
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet.py
wvlt_cross_spectrum
¶
wvlt_cross_spectrum(da1: DataArray, da2: DataArray, s: DataArray, *, dim: tuple[str, str] = ('y', 'x'), x0: float = 50000.0, ntheta: int = 16, k0: float = 1.0, isotropic: bool = True) -> DataArray
Return the complex 2-D Morlet cross-spectrum of two fields.
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet.py
wavelet_significance
¶
wavelet_significance(power: DataArray, *, dim_time: str = 'time', dim_scale: str = 'scale', null: NullModel = 'red', alpha: float | None = None, confidence: float = 0.95, mother: str = 'morlet', param: float | None = None) -> DataArray
Return a mask where wavelet power exceeds a red/white-noise threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
power
|
DataArray
|
Wavelet power with scale and time dimensions. |
required |
dim_time
|
str
|
Time dimension name. |
'time'
|
dim_scale
|
str
|
Scale dimension name. |
'scale'
|
null
|
NullModel
|
Null spectrum, either AR(1) red noise or white noise. |
'red'
|
alpha
|
float | None
|
Lag-1 autocorrelation. When omitted, the value saved by
:func: |
None
|
confidence
|
float
|
Chi-square confidence level. |
0.95
|
mother
|
str
|
Mother wavelet name, used for the scale-period mapping if no
|
'morlet'
|
param
|
float | None
|
Optional mother parameter. |
None
|
Returns:
| Type | Description |
|---|---|
DataArray
|
Boolean DataArray with the same dimensions as |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/wavelet1d.py
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 159 160 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 | |
bandpass_wavelength
¶
bandpass_wavelength(da: DataArray, *, dim: str, lambda_min_km: float | None = None, lambda_max_km: float | None = None, spacing_km: float | None = None, method: str = 'lanczos', num_taps: int | None = None, attenuation_db: float | None = None, lon: DataArray | None = None, lat: DataArray | None = None) -> DataArray
Filter an along-track DataArray using wavelength cutoffs in kilometres.
Per the PR γ primitive-flip (docs/design/xarray-native-primitives.md),
this Layer-0 primitive operates on a single DataArray. The
Layer-1 BandpassWavelength operator handles Dataset selection
(including per-variable iteration and string lon/lat name
lookup) and forwards the resulting DataArrays here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
Input DataArray. Must carry |
required |
dim
|
str
|
Along-track dimension to filter. |
required |
lambda_min_km
|
float | None
|
Short-wavelength edge in kilometres. With
|
None
|
lambda_max_km
|
float | None
|
Long-wavelength edge in kilometres. With
|
None
|
spacing_km
|
float | None
|
Optional along-track sample spacing. If omitted, it is
derived as the median WGS-84 spacing from |
None
|
method
|
str
|
FIR window family, |
'lanczos'
|
num_taps
|
int | None
|
Optional odd FIR tap count. |
None
|
attenuation_db
|
float | None
|
Kaiser attenuation target in decibels. |
None
|
lon
|
DataArray | None
|
1-D longitude DataArray along |
None
|
lat
|
DataArray | None
|
1-D latitude DataArray along |
None
|
Returns:
| Type | Description |
|---|---|
DataArray
|
DataArray filtered along |
Source code in packages/xrtoolz-ops/src/xrops/wavelets/_src/along_track.py
66 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 119 120 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 159 160 161 162 163 164 165 166 | |