AGENT SKILL

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".

License 许可
LGPL-2.1
最近更新
2026-11-02
Stars
★ 1
Forks
0

01 前言 Front Matter

name
sliding-patch-processing
description
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".

02 资源文件 1

03 SKILL.md 正文

Goal: a correctly tiled windowed operator for the user's data and local transform, proven by a coverage check and a dot-test, used in the processing they need (usually a sparsity-promoting inversion). Do not modify the installed pylops package.

0. Check the environment

Use the project's Python runner; check pylops.__version__ and inspect the installed signatures (help(pylops.signalprocessing.Patch2D), help(pylops.signalprocessing.patch2d_design)) – the design helpers and *_pad_to_next are recent additions (PyLops ≥ 2.x).

1. Choose the operator

Data Windows along Operator Local operator acts on
1-D signal axis 0 Sliding1D(Op, dim, dimd, nwin, nover) nwin samples
2-D, window one axis only (e.g. space, full time) axis 0 Sliding2D(Op, dims, dimsd, nwin, nover) (nwin, dimsd[1])
3-D, window two axes, full third axes 0, 1 Sliding3D(Op, dims, dimsd, nwin, nover, nop) (nwin[0], nwin[1], dimsd[2])
2-D, window both axes axes 0, 1 Patch2D(Op, dims, dimsd, nwin, nover, nop) nwin (2-tuple)
3-D, window all axes axes 0, 1, 2 Patch3D(...) nwin (3-tuple)

All live in pylops.signalprocessing. Common arguments: tapertype ("hanning" default, "cosine", "cosinesquare", None), savetaper (True = faster, False = less memory), Patch* also scalings (one factor per window).

2. Define the local operator

The key convention: Op maps one window of model coefficients to one window of data, i.e. Op.shape == (prod(window data shape), prod(nop)). For a transform T that maps data → coefficients (FFT, Radon adjoint, wavelets), pass its synthesis side, typically T.H (e.g. FFT2D(nwin, nffts=nop).H, or Radon2D(t, hwin, px) which already maps (px, t) → (h, t)). For local coordinates (e.g. Radon offsets), centre the window axis (np.linspace(-dx*nwin//2, dx*nwin//2, nwin) with centeredh=True).

3. Design the windows

  • nwin: long enough to contain the local structure (a few wavelengths/events), short enough that events are locally linear/sparse.
  • nover: typically 20–50 % of nwin; needed for smooth tapering.
  • nop: the model size per window in the transform domain (e.g. number of slopes, FFT sizes ≥ nwin).
  • Call nwins, dims, mwins_inends, dwins_inends = patch2d_design(dimsd, nwin, nover, nop) (sliding1d_design, sliding2d_design, sliding3d_design, patch3d_design similarly) and use the returned dims for the operator.
  • Windows may not reach the end of the data. Check dwins_inends (last end must equal dimsd along each windowed axis), or pad with inpt_pad, nwins, dims, mwins_inends, dwins_inends = patch2d_pad_to_next(inpt, nwin, nover, nop) (sliding2d_pad_to_next, sliding3d_pad_to_next, patch3d_pad_to_next likewise; for Sliding1D pad manually) and crop at the end.

4. Verify

Adapt reference/sliding_template.py:

  1. Tiling check (check_tiling): with an identity local operator, Ptaper @ Pnotaper.H @ ones == ones everywhere. Any deviation means uncovered samples or tapers that do not sum to one.
  2. Dot-test of the full windowed operator (complexflag=2 when the local operator is complex in model and real in data, e.g. FFT synthesis).
  3. For transforms, apply P.H to data and P back with an untapered adjoint and a tapered forward to see the reconstruction quality before inverting.

5. Use it

  • Denoising / sparse representation: pylops.fista(P, y, eps=..., niter=...) or pylops.spgl1(P, y, sigma=...) for the window coefficients, then P @ coeffs.
  • Interpolation: Op = Restriction @ P (or R @ P), invert for coefficients, apply P for the full data.
  • Adaptive subtraction / local filtering: local MatrixMult/Convolve1D per window via Sliding*.
  • Tune eps / niter with tune-regularization; pick the transform with pick-sparsifying-transform.
  • CPU/CuPy only (not JAX); cost grows with the number of windows and overlap.

6. Hand off

Report: chosen operator and window parameters (with nwins), the tiling-check and dot-test results, padding applied (if any), and the processing result (plots, SNR if a reference is available).

04 同仓库更多 Skills

PyLops
PyLops/pylops-agent-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.

★ 1
PyLops
PyLops/pylops-agent-skills

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").

★ 1
PyLops
PyLops/pylops-agent-skills

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.

★ 1
PyLops
PyLops/pylops-agent-skills

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).

★ 1
PyLops
PyLops/pylops-agent-skills

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".

★ 1
PyLops
PyLops/pylops-agent-skills

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).

★ 1