本文實(shí)例為大家分享了python地震數(shù)據(jù)可視化的具體代碼,供大家參考,具體內(nèi)容如下
參考源碼:seisplot
準(zhǔn)備工作:
在windows10下安裝python3.7,下載參考源碼到本地。
1. demo繪圖測(cè)試
demo繪圖指令
cmd> python seisplot.py --demo
問(wèn)題1)缺少依賴包
1
2
3
4
5
6
7
|
file "d:/desktop/python可視化/seisplot/seisplot.py" , line 16 , in <module> import yaml modulenotfounderror: no module named 'yaml' >pip3 install yaml could not find a version that satisfies the requirement yaml ( from versions: ) no matching distribution found for yaml |
查看environment.yml:
1
2
3
4
5
6
7
8
9
|
channels: - defaults - conda - forge dependencies: - matplotlib - numpy - obspy - pillow - pyyaml |
安裝相關(guān)依賴包,如 obspy pillow pyyaml
cmd> pip3 install obspy
出現(xiàn)proxy error, 添加選項(xiàng) --proxy server:port
安裝ok
問(wèn)題2)配置文件的編碼異常
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
d:\desktop\python可視化\seisplot>python seisplot.py - - demo [ 91m welcome to ┌─┐┌─┐┬┌─┐┌─┐┬ ┌─┐┌┬┐ └─┐├┤ │└─┐├─┘│ │ │ │ └─┘└─┘┴└─┘┴ ┴─┘└─┘ ┴ good luck[ 0m traceback (most recent call last): file "seisplot.py" , line 421 , in <module> cfg = yaml.load(f) file "d:\programfiles\python36\lib\site-packages\yaml\__init__.py" , line 70 , in load loader = loader(stream) file "d:\programfiles\python36\lib\site-packages\yaml\loader.py" , line 34 , in __init__ reader.__init__( self , stream) file "d:\programfiles\python36\lib\site-packages\yaml\reader.py" , line 85 , in __init__ self .determine_encoding() file "d:\programfiles\python36\lib\site-packages\yaml\reader.py" , line 124 , in determine_encoding self .update_raw() file "d:\programfiles\python36\lib\site-packages\yaml\reader.py" , line 178 , in update_raw data = self .stream.read(size) unicodedecodeerror: 'gbk' codec can't decode byte 0x99 in position 2003 : illegal multibyte sequence |
分析源碼中參數(shù)傳遞情況:
1
2
3
4
5
6
7
8
9
10
11
|
def load(stream, loader = loader): """ parse the first yaml document in a stream and produce the corresponding python object. """ print (stream) ## debug by huanying03 loader = loader(stream) try : return loader.get_single_data() finally : loader.dispose() |
打印結(jié)果如下:
1
|
<_io.textiowrapper name = 'config.yml' mode = 'r' encoding = 'cp936' > |
編碼不對(duì)?
65001 :utf-8代碼頁(yè)
936 :默認(rèn)的gbk
437 :是美國(guó)英語(yǔ)
仔細(xì)檢查發(fā)現(xiàn)config.yml中有異常字符,更正config.yml中錯(cuò)誤字符:ok
問(wèn)題3)python調(diào)試打印語(yǔ)句
print ("value=%d"%value)
demo數(shù)據(jù)繪圖結(jié)果
如下:
2. 本地?cái)?shù)據(jù)繪圖測(cè)試
應(yīng)用指令
cmd > python seisplot.py data/my.sgy
問(wèn)題1)數(shù)據(jù)道的采樣值異常
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
filename data2 / t10.sgy seismic.py: 104 :dt = 4000 seismic.py: 104 :ns = 512 seismic.py: 144 :header = b 'c 1 client' n_traces 500 n_samples 512 dt 0.004 t_start 0 t_end 2.044 max_val inf min_val - inf clip_val 180462501764003194804057887685476352 read data in 0.4 s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + plotting plot width 17.00 in plot height 11.00 in traceback (most recent call last): file "seisplot.py" , line 442 , in <module> main(t, cfg) file "seisplot.py" , line 214 , in main cfg) file "d:\desktop\python可視化\seisplot\plotter.py" , line 123 , in plot_histogram y, x, _ = ax.hist(np.ravel(data), bins = int ( 100.0 / (clip_val / largest)), overflowerror: cannot convert float infinity to integer |
解決辦法:將數(shù)據(jù)做歸一化處理
問(wèn)題2)數(shù)據(jù)文件的卷頭異常
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
filename data2 / marmousi_vel.segy.hdrs.sgy.cdp.sgy seismic.py: 104 :dt = 10000 seismic.py: 104 :ns = 350 seismic.py: 144 :header = b '\xc3@\xf1@\xc3\xd3\xc9\xc5\xd5\xe3' traceback (most recent call last): file "seisplot.py" , line 442 , in <module> main(t, cfg) file "seisplot.py" , line 40 , in main s = seismic.from_segy(target, params = { 'ndim' : cfg[ 'ndim' ]}) file "d:\desktop\python可視化\seisplot\seismic.py" , line 164 , in from_segy return cls .from_obspy(stream, params = params) file "d:\desktop\python可視化\seisplot\seismic.py" , line 147 , in from_obspy x = np.array( list (stream.textual_file_header.decode())) unicodedecodeerror: 'utf-8' codec can't decode byte 0xc3 in position 0 : invalid continuation byte |
解決辦法:重寫3200字節(jié)的segy卷頭
marmousi相關(guān)數(shù)據(jù)繪圖
速度模型繪圖結(jié)果如下:
marmousi模型正演的炮集數(shù)據(jù)繪圖結(jié)果如下:
測(cè)試備忘
1
cygwin執(zhí)行指令,可以看到反饋信息為彩色,分析信息很方便。
相比之下,cmd終端執(zhí)行指令后的反饋信息可讀性較差。
2
本地?cái)?shù)據(jù)出現(xiàn)異常后,通過(guò)cwp中的segyread, sushw, sugain, segywrite等程序進(jìn)行修改,滿足繪圖程序要求。
1)3200字節(jié)的卷頭必須規(guī)范
2)道頭字中的cdpt取值必須規(guī)范(xline)
3)道采樣值最好歸一化處理。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/sinat_27917465/article/details/86517738