Workshop: A CNN Segments the Field's Seismic Line

Chapter 14, Convolutional Networks for Spatial Data

Learning objectives

  • Build a synthetic seismic trace from a well's sonic and density: depth to time, impedance, reflection coefficients, a convolution with a Ricker
  • Label each sample of a trace by its zone, and train a small 1-D CNN to call the zones from the wiggles
  • Score a segmentation on a stretch of the line it never trained on, and say why the training pixels flatter it
  • Read which zones a network can and cannot see on a seismic line, and why

Zones From Wiggles

A seismic trace is the earth's reflection coefficients convolved with a wavelet, the convolution of Section 14.1 run along time. On a synthetic line through the Ogbon field, a small 1-D CNN trained on the line's updip stretch calls 0.934 of those pixels' zones right and 0.918 of the 21 traces past it that it never saw; calling every pixel shale would get 0.749. The held-out score is the one to report: the training pixels are pixels the network learned from. This workshop builds traces and the network in Python; the figure reads the book's own line and network from the book's precomputed line table.

Seismic Line SegmentationInteractive figure, enable JavaScript to interact.

The Line

The line is the book's own, synthetic: it runs down the dip through Ogbon-3, Ogbon-2, Ogbon-1 and Ogbon-8, 2761 ft, with a trace every 52.8 ft, a quarter of a cell of the field's lateral model, 53 traces in all. Each trace is the field's column at its place, Ogbon-1's beds moved down the dip and their porosity scaled by the lateral model there, logged by Ogbon-1's own build. Its sonic is integrated to two-way time on 1 ms samples, t(z)=2βˆ‘Ξ”t Δzt(z) = 2 \sum \Delta t\, \Delta z, its impedance Z=ρVPZ = \rho V_P differenced to reflection coefficients r=(Z2βˆ’Z1)/(Z2+Z1)r = (Z_2 - Z_1)/(Z_2 + Z_1), and the coefficients convolved with the Synthetic Seismic Modeling book's standard wavelet, a zero-phase Ricker of 30 Hz on 81 samples, as that book builds Ogbon-1's own synthetic. Time zero is the top of Ogbon-3's log, 5568.1 ft, the shallowest on the line; the rock above a trace's log is taken as its first rock and below it its last, and each trace is 249 ms long. The logs' density and sonic are the Petrophysics book's flushed-zone values, so the line does not see the oil. Each pixel is labelled by its zone at its depth, from the generator's truth.

Real seismic is noisy, so each trace carries the Synthetic Seismic Modeling book's band-limited noise, one seeded draw a trace, at 0.500 of the clean line's rms (0.0666): rms 0.0333.

Step 1: Load the Learning Set

The CSV holds the nine wells' measured logs and their zones by the truth, not the line's other traces, so this workshop builds one trace at each well.

import numpy as np
import pandas as pd

URL = "https://ogbonlab.com/mlgeo-core/data/ogbon-learning-set.csv"
df = pd.read_csv(URL, comment="#")
ZONES = ["shale", "upper oil sand", "shaly oil sand",
         "tight limestone", "main sand"]
df["z"] = df["zone"].map({z: i for i, z in enumerate(ZONES)})
wells = df["well"].unique()

Step 2: A Trace From a Well

Integrate the sonic to two-way time, sample the impedance every millisecond, difference it and convolve with a 30 Hz Ricker. Each sample keeps the zone of the depth it came from.

