import os
import numpy as np
import matplotlib.pyplot as plt
import pysegy
from devitohorizon.preprocess import (lowpass, highpass, bandpass, time_gain, agc,
normalize_shot, normalize_traces, mute_direct, mute_reflections,
apply_preprocessing, differentiate, integrate)
data_path = os.path.join('.' , 'marmousi' )
scan = pysegy.segy_scan(data_path, '*.segy' , keys= ['SourceX' , 'SourceY' , 'ns' , 'dt' ])
shot = scan[0 ]
rec = shot.data
dt = shot.dt/ 1e6
rec.shape, dt
Sampling and Nyquist
Sample interval \(\Delta t\) (s), sampling rate \(f_s=1/\Delta t\) , Nyquist \(f_N=f_s/2\) .
fs, fN = 1.0 / dt, 0.5 / dt
print (f'dt= { dt:.6f} s, fs= { fs:.2f} Hz, Nyquist= { fN:.2f} Hz' )
dt=0.004000s, fs=250.00Hz, Nyquist=125.00Hz
Filters (Butterworth, zero-phase)
We use Butterworth IIR filters with order \(n\) and cutoffs \((f_c)\) or \((f_{min},f_{max})\) . Zero-phase via forward-backward filtering avoids phase distortion. Typical: order 4.
lp = lowpass(shot, None , fcut= 8.0 , order= 4 )
hp = highpass(shot, None , fcut= 3.0 , order= 4 )
bp = bandpass(shot, None , fmin= 3.0 , fmax= 12.0 , order= 4 )
plt.figure(figsize= (10 , 6 ))
for i, g in enumerate (zip ([lp, hp, bp], ['LP 8Hz' , 'HP 3Hz' , 'BP 3-12Hz' ], strict= False )):
plt.subplot(1 , 3 , i+ 1 )
pysegy.plot_sdata(g[0 ], new_fig= False , name= g[1 ])
plt.tight_layout()
Muting (Direct and Reflections)
Per trace, the mute boundary is \(t_{cut}(h)=t_0+h/v\) with offset \(h\) and velocity \(v\) . Direct mute zeros \(t<t_{cut}\) , reflection mute zeros \(t>t_{cut}\) . Cosine taper smooths transitions.
md = mute_direct(shot, None , None , None , v= 1500.0 , t0= 0.00 , taper= 0.5 )
mr = mute_reflections(shot, None , None , None , v= 1500.0 , t0= 0.10 , taper= .5 )
plt.figure(figsize= (8 , 6 ))
plt.subplot(121 )
pysegy.plot_sdata(md, name= 'Direct mute' , new_fig= False )
plt.subplot(122 )
pysegy.plot_sdata(mr, name= 'Reflection mute' , new_fig= False )
plt.tight_layout()
# Sanity check: ensure not fully zero
assert np.linalg.norm(mr) > 0
Gains (Time and AGC)
Time gain: \(g(t)=(t_0+t)^p\) . AGC divides by a moving RMS/|.| window.
tg = time_gain(shot, None , power= 1.0 )
ga = agc(shot, None , window= 0.2 , mode= 'rms' )
plt.figure(figsize= (8 , 6 ))
plt.subplot(121 )
pysegy.plot_sdata(tg, name= 'Time gain' , new_fig= False )
plt.subplot(122 )
pysegy.plot_sdata(ga, name= 'AGC 0.2s' , new_fig= False )
plt.tight_layout()
Normalization
Shot normalization (global RMS/max) vs per-trace normalization.
ns = normalize_shot(rec, mode= 'rms' )
nt = normalize_traces(rec, mode= 'rms' )
plt.figure(figsize= (8 , 6 ))
plt.subplot(121 )
pysegy.plot_sdata(ns, name= 'Shot RMS' , new_fig= False )
plt.subplot(122 )
pysegy.plot_sdata(nt, name= 'Trace RMS' , new_fig= False )
plt.tight_layout()
Pipeline
Combine steps: band-pass, direct mute, AGC.
cfg = {
'filter' : {'type' : 'bandpass' , 'fmin' : 3.0 , 'fmax' : 12.0 , 'order' : 4 },
'mute' : {'type' : 'direct' , 'v' : 1500.0 , 't0' : 0.0 , 'taper' : 0.05 },
'gain' : {'type' : 'agc' , 'window' : 0.2 , 'mode' : 'rms' }
}
rp = apply_preprocessing(shot, None , cfg)
pysegy.plot_sdata(rp, name= 'All steps' , new_fig= True )
Time Differentiation and Integration
Integer orders use finite differences (np.gradient) for derivatives and cumulative sum for integrals. Fractional orders use FFT: multiply spectrum by \((2\pi i f)^{\pm\alpha}\) , DC bin zeroed.
d1 = differentiate(shot, None , order= 1 ) # 1st derivative (FD)
d2 = differentiate(shot, None , order= 2 ) # 2nd derivative (FD, iterated)
i1 = integrate(shot, None , order= 1 ) # 1st integral (cumsum * dt)
d_half = differentiate(shot, None , order= 0.5 ) # ½ derivative (FFT)
i_half = integrate(shot, None , order= 0.5 ) # ½ integral (FFT)
plt.figure(figsize= (14 , 8 ))
for i, (arr, name) in enumerate (zip (
[rec, d1, d2, i1, d_half, i_half],
['Original' , '1st deriv (FD)' , '2nd deriv (FD)' ,
'1st integral (cumsum)' , '½ deriv (FFT)' , '½ integral (FFT)' ], strict= False
)):
plt.subplot(2 , 3 , i+ 1 )
pysegy.plot_sdata(arr, new_fig= False , name= name)
plt.tight_layout()
Via pipeline config
Use differentiate or integrate as top-level config keys. Negative order flips the operation: differentiate: {order: -1} integrates, integrate: {order: -1} differentiates.
cfg_diff = {
'filter' : {'type' : 'bandpass' , 'fmin' : 3.0 , 'fmax' : 12.0 , 'order' : 4 },
'differentiate' : {'order' : 1 }
}
cfg_intg = {
'filter' : {'type' : 'bandpass' , 'fmin' : 3.0 , 'fmax' : 12.0 , 'order' : 4 },
'integrate' : {'order' : 0.5 }
}
rp_diff = apply_preprocessing(shot, None , cfg_diff)
rp_intg = apply_preprocessing(shot, None , cfg_intg)
plt.figure(figsize= (10 , 5 ))
plt.subplot(121 )
pysegy.plot_sdata(rp_diff, name= 'BP + 1st deriv' , new_fig= False )
plt.subplot(122 )
pysegy.plot_sdata(rp_intg, name= 'BP + ½ integral' , new_fig= False )
plt.tight_layout()
Back to top