Reading segY seismic files with obspy

Corresponding obspy documentation can be found at:

https://docs.obspy.org/packages/autogen/obspy.io.segy.segy._read_segy.html

Each file has a general form of T traces, where the i-th trace can be accessed in segyfile.traces[i]. Each trace has N samples that are accessed in segyfile.traces[i].data and the j-th data point is accessed in segyfile.traces[i].data[j]. N is such that $N = n\Delta_y$, where $\Delta_y$ is the is the size of the y-dimension.


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

from PIL import Image
from obspy.io.segy import segy
import urllib
import numpy as np

Reading the data:


In [2]:
segyfile = segy._read_segy('/Users/mviana/Documents/IBMProjects/Seismic/SegY2TifConv/PSDM_IL1500_2600_XL_3100_6500_time.sgy')

In [180]:
def CropAndEqualize(mtraces):
    mtraces = mtraces[600:1500,:]
    mtraces[mtraces<-3E4] = -3E4
    mtraces[mtraces>+3E4] = +3E4
    mtraces = 255*(mtraces-np.min(mtraces))/(np.max(mtraces)-np.min(mtraces))
    mtraces = mtraces.astype(np.uint8)
    return mtraces

In [182]:
ntraces  = 3401
nsamples = len(segyfile.traces[0].data)
nimages  = round(len(segyfile.traces)/ntraces)
mtraces  = np.zeros((nsamples, ntraces))

nimages  = 1000

for image in range(nimages):
    for trace in range(ntraces):
        mtraces[:,trace] = segyfile.traces[trace+(image*ntraces)].data
    FileName = '/Users/mviana/Documents/IBMProjects/Seismic/SegY2TifConv/volume/Image' + str(image).zfill(4) + '.tif'
    Image.fromarray(CropAndEqualize(mtraces)).save(FileName)

In [ ]: