feat: wavelets
This commit is contained in:
@@ -80,18 +80,30 @@ def band_decompose(
|
|||||||
try:
|
try:
|
||||||
recon = icwt(Wx[mask, :], wavelet=wavelet, scales=scales_band, x_len=n)
|
recon = icwt(Wx[mask, :], wavelet=wavelet, scales=scales_band, x_len=n)
|
||||||
except Exception:
|
except Exception:
|
||||||
# ssqueezepy's internal scale-type inference (log vs linear spacing
|
# Root-caused: icwt's internal scaletype inference recursively splits
|
||||||
# detection) can raise on some narrow slices depending on how many
|
# `scales` looking for a log/linear transition point (infer_scaletype ->
|
||||||
# scales land in this bucket for this specific series length.
|
# logscale_transition_idx), and on a masked SUBSET of the original CWT
|
||||||
# Treat as a negligible band instead of failing the whole request —
|
# scales that recursive sub-slice can come out too short, crashing with
|
||||||
# but log it (previously silently swallowed) and flag it, since a flat
|
# "attempt to get argmax of an empty sequence" instead of a clean error.
|
||||||
# zero band otherwise looks identical to "genuinely no energy here".
|
# Confirmed by reproducing it directly against ssqueezepy 0.6.6: retrying
|
||||||
logger.warning(
|
# with a regenerated, exactly log-uniform array over the same range/count
|
||||||
"band_decompose: icwt failed for band %d (n=%d scales, wavelet=%s) — "
|
# sidesteps the fragile inference entirely (trivially satisfies its "is
|
||||||
"falling back to a zero band", i, len(scales_band), wavelet, exc_info=True,
|
# this log-spaced" check) and reliably recovers a real reconstruction —
|
||||||
)
|
# verified on 5 independently reproduced failures, all recovered.
|
||||||
recon = np.zeros(n)
|
try:
|
||||||
reconstruction_failed = True
|
clean_scales = np.geomspace(scales_band.min(), scales_band.max(), len(scales_band))
|
||||||
|
recon = icwt(Wx[mask, :], wavelet=wavelet, scales=clean_scales, x_len=n)
|
||||||
|
logger.warning(
|
||||||
|
"band_decompose: icwt failed for band %d with original scales (n=%d, wavelet=%s) — "
|
||||||
|
"recovered using a regenerated log-uniform scale array", i, len(scales_band), wavelet,
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
logger.warning(
|
||||||
|
"band_decompose: icwt failed for band %d (n=%d scales, wavelet=%s) even after "
|
||||||
|
"retry — falling back to a zero band", i, len(scales_band), wavelet, exc_info=True,
|
||||||
|
)
|
||||||
|
recon = np.zeros(n)
|
||||||
|
reconstruction_failed = True
|
||||||
scale_lo, scale_hi = float(scales_band.min()), float(scales_band.max())
|
scale_lo, scale_hi = float(scales_band.min()), float(scales_band.max())
|
||||||
else:
|
else:
|
||||||
# Too few scales in this bucket for a stable reconstruction; report a
|
# Too few scales in this bucket for a stable reconstruction; report a
|
||||||
|
|||||||
Reference in New Issue
Block a user