This tutorial is presented as Python code running inside a Jupyter Notebook, the recommended way to use Salvus. To run it yourself you can copy/type each individual cell or directly download the full notebook, including all required files.

Model Interpolation

This notebook shows how to interpolate a given model defined on a regular grid to a Salvus mesh using the Marmousi model as an example.
# initialize notebook
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import obspy
import salvus.namespace as sn

plt.rcParams["figure.figsize"] = (10, 8)
The Marmousi model is provided in a segy file, which we open with obspy and map to numpy arrays.
def get_marmousi():
    nx, ny = 2301, 751
    dx, dy = 4.0, 4.0

    rho = np.empty((ny, nx))
    st ="data/marmousi_density.segy.gz")
    for _i, tr in enumerate(st):
        rho[_i, :] =

    vp = np.empty((ny, nx))
    st ="data/marmousi_velocity.segy.gz")
    for _i, tr in enumerate(st):
        vp[_i, :] =

    x = np.arange(nx) * dx
    y = np.arange(ny) * dy

    return x, y, vp, rho
Plot the model to verify we got it in correctly:
x, y, vp, rho = get_marmousi()
fig, axes = plt.subplots(2, 1)