Data Preprocessing
Ordering the built-in preprocessing and adding your own steps
The preprocess config is applied to every shot before the misfit sees it, to the observed and the synthetic alike. It is a dict of named sections (filter, differentiate, integrate, mute, offset, gain), each documented in devitohorizon.preprocess.apply_preprocessing. An optional steps list sets the order they run in and adds custom steps. The contract is in the devitohorizon.preprocess.steps module docstring.
Default order
Without steps, the configured sections run in a fixed order: filter, differentiate, integrate, mute, offset, gain. This is BUILTIN_PREPROCESS_STEPS.
physics = DevitoPhysics(
preprocess={
"filter": {"type": "bandpass", "fmin": 3.0, "fmax": 8.0},
"mute": {"type": "direct", "v": 1500.0},
},
)Choosing the order
steps lists the steps in the order you want them. A built-in step is listed by name. Its parameters stay in its section:
preprocess = {
"filter": {"type": "bandpass", "fmin": 3.0, "fmax": 8.0},
"mute": {"type": "direct", "v": 1500.0},
"steps": ["mute", "filter"],
}Two rules keep the data and the source wavelet consistent:
- Built-in parameters live only in their section. The
filtersection is also what filters the source wavelet, and a continuation schedule writes each band into it.{"kind": "filter", "fmax": 8.0}instepsis rejected. - Every configured section must be listed. A section that isn’t listed raises an error instead of being silently dropped. Listing a built-in with no section is a no-op, so put
"filter"instepswhenever a continuation is used.
Custom steps
A step is a function of the gather, the sample interval in seconds and the coordinates. Its extra parameters come from the step dict:
import numpy as np
from devitohorizon.preprocess import preprocess_step
@preprocess_step("despike")
def despike(data, dt, src_pos, rec_pos, *, threshold=5.0):
"""Clip samples beyond ``threshold`` times each trace's RMS."""
rms = np.sqrt(np.mean(data**2, axis=0, keepdims=True)) + 1e-30
return np.clip(data, -threshold * rms, threshold * rms)
physics = DevitoPhysics(
preprocess={
"filter": {"type": "bandpass", "fmin": 3.0, "fmax": 8.0},
"steps": [{"kind": "despike", "threshold": 4.0}, "filter"],
},
)register_preprocess_step(name, fn) is the non-decorator form. A step returns a gather of the same shape, and src_pos/rec_pos are None when the caller has no coordinates.
In the misfit a step runs on both sides. Add "target": "obs" or "target": "syn" to its dict to run it on one side only, the same way a section is targeted:
"steps": ["filter", {"kind": "despike", "target": "obs"}]A custom step only processes the gathers. Only the filter section is also applied to the source wavelet, so a step that changes the phase of the data should run on both sides.
Distributed runs
The registry is per process. A step registered in a notebook is not known to the Dask workers that preprocess the shots. Either register it in a module the workers import, or put the function itself in the step so it is shipped with the config:
"steps": [{"kind": despike, "threshold": 4.0}, "filter"]A JSON config can only name steps, so a step used from a JSON config has to be registered on every worker.
See Also
- Despiking Noise Bursts: a custom step on field-like noise, from the gathers to an inversion
- Custom Gradient Processing: the matching step pipeline on the gradient side
- Configuring an FWI Run: the
preprocesssections in a JSON run config