Ejemplo n.º 1
0
    def getGroupDict(fn):

        if sfopts is not None:
            sf = SEGYFile(fn, **sfopts)
        else:
            sf = SEGYFile(fn)

        fnbase = os.path.split(fn)[-1]
        gd = matcher.match(fnbase).groupdict()
        gd['data'] = sf[::2] + 1j * sf[1::2]

        return gd
Ejemplo n.º 2
0
def get_segy_real(filename):
    '''
  Reads a SEG-Y file and returns all traces without additional metadata.
  '''

    sf = SEGYFile(filename, endian=endian, verbose=VERBOSE)
    traces = sf.readTraces()

    return traces
Ejemplo n.º 3
0
def get_segy_time(filename):
    '''
  Reads a SEG-Y file and returns all traces, as well as the sample rate
  (read from the binary header).
  '''

    sf = SEGYFile(filename, endian=endian, verbose=VERBOSE)
    traces = sf.readTraces()

    return [traces, sf.bhead['hdt'], sf.trhead[0]['lagb']]
Ejemplo n.º 4
0
def get_segy_complex(filename):
    '''
  Reads a SEG-Y file and returns all traces without additional metadata.
  The traces are split into two separate arrays, one each for the real and
  imaginary components of the data.
  '''

    sf = SEGYFile(filename, endian=endian, verbose=VERBOSE)
    real = sf[::2]  #sf.readTraces(sf.findTraces('trid',1001,1001))
    imag = sf[1::2]  #sf.readTraces(sf.findTraces('trid',1002,1002))

    return real + 1j * imag
Ejemplo n.º 5
0
from pygeo.analysis import *
from pygeo.segyread import SEGYFile

sfs2D = SEGYFile('syn2d-after20-postmod-windowed.ppre.su',
                 isSU=True,
                 endian='Little')
sfs00 = SEGYFile('synth-after00-postmod-windowed.ppre.su',
                 isSU=True,
                 endian='Little')
sfs28 = SEGYFile('synth-after28-postmod-windowed.ppre.su',
                 isSU=True,
                 endian='Little')
sfo = SEGYFile('real-withpicks.ppre.su', isSU=True, endian='Little')

picks = getpicks(sfo)
offsets = calcoffset(sfo)
live = getlive(offsets)
loffs = offsets[live]
lpicks = picks[live]
lrpicks = lpicks / 1000. - timereduce(loffs, 4500, 0)

otraces = sfo[:]
s2Dtraces = sfs2D[:]
s00traces = sfs00[:]
s28traces = sfs28[:]

lotraces = otraces[live]
ls2Dtraces = s2Dtraces[live]
ls00traces = s00traces[live]
ls28traces = s28traces[live]
Ejemplo n.º 6
0
else:
    outfile = infile + '.proj'

# Convert rotation angle to radians
angle = np.float(options.angle) * np.pi / 180.

# Convert basis to array
basis = np.array([np.float(item) for item in options.basis.strip().split(',')])

# Set units
unit = np.float(options.unit)

printnow('Reading input files')

# Get data and geometry input files
sfdata = SEGYFile(infile)
if (not options.geom is None):
    geomfile = options.geom
    sfgeom = SEGYFile(geomfile)
else:
    geomfile = infile
    sfgeom = sfdata

printnow('Computing geometry')

# Grab headers
trh0 = sfgeom.trhead[0]
ntr = sfgeom.ntr
ns = sfgeom.ns

# Check to see if geometry and data files are the same shape
Ejemplo n.º 7
0
elif (not os.path.isfile(args[0])):
    parser.error('File %s does not exist!' % (args[0], ))

infile = args[0]

if (len(args) > 1):
    outfile = args[1]
else:
    outfile = infile + '.su'

if (options.verbose):
    print(
        '\nSEG-Y --> SU File Converter v1.0\nBrendan Smithyman, July 2011\n\n\tConverting \'%s\' to \'%s\'...\n'
        % (infile, outfile))