def ricker(f=30.0, dt=0.001, n=81):
    t = (np.arange(n) - n // 2) * dt
    a = (np.pi * f * t) ** 2
    return (1 - 2 * a) * np.exp(-a)

def trace(well, dt_ms=1.0):
    d = df[df["well"] == well]
    z_ft = d["depth_ft"].to_numpy()
    son = d["DT_usft"].to_numpy()
    rho = d["RHOB_gcc"].to_numpy()
    # two-way time from the sonic, zero at the log's top (ms)
    t = np.concatenate([[0.0], np.cumsum(2 * son[:-1] * np.diff(z_ft) / 1000)])
    n = int(np.floor(t[-1] / dt_ms + 1e-9)) + 1
    k = np.searchsorted(t, np.arange(n) * dt_ms + 1e-9, side="right") - 1
    imp = 304800 / son[k] * rho[k]
    r = np.zeros(n)
    r[1:] = (imp[1:] - imp[:-1]) / (imp[1:] + imp[:-1])
    return np.convolve(r, ricker(), mode="same"), d["z"].to_numpy()[k]

These traces start at each well's own log top and are built from the measured logs, tool noise and all; the book's line starts every trace at one datum and builds it from the field's clean column. The shapes agree, and the numbers below are the book's line's.

Step 3: Noise and the Held-Out Trace

traces = [trace(w) for w in wells]
nt = max(len(a) for a, _ in traces)
amp = np.zeros((len(wells), nt))
lab = np.zeros((len(wells), nt), dtype=int)
for i, (a, z) in enumerate(traces):
    amp[i, :len(a)], lab[i, :len(z)] = a, z

def rms(v):
    return np.sqrt(np.mean(v ** 2))

rng = np.random.default_rng(0)
raw = rng.uniform(-1, 1, amp.shape)
smooth = np.array([np.convolve(v, np.ones(5) / 5, mode="same") for v in raw])
noise = smooth / np.sqrt(np.mean(smooth ** 2, axis=1, keepdims=True))
noisy = amp + 0.5 * rms(amp) * noise

held = wells == "Ogbon-8"
X = noisy / rms(noisy[~held])

Step 4: A Small 1-D CNN

Two "same" conv layers of 6 filters 15 samples long with ReLU, then a 1 x 1 layer to the 5 zones, as in the book's network: 677 numbers to learn, and each call reads 29 ms of the trace around it. PyTorch runs locally, not in the playground.

import torch
import torch.nn as nn

torch.manual_seed(14)
net = nn.Sequential(
    nn.Conv1d(1, 6, 15, padding=7), nn.ReLU(),
    nn.Conv1d(6, 6, 15, padding=7), nn.ReLU(),
    nn.Conv1d(6, 5, 1))
opt = torch.optim.Adam(net.parameters(), lr=0.01)
xb = torch.tensor(X[~held, None, :], dtype=torch.float32)
yb = torch.tensor(lab[~held])
for epoch in range(300):
    opt.zero_grad()
    loss = nn.functional.cross_entropy(net(xb), yb)
    loss.backward()
    opt.step()

The book's kernel trains the same network on the line's first 32 traces, full-batch Adam at a rate of 0.01 for 300 epochs, its loss falling from 1.509 to 0.198.

Step 5: Score It Where It Never Trained

with torch.no_grad():
    call = net(torch.tensor(X[:, None, :], dtype=torch.float32)).argmax(1).numpy()
right = call == lab
acc_train = right[~held].mean()
acc_held = right[held].mean()
all_shale = (lab[held] == 0).mean()

The book's kernel gives, on the book's line, 7440 of the training stretch's 7968 pixels right, 0.934, and 4798 of the held-out stretch's 5229, 0.918. Calling every held-out pixel shale would get 0.749: the number the network must beat. Ogbon-2's trace, which it trained on, has 230 of its 249 pixels right; Ogbon-8's, at the line's downdip end, 1105 ft past the training stretch, 227. A run of this code trains its own network on nine traces and gives its own numbers.

What the Network Sees

On the held-out stretch the network finds 0.983 of the shale pixels, 0.980 of the tight limestone's, 0.946 of the shaly oil sand's and 0.830 of the main sand's, but only 0.069 of the upper oil sand's, and calls 0.893 of those shale. The limestone is far harder than the shales around it and reflects strongly; the upper oil sand is thin, its reflections weak beside the noise, and the network calls it the shale around it. A CNN segments what the wiggles show. Neighbouring traces on a layer-cake line are alike, so even the held-out score flatters a line from another field: it is the honest score for more of this one.

What Comes Next

Section 14.3, the chapter quiz, asks what Sections 14.1 and 14.2 computed.

This page is prerendered for SEO and accessibility. The interactive widgets above hydrate on JavaScript load.