Skip to main content

Frequency Continuation

Multi-scale FWI with FWIObjective

Frequency continuation inverts data in stages, starting from low frequencies and progressively including higher frequencies. This mitigates cycle-skipping and produces more robust velocity models.

The FWIObjective class handles continuation automatically when the param dictionary contains a continuation key.

Minimal example

from devitohorizon.inversion.fwi import FWIObjective

param = {
    "model": "models/init.zarr",
    "data_path": "data/shots.segy",
    "nbl": 40,
    "space_order": 12,
    "tn": 2.0,
    "wavelet": {"type": "ricker", "f0": 0.020},
    "bounds": {"vp": (1.4, 5.0)},
    "continuation": {
        "fmax": [5.0, 10.0, 15.0, 20.0],
        "iters": [4, 5, 6, 8],
    },
    "optimizer": {"method": "SPG"},
}

objective = FWIObjective(param=param)
model, fval, result = objective.run()

The continuation["fmax"] list defines one band per entry. A bandpass filter is applied to the data automatically for each band, and the optimized model from one band seeds the next.

Continuation configuration

The continuation dict supports the following keys:

Key Type Default Description
fmax list of float required Upper frequency bound per band (Hz)
fmin float or list 0.0 (lowpass) Lower frequency bound per band (Hz)
iters int or list from optimizer Iterations per band
ppw float None Points per wavelength for automatic grid coarsening
band_spacings list None Explicit grid spacing per band (alternative to ppw)
model_smoothing bool, str or callable True Between-band model smoother: True/False to enable/disable the default Gaussian, a registered smoother name, or a callable
smoothing_factor float 0.25 Controls default-smoother strength (0=none, 1=aggressive)
smoothing_params dict None Extra keyword arguments forwarded to the smoother
sweeps int 1 Repeat the entire frequency schedule N times
batch_size int or list from param Shots per iteration, per band
shot_fraction float or list None Fraction of shots per iteration, per band
preprocess list of dict None Per-band preprocessing overrides

Frequency bounds

By default fmin is 0, meaning each band acts as a lowpass filter. You can set it globally (scalar) or per-band (list) to use a bandpass instead:

"continuation": {
    "fmax": [5.0, 10.0, 15.0],
    "fmin": [0.5, 1.0, 1.0],    # per-band lower bounds
}

If a global fmin is set in param (outside the continuation dict), it is used as a fallback when no per-band fmin is given.

Grid resampling

If neither ppw nor band_spacings is set, the model keeps its original grid spacing for all bands.

Low-frequency bands do not require fine grids. Use ppw (points per wavelength) to let the framework compute an appropriate spacing for each band automatically:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "ppw": 6,
}

The model is resampled to the coarser grid for early bands and interpolated back to the original spacing as fmax increases.

Alternatively, specify explicit spacings with band_spacings:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "band_spacings": [60.0, 30.0, 15.0],  # meters
}

Model smoothing

Between bands the model is spatially smoothed with a Gaussian filter whose cutoff matches the maximum resolvable wavenumber at the next band’s fmax. This is enabled by default; disable it with:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "model_smoothing": False,
}

The smoothing is adaptive: when grid spacing remains the same between bands, smoothing is scaled by the frequency ratio to avoid removing resolvable content. You can control the smoothing strength with smoothing_factor:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "smoothing_factor": 0.25,  # conservative (default)
}
  • smoothing_factor=0.0 effectively disables smoothing
  • smoothing_factor=0.25 is conservative, preserving most detail
  • smoothing_factor=0.5 is moderate
  • smoothing_factor=1.0 applies full wavelength-based smoothing

Custom smoothers

model_smoothing is pluggable. In addition to True/False, it accepts a registered smoother name or a callable, so you can replace the built-in Gaussian low-pass with your own strategy. A smoother has the signature:

def my_smoother(model, fmax, **params):
    """model: WaveModel; fmax: band frequency (Hz); returns a WaveModel."""
    ...

It receives smoothing_factor, mute_type, mute_threshold (resolved from the gradient mute configuration), plus anything you put in smoothing_params, as keyword arguments. Register it by name:

from devitohorizon.inversion.fwi import model_smoother

@model_smoother("median")
def median_smoother(model, fmax, *, radius=3, **_):
    from scipy.ndimage import median_filter
    from devitohorizon.model.grid import get_interior_vp
    # ... build and return a new WaveModel with median-filtered parameters ...
    return model

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "model_smoothing": "median",
    "smoothing_params": {"radius": 5},
}