sf = SEGYFile(infile, verbose=options.verbose, majorheadersonly=False)
intr = sf.readTraces()
if (options.normalize):
    intr = sf.sNormalize(intr)

if (options.verbose):
    print('Generating output file.')

if (len(intr.shape) == 1):
    intr = [intr]

sf.writeSU(outfile, intr, sf.trhead)

if (options.verbose):
    print('Done!\n')
Ejemplo n.º 8
0
wlen = DEFAULT_WLEN

if len(sys.argv) >= 3:
    wlen = int(sys.argv[2])

shift = -wlen

if len(sys.argv) >= 4:
    shift = -int(sys.argv[3])

inifile = glob.glob('*.ini')[0]
projnm = inifile.split('.')[0]

ini = readini(inifile)

ns = ini['ns']
nr = ini['nr']

sf = SEGYFile(infile)
dt = sf.bhead['hdt'] * TUNIT
picks = (np.argmax(energyratio(sf[:], wlen), axis=1) + shift)
picks.shape = (ns, nr)

picks = picks * dt

with open('%s.picks'%(projnm,), 'w') as fp:
    fp.writelines(['%d %d %f\n'%(isrc+1, irec+1, picks[isrc, irec]) for isrc in xrange(ns) for irec in xrange(nr)])


Ejemplo n.º 9
0
# Convert basis to array
basis = np.array([np.float(item) for item in options.basis.strip().split(',')])

pickkey = options.key

unit = np.float(options.unit)
zantithesis = np.float(options.zdir)
tfac = np.float(options.tfac)
shotout = options.shotout
error = np.float(options.error)
omit = options.omit

# Open SEG-Y file and get first trace header
sys.stdout.write('Reading "%s"...\n' % (infile, ))
sys.stdout.flush()
sf = SEGYFile(infile, endian='Big')
trh0 = sf.trhead[0]

sys.stdout.write('Calculating scale factors...\n')
sys.stdout.flush()

# Determine coordinate and elevation scale factors from first trace header
# (assume same for all traces)
if (trh0['scalco'] < 0):
    scalco = 1. / abs(trh0['scalco'])
else:
    scalco = trh0['scalco']

scalco = scalco / unit

if (trh0['scalel'] < 0):
Ejemplo n.º 10
0
estfiles = np.array(glob.glob(estfilekey))
sest = np.sort([float(item[lpn + 6:]) for item in estfiles])
maybePrint('\tfound %d synthetic data files' % (len(estfiles), ))

obsfiles = np.array(glob.glob(obsfilekey))
sobs = np.sort([float(item[lpn + 6:]) for item in obsfiles])
maybePrint('\tfound %d observed data files' % (len(obsfiles), ))

sortedfreqs = [item for item in sest if item in sobs]
estfiles = [estfilecompose % (item, ) for item in sortedfreqs]
obsfiles = [obsfilecompose % (item, ) for item in sortedfreqs]
maybePrint('\twith  %d frequencies in common' % (len(sortedfreqs), ))

tau = float(options.tau)
if (tau):
    sf = SEGYFile(obsfiles[0])
    dims = (sf.ntr / 2, sf.ns)
    if (norm in picknorms):
        if (os.path.isfile(options.pickfile)):
            maybePrint('\treading picks from %s...' % (options.pickfile, ))
            pickmap = getpicksbitmap(options.pickfile, dims)
        else:
            parser.error(
                'Laplace-domain (Tau) compensation not implemented for offset! File %s does not exist. Please provide a pick file.'
                % (options.pickfile, ))
    else:
        maybePrint(
            '\tNB: Tau of %3.3f specified; meaningless for fazonly=%d.' %
            (tau, norm))
else:
    pickmap = None
Ejemplo n.º 11
0
def loadfunc():

    sf = SEGYFile(infile)
    sf._calcEnsembles()
    ntr = sf.ntr
    nsrc = len(sf.ensembles)
    nrec = ntr / nsrc
    nsamp = sf.ns
    dt = sf.bhead['hdt'] / 1.e6

    trh0 = sf.trhead[0]

    scalco = trh0['scalco']
    if (scalco < 0):
        scalco = -1. / scalco

    scalel = trh0['scalel']
    if (scalel < 0):
        scalel = -1. / scalel

    datadims = (nsrc, nrec, nsamp)
    headerdims = (nsrc, nrec)
    flatdatadims = (ntr, nsamp)

    params = {
        'ntr': ntr,
        'nsrc': nsrc,
        'nrec': nrec,
        'nsamp': nsamp,
        'dt': dt,
        'scalco': scalco,
        'scalel': scalel,
        'datadims': datadims,
        'headerdims': headerdims,
        'flatdatadims': flatdatadims,
    }

    dbase['params'] = params

    sx = np.array([float(abs(trh['sx']))
                   for trh in sf.trhead]).reshape(headerdims)
    gx = np.array([float(abs(trh['gx']))
                   for trh in sf.trhead]).reshape(headerdims)
    offset = abs(sx - gx)
    cdp = (sx + gx) / 2.

    water = offset / watervelocity
    wmute = water / dt

    headers = {
        'sx': sx,
        'gx': gx,
        'offset': offset,
        'cdp': cdp,
        'water': water,
        'wmute': wmute,
    }

    dbase['headers'] = headers

    if (os.path.exists(tempfile)
            and os.path.getmtime(tempfile) > os.path.getmtime(infile)):
        tracebuf = np.memmap(tempfile,
                             dtype=np.float32,
                             shape=datadims,
                             mode='r+')
    else:
        tracebuf = np.memmap(tempfile,
                             dtype=np.float32,
                             shape=datadims,
                             mode='w+')
        tracebuf[:] = sf[:].reshape(datadims)

    dbase['data_orig'] = tracebuf
    dbase['data_current'] = tracebuf
Ejemplo n.º 12
0
x0, x1 = [np.float(item) for item in options.extent.strip().split(',')]

# Convert rotation angle to radians
angle = np.float(options.angle) * np.pi / 180.

# Convert basis to array
basis = np.array([np.float(item) for item in options.basis.strip().split(',')])

unit = np.float(options.unit)
zantithesis = np.float(options.zdir)

stackfile = args[0]
velfile = args[1]
outfile = args[2]

sfstack = SEGYFile(stackfile, endian='Big')
sfvel = SEGYFile(velfile, endian='Big')

# ------------------------------------------------------------------------
# Main Program

strh0 = sfstack.trhead[0]
sntr = sfstack.ntr
sns = sfstack.ns

vtrh0 = sfvel.trhead[0]
vntr = sfvel.ntr
vns = sfvel.ns

scalco = float(strh0['scalco'])
if (scalco < 0):
Ejemplo n.º 13
0
            if (gopts['filename'].find(thisprojnm) == 0):
                gopts['projnm'] = thisprojnm
                gopts['inifile'] = gri
                if (options.verbose):
                    print('Found matching project file: %s' % (gri, ))
                break
    else:
        parser.error('This program requires a project *.ini file to function!')
except:
    parser.error('Something happened!')

ini = readini(gopts['inifile'])

extent = [
    ini['xorig'], ini['xorig'] + ini['dx'] * (ini['nx'] - 1),
    -(ini['zorig'] + ini['dz'] * (ini['nz'] - 1)), -ini['zorig']
]

srcs = ini['srcs']

sf = SEGYFile(gopts['filename'], endian='Big', verbose=options.verbose)
model = sf[:].T

fig = pl.figure()
ax = fig.add_subplot(1, 1, 1, aspect=1.0)
pl.imshow(model, extent=extent)
pl.plot(srcs[:, 0], -srcs[:, 2], 'w.')
ax.axis(extent)

pl.show()
Ejemplo n.º 14
0
    def sfWrapper(filename):

        sf = SEGYFile(filename)
        return sf