示例代码
'''
Description: henggao_note
version: v1.0.0
Date: 2022-08-08 18:04:47
LastEditors: henggao
LastEditTime: 2022-09-14 18:59:39
'''
import matplotlib.pyplot as plt
import segyio
# demo1
# # segyfile = '.\data\LX_SEGY005.segy'
# segyfile = '.\data\LX_SEGY2.segy'
# f = segyio.open(segyfile, ignore_geometry=True)
# clip = 1e+2
# vmin, vmax = -clip, clip
# # Figure
# figsize=(20, 20)
# fig, axs = plt.subplots(nrows=1, ncols=1, figsize=figsize, facecolor='w', edgecolor='k',
# squeeze=False,
# sharex=True)
# axs = axs.ravel()
# im = axs[0].imshow(f.trace.raw[0:800].T, cmap=plt.cm.seismic, vmin=vmin, vmax=vmax)
# plt.show()
# demo2
# with open(".\data\LX_SEGY005.segy",'rb+') as f:
# i = 0
# for line in f:
# i+=1
# print("line"+str(i),line)
# with open(".\data\LX_SEGY005.segy",'rb') as f:
# print(f.readlines())
# demo3
with segyio.open(".\data\LX_SEGY005.segy") as f:
# with segyio.open(".\data\LX_SEGY2.segy") as f:
# print(f.format) # 4-byte IBM float
# print(f.ilines)
# print(f.header[0]) #道头
# print(f.tracecount)
# print(len(f.trace[0]))
print(f.trace[1])
# print(len(f.ilines))
# print(len(f.xlines))
# demo4
# with open(".\data\demo.txt",'r',c) as f:
# print(f.readlines())
# f = open(".\data\LX_SEGY005.segy",'rb+')
# print(f.readlines())
# segyio.open(f) as f1:
# f1 = segyio.open(".\data\LX_SEGY2.segy")
# print(f1)
# print(f1.ilines)
# print(f1.trace[100])
# print(f1.trace[100][1800])
# print(f1.trace[500][1200])
# i = 800
# list_tmp = []
# for i in range(0,2000):
# i+=1
# list_tmp.append(f1.trace[100][i])
# # list_tmp.append(abs(f1.trace[100][i]))
# print(list_tmp.sort())
# print(list_tmp)
# with open(".\data\LX_SEGY2.segy",'rb+') as f:
# with open(".\data\LX_SEGY005.segy",'rb+') as f:
# print(f.read())
# print(f.read().decode())
# demo4
# import matplotlib.pyplot as mp
# import numpy as np
# import sys
# import struct
# import binascii
# fileName = "BAOFU_amp.segy"
# nTrace = 4
# nSample = 3001
# fSegy = open(fileName,"rb")
# fSegyHeader = {'tracr':[5,8] ,'ep':[17,20] , 'cdp':[21,24] , 'offset':[37,40],
# 'gelev':[41,44] , 'selev': [45,48] , 'sdepth':[49,52], 'scalel':[69,70],
# 'scalco':[71,72], 'sx':[73,76] , 'sy':[77,80] , 'gx':[81,84] , 'gy':[85,88]}
# for iTrace in range(nTrace):
# fSegy.seek(240*iTrace+3600+nSample*4*iTrace,0) # 每一道都跳过240字节道头
# traceHeader = fSegy.read(240)
# for key in fSegyHeader.keys():
# tempValue = traceHeader[fSegyHeader[key][0]:fSegyHeader[key][1]]
# hexValue = tempValue.hex()
# decValue = int(hexValue,16)
# print(key,decValue)
#demo 5
# code for read IBM segy format seismic data files
# import matplotlib.pyplot as mp
# import numpy as np
# import sys
# import struct
# import binascii
# def ibm2ieee(ibm):
# if ibm == 0:
# return 0.0
# sign = ibm >> 31 & 0x01
# exponent = ibm >> 24 & 0x7f
# mantissa = (ibm & 0x00ffffff) / float(pow(2, 24))
# return (1 - 2 * sign) * mantissa * pow(16, exponent - 64)
# fileName = ".\data\LX_SEGY2.segy"
# nTrace = 241
# nSample = 2001
# fSegy = open(fileName,"rb")
# print(fSegy)
# print(type(fSegy))
# data = np.zeros((nSample,nTrace))
# fSegy.seek(3600,0) # 跳过3600字节卷头
# for iTrace in range(nTrace):
# fSegy.seek(240,1) # 每一道都跳过240字节道头
# for iSample in range(nSample):
# tempValue = fSegy.read(4)
# hexValue = tempValue.hex()
# decValue = int(hexValue,16)
# unintValue = struct.unpack('>L',struct.pack('>I', decValue))[0] # < > 用于控制大小端转换
# floatValue = ibm2ieee(unintValue)
# data[iSample][iTrace] = floatValue
# fSegy.close()
# print(data)
# mp.matshow(data, cmap=mp.cm.gray)
# mp.show()
# fileName = ".\data\LX_SEGY005.segy"
# nTrace = 1
# nSample = 783
# fSegy = open(fileName,"rb")
# # print(fSegy)
# print(type(fSegy))
# print(type(fSegy.read()))