The built-in Gaussian smoother is registered under the name "gaussian", so model_smoothing=True and model_smoothing="gaussian" are equivalent. You can also pass a callable directly instead of registering a name:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "model_smoothing": median_smoother,
}
Note

A registered name keeps the continuation config serialisable; a bare callable is convenient for quick experiments but will not survive being saved to disk.

Per-band preprocessing

By default the global param["preprocess"] config is used for all bands (with the frequency filter merged on top). To override mute, gain, or other preprocessing per band, pass a list of dicts via continuation["preprocess"]:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "preprocess": [
        {"mute": {"type": "direct", "v": 1500}, "gain": {"type": "t2"}},
        {"mute": {"type": "direct", "v": 1500}},
        {"mute": {"type": "direct", "v": 1600}, "gain": {"type": "agc", "window": 0.5}},
    ],
}

Each entry fully replaces param["preprocess"] for that band; the bandpass filter is still merged automatically. If the list is shorter than fmax, the last entry is reused for subsequent bands. If continuation["preprocess"] is omitted, all bands use the global param["preprocess"].

Shot subsampling

Use batch_size (number of shots) or shot_fraction (fraction of total shots) to control how many shots are used per iteration. They are alternatives – use one or the other, not both.

Set the value globally in param, or override per band in continuation:

# Fixed batch size per band
param = {
    ...,
    "continuation": {
        "fmax": [5.0, 10.0, 15.0, 20.0],
        "batch_size": [4, 8, 12, 16],
    },
}

# Or as a fraction of total shots per band
param = {
    ...,
    "continuation": {
        "fmax": [5.0, 10.0, 15.0, 20.0],
        "shot_fraction": [0.1, 0.25, 0.5, 1.0],
    },
}

A scalar applies the same value to all bands:

"continuation": {
    "fmax": [5.0, 10.0, 15.0, 20.0],
    "batch_size": 8,
}

A global default can also be set in param directly (e.g. "batch_size": 8) and will apply to any band that does not have a per-band override. If the per-band list is shorter than fmax, the last value is reused.

Multiple sweeps

Repeat the full frequency schedule multiple times, optionally changing the misfit or normalization per sweep:

"continuation": {
    "fmax": [5.0, 10.0, 20.0],
    "iters": [4, 6, 8],
    "sweeps": 2,
    "sweep_misfits": ["l2", "l2"],
    "sweep_normalization": [False, "trace"],
    "sweep_labels": ["pass-1", "pass-2"],
}

Optimizer configuration

Optimizer settings are passed via param["optimizer"]. The method key selects the algorithm (SPG, PQN, or BREGMAN); all other keys are forwarded as constructor arguments:

# SPG with custom step size and non-monotone memory
"optimizer": {
    "method": "SPG",
    "maxiter": 20,
    "ftol": 1e-6,
    "gtol": 1e-8,
    "alpha0": 1e-3,
    "first_order_ls": True,
    "nm_memory": 5,
}

# PQN with L-BFGS memory
"optimizer": {
    "method": "PQN",
    "maxiter": 15,
    "memory": 3,
    "nm_memory": 3,
}

# Split Bregman for sparsity-promoting inversion
"optimizer": {
    "method": "BREGMAN",
    "maxiter": 20,
    "tau": 1.0,
}

When using continuation, maxiter in the optimizer dict acts as the default for all bands. Per-band iteration counts set via continuation["iters"] override it.

You can also pass optimizer settings as the options argument to FWIObjective directly (they take precedence over param["optimizer"]):

objective = FWIObjective(
    param=param,
    options={"method": "PQN", "memory": 5, "maxiter": 12},
)

Parallel execution with Dask

Pass a Dask client to FWIObjective to distribute shots across workers. The scheduler is used for every band in the continuation loop automatically:

from dask.distributed import Client
from devitohorizon.inversion.fwi import FWIObjective

client = Client(n_workers=4, threads_per_worker=2)

param = {
    "model": "models/init.zarr",
    "data_path": "data/shots.segy",
    "nbl": 40,
    "space_order": 12,
    "tn": 2.0,
    "wavelet": {"type": "ricker", "f0": 0.020},
    "bounds": {"vp": (1.4, 5.0)},
    "continuation": {
        "fmax": [5.0, 10.0, 15.0, 20.0],
        "iters": [4, 5, 6, 8],
    },
    "optimizer": {"method": "SPG"},
}

