当采用SeismicUnix进行地震数据处理,我们常采用SeismicUnix快速显示本地二进制数据文件,如速度、成像结果文件等。
这些文件通常为本地的二进制格式文件,以4字节浮点型float
进行读写,且按照数组列优先格式存储。下面我们利用Python,阐述如何读写这样的二进制文件,此处我们用到了numpy
及matplotlib
库。
下面直接上代码:
import numpy as np
import matplotlib.pyplot as plt
nz=301
nx=400
var=np.random.random([nz,nx])
var[150:160,:]=0.5
var1=var.astype(np.float32)
fig=plt.figure() # Figure 1
ax=fig.add_subplot()
ax.imshow(var1,cmap=plt.cm.jet)
ax.set_title('var1')
# write the binary file
var1.T.tofile('var.bin')
# read the binary file
var2=np.fromfile('var.bin',dtype='float32')
fig=plt.figure() # Figure 2
ax=fig.add_subplot()
axis=ax.imshow(var2.reshape([nx,nz]).T,cmap=plt.cm.jet)
ax.set_title('var2')
# example 2
var3=np.fromfile('marm.dat',dtype=np.float32)
fig=plt.figure() # Figure 3
ax=fig.add_subplot()
axis=ax.imshow(var3.reshape([901,231]).T,cmap=plt.cm.jet)
ax.set_title('var3')
plt.show()
Figure 1
Figure 2
Figure 3
如有错误,请指正,谢谢!