pick-sparsifying-transform
Choose a sparsifying transform for a signal or image in a PyLops sparsity-promoting inversion (FFT/FFT2D/FFTND, DCT, DWT/DWT2D/DWTND, DTCWT, Seislet, curvelets via UDCT, Radon/FourierRadon/ChirpRadon, windowed versions with Sliding/Patch), check its optional dependencies and frame properties, compare candidates quantitatively with a best-k-term compressibility test, and wire the winner into fista/spgl1 in synthesis or analysis form. Use when the user asks "which transform should I use for sparsity", "wavelets or curvelets for my data", "make my model sparse for fista/spgl1", "compressive sensing / interpolation with PyLops".
- License 许可
- LGPL-2.1
- 最近更新
- 2026-11-02
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- pick-sparsifying-transform
- description
- Choose a sparsifying transform for a signal or image in a PyLops sparsity-promoting inversion (FFT/FFT2D/FFTND, DCT, DWT/DWT2D/DWTND, DTCWT, Seislet, curvelets via UDCT, Radon/FourierRadon/ChirpRadon, windowed versions with Sliding/Patch), check its optional dependencies and frame properties, compare candidates quantitatively with a best-k-term compressibility test, and wire the winner into fista/spgl1 in synthesis or analysis form. Use when the user asks "which transform should I use for sparsity", "wavelets or curvelets for my data", "make my model sparse for fista/spgl1", "compressive sensing / interpolation with PyLops".
02 资源文件 1
03 SKILL.md 正文
Goal: a transform chosen by evidence (not habit) for the user's signal, and
correct code that uses it in a sparsity-promoting PyLops inversion. Do not modify
the installed pylops package.
0. Check the environment
- Use the project's Python runner; check
pylops.__version__. - Optional dependencies (ask before installing):
DWT,DWT2D,DWTND→PyWavelets(pywt);UDCT(curvelets) →curvelets>=1.2;DTCWT→dtcwt(may lag behind NumPy 2);spgl1solver →spgl1;- fast
Radon2D/3D→numba(engine="numba"); - the external Curvelops package (FDCT via CurveLab) is a separate install –
only suggest it if
UDCTis not suitable.
- Check what imports:
python -c "import pywt, curvelets, spgl1"etc.
1. Understand the signal
Ask for (or load) a representative example of the model/data to be made sparse – ideally noise-free (a synthetic, a well-sampled subset, or a previous good result). Characterise it:
| Signal character | Natural candidates |
|---|---|
| sum of few sinusoids / band-limited, stationary | FFT, FFT2D, FFTND (norm="ortho"), DCT |
| smooth with localised discontinuities (1-D, images) | DWT/DWT2D/DWTND (e.g. db4, sym8, few levels) |
| piecewise constant / blocky | DWT with haar, or not a transform at all: TV (splitbregman, PyProximal) |
| images/seismic with oriented curved edges or events | curvelets UDCT, DTCWT |
| seismic events with smoothly varying slope | Seislet (needs slopes from pylops.utils.signalprocessing.slope_estimate) |
| linear/parabolic/hyperbolic seismic events | Radon2D/3D, FourierRadon2D/3D, ChirpRadon2D/3D |
| locally simple, globally complex | any of the above in windows with Patch2D/3D or Sliding1D/2D/3D (see sliding-patch-processing) |
| a learned or explicit dictionary | MatrixMult(D) with omp |
Shortlist 2–4 candidates.
2. Compare candidates
Adapt reference/compressibility_test.py: it reports, for each candidate
analysis transform T (data → coefficients):
- tight frame or not (
T.H @ T == I): decides whetherT.Hreconstructs and whether analysis-formfistaupdates are exact (true forFFT*withnorm="ortho", orthogonal wavelets,DCT,UDCT; false forSeislet, Radon); - redundancy (
T.shape[0] / T.shape[1]): cost and memory grow with it; - the best-k-term curve: SNR of the signal rebuilt from its largest k coefficients (k as a % of the number of signal samples, so redundant frames are not favoured). The best transform reaches high SNR with the fewest coefficients.
Radon-type operators map model (slowness, time) → data, so their "coefficients"
come from an inversion, not T @ x: compare them by running a short fista on
the representative signal instead of the best-k test.
Also weigh: speed of matvec/rmatvec, GPU support (see accelerate-on-gpu),
and parameters that need tuning (wavelet family/levels, curvelet scales/angles,
Radon slowness range and sampling).
3. Wire it into the inversion
Let Op be the physics/sampling operator (e.g. Restriction for interpolation)
and S the synthesis operator (coefficients → signal; for the transforms above
S = T.H, or the transform itself for Radon-type operators).
- Synthesis (
x = S p,psparse) – works for anyS:pylops.spgl1(Op, y, SOp=T, sigma=...)→(x, p, info): note thatspgl1takes the analysis transformTand internally invertsOp @ T.H, returningx = T.H p; setsigmafrom the noise level (‖noise‖₂);- or
p = pylops.fista(Op @ S, y, eps=..., niter=...)[0], thenx = S @ p.
- Analysis (
‖T x‖₁small) –pylops.fista(Op, y, SOp=T.H, eps=...)(hereSOpis the synthesis side, penalty‖SOpᴴ x‖₁) is exact only for tight frames; otherwise use PyProximal (solve-nonsmooth-problemskill, e.g.L1composed withTinPrimalDual/LinearizedADMM). - For complex transforms (
FFT*,UDCT) of real signals, takenp.realof the finalx, and usecomplexflagin dot-tests. - Dot-test
Op @ Sbefore inverting. Tuneeps/sigmawithtune-regularization.
4. Hand off
Report: the candidates tried, the compressibility table/plot and tight-frame properties, the chosen transform with its parameters and why, dependency notes, and the snippet (synthesis or analysis) used in the user's inversion.
04 同仓库更多 Skills
solve-nonsmooth-problem
Use this skill whenever the user wants to solve an inverse problem on PyLops operators with a non-smooth, constrained or non-convex term - load it before writing the objective, choosing a solver or writing optimisation code, even when a SciPy bounded solver or a hand-written FISTA/ADMM loop would also work. Covers total variation, L1/sparsity in a transform, joint sparsity across signals sharing the same components, bounds/positivity/ball/affine constraints, low-rank matrix completion (nuclear norm) and plug-and-play priors with a denoiser (median filter, BM3D), solved with PyProximal (ProximalGradient, ADMM, PrimalDual, ...), step sizes from operator norms. E.g. "add TV regularisation", "keep the model within physical bounds", "recover several signals that share their components", "fill in missing entries of a low-rank matrix", "use PyProximal". Not for purely quadratic regularisation (Tikhonov, damping, derivative smoothing), which is plain least squares - use the pylops skill solve-inverse-problem.
wrap-operator
Wrap a user's own forward model as a PyLops linear operator inside their project (not inside the PyLops library), with a verified adjoint, a dot-test and a small test suite. Use when the user wants to turn existing forward/adjoint code, a script at a URL, or a mathematical description into a PyLops operator they can pass to PyLops solvers (e.g. "make my blurring function a PyLops operator", "wrap this forward model so I can invert it with lsqr", "I have a forward and adjoint, plug them into PyLops").
tune-regularization
Choose regularisation weights and thresholds for a PyLops inversion (epsRs in regularized_inversion, damp in cgls/lsqr, eps in ista/fista, epsRL1s in splitbregman, sigma/tau in spgl1, niter as implicit regularisation) with a principled, reproducible sweep - L-curve, discrepancy principle, GCV for small problems, or a synthetic test with a known model. Use when the user asks "how do I choose epsilon / lambda / damping", "my inversion is too smooth / too noisy", "make an L-curve", or after solve-inverse-problem produced a working but untuned inversion.
solve-inverse-problem
Use this skill whenever the user has (or can build) a PyLops operator and data and wants to invert it - load it before choosing a solver or writing any inversion code, even when the right solver or regularisation seems obvious. It sets up and runs the inversion in the user's project - choose the solver (lsqr, cgls, cg, regularized_inversion, preconditioned_inversion, fista, spgl1, omp, irls, splitbregman), the regularisation and the stopping parameters, and write a runnable script that reports convergence. E.g. "invert my data with this operator", "which PyLops solver should I use", "add Tikhonov / smoothness / sparsity regularisation to my inversion", "solve y = Op x". Not for an inversion that already misbehaves (use debug-inversion) or for choosing regularisation weights with an L-curve or sweep (use tune-regularization).
sliding-patch-processing
Set up PyLops windowed operators - Sliding1D, Sliding2D, Sliding3D, Patch2D, Patch3D - to apply a local transform or operator over overlapping windows of 1-D/2-D/3-D data, choosing window size, overlap, taper and model size with the *_design and *_pad_to_next helpers, checking coverage and the dot-test, and using them for local denoising, interpolation or inversion. Use when the user asks "apply FFT/Radon/any operator in overlapping windows", "local transform / patching with PyLops", "Patch2D gives artefacts at the edges", "how do I pick nwin, nover, nop".
debug-inversion
Use this skill whenever a user shares PyLops code or results that misbehave and asks what is wrong - load it first, before running the user's code, testing a hypothesis or answering, even when the bug looks obvious from the code. Covers a crash or traceback (dtype/casting errors, shape mismatches), a solver (lsqr, cgls, cg, fista, ista, spgl1, regularized_inversion, splitbregman) that stalls, diverges, returns NaNs, zeros, ringing or a wrong model, one dataset or block being ignored in a stacked/joint inversion, or a custom FunctionOperator/LinearOperator that may have a wrong adjoint. Diagnoses with evidence (block-by-block dot-tests incl. complex, dtype and dims checks, operator/data scaling, solver and eps/damp choice), then proposes the smallest fix and verifies it. Not for choosing a solver for a new, working setup (use solve-inverse-problem) or picking regularisation weights (use tune-regularization).