objective = FWIObjective(client=client, param=param)
model, fval, result = objective.run()
client.close()

For the CLI entry point (devitohorizon-fwi), a local cluster is created automatically when the config contains a dask key:

{
    "dask": {"n_workers": 4, "threads_per_worker": 2},
    "continuation": {"fmax": [5.0, 10.0, 20.0]},
    ...
}

Combining with other options

Continuation composes with all other param options – preprocessing, gradient processing, source estimation, and normalization all work as usual:

param = {
    "model": "models/init.zarr",
    "data_path": "data/shots.segy",
    "nbl": 40,
    "space_order": 12,
    "tn": 2.0,
    "wavelet": {"type": "ricker", "f0": 0.020},
    "bounds": {"vp": (1.4, 5.0)},
    "gradient": {"mute_type": "water", "cone_mute": True},
    "normalization": "trace",
    "source_estimation": True,
    "preprocess": {
        "mute": {"type": "direct", "v": 1500},
    },
    "continuation": {
        "fmax": [5.0, 10.0, 15.0, 20.0],
        "iters": [4, 5, 6, 8],
        "ppw": 6,
        "shot_fraction": [0.3, 0.5, 0.8, 1.0],
    },
    "optimizer": {"method": "SPG"},
}

objective = FWIObjective(param=param)
model, fval, result = objective.run()

# Per-band history
for entry in objective.history:
    print(entry["label"], entry["objective"])

Saving iterates and plots

Output is controlled by keys in param:

Key Type Default Description
output_dir str run_name Directory for all output files
save_models bool True Save HDF5 model checkpoints
save_every int 1 Save every N iterations
plot bool True Save PNG plots per iteration
run_name str "fwi_run" Base name for output files

These settings are forwarded to the optimizer which creates a ResultCollector for each band. Each band gets its own files, named by the band’s run name ({run_name}_{sweep}_{fmax}), so nothing is overwritten across bands:

param = {
    ...,
    "run_name": "my_fwi",
    "output_dir": "/results/fwi",
    "save_models": True,
    "save_every": 1,
    "plot": True,
}

Example output with fmax=[5.0, 10.0]:

/results/fwi/
  my_fwi_sweep-1_f5_iter_0000_vp.segy   # checkpoints, band 1, one file
  my_fwi_sweep-1_f5_iter_0000_b.segy    #   per physical parameter
  my_fwi_sweep-1_f5_iter_0000.png       # iteration plots, band 1
  my_fwi_sweep-1_f5_iter_0001_vp.segy
  ...
  my_fwi_sweep-1_f10_iter_0000_vp.segy  # band 2
  my_fwi_sweep-1_f10_iter_0000.png
  ...

Everything a run saves that has samples in it is SEG-Y — the checkpoints, the final model, the QC gathers and the migrated images — and everything goes through the store creds names, so a run against blob storage leaves its results there rather than on the machine that drove it.

If output_dir is not set, each band creates a directory named after its run name in the current working directory.

When plot=True, each iteration PNG is a two-row figure: the velocity model on top and the model update (difference from the previous iteration) on the bottom.

Inspecting results

After objective.run() completes:

  • model_opt – the final optimized WaveModel
  • result.model0 – the initial model as a WaveModel, resampled to the final grid spacing so it is directly comparable to model_opt
  • result.fun – final objective value
  • result.nit – iterations in the last band
  • objective.history – list of dicts with band, label, objective, and nit for each band

Plotting the final model and total update

from devitohorizon.model.grid import get_interior_vp

model_opt, f_opt, result = objective.run()
vp_opt = get_interior_vp(model_opt)
vp0 = get_interior_vp(result.model0)
update = vp_opt - vp0

fig, axes = plt.subplots(2, 1, figsize=(24, 12))

plt.sca(axes[0])
pysegy.plot_velocity(
    vp_opt.T,
    origin=model_opt.origin,
    spacing=model_opt.spacing,
    cmap='jet',
    cbar=True,
    new_fig=False,
    name='Optimized Velocity',
)

plt.sca(axes[1])
pysegy.plot_simage(
    update.T,
    origin=model_opt.origin,
    spacing=model_opt.spacing,
    cmap='seismic',
    cbar=True,
    new_fig=False,
    name='Total Update',
    perc=98,
)

fig.tight_layout()
plt.savefig('final_result.png', dpi=150, bbox_inches='tight')
Back to top