两套sps合并

在地震采集施工中,经常需要对观测系统进行针对性调整,例如加线等情况,利用绿山可以生产各类复杂观测系统,但两套sps这种情况直接导入就回报重复错误,一般情况,两套sps合并都是到克浪软件中导进导出,为节约时间,编写了一个简单gui界面的两套sps合并小程序。合并之后的sps为简单合并,未进行通道号重置,但绿山和omni软件能准确识别。

import tkinter as tk
from tkinter import filedialog, dialog
from tkinter.messagebox import *
import pandas as pd
import os
import time

def open_bigspsfile():
    filebig_path = filedialog.askopenfilename(title='选择关系文件', filetypes=[('All Files', ['.xps','x'])])
    bigpath.set(filebig_path)

def open_litspsfile():
    filelit_path = filedialog.askopenfilename(title='选择关系文件', filetypes=[('All Files', ['.xps','x'])])
    litpath.set(filelit_path)
def getValueBig():
    filebig_path=entry1.get()
    return filebig_path
def getValueLit():
    filelit_path=entry2.get()
    return filelit_path   
def mat_file():
    filebig_path=getValueBig()
    filelit_path=getValueLit()
    filetemp_path=os.path.splitext(filebig_path)[0]
    time_start = time.time()
    ########################输入输出sps文件都是sps2.1格式,sps软件8.0版本#################
    ###################读取原始sps信息,即全sps文件,输出sps2.1格式sps软件8.0版本######################
    print('读取第一套sps文件......')
    data = []
    for line in open(filebig_path, 'r'):
        data.append(line)
    ############计算头卡行数########
    i = 0
    while data[i][0] == 'H':
        i = i + 1
    ii = i  ##计算头卡行数
    ###########读取关系文件获得文件号与桩号对应关系####
    v = data[ii:]
    del data
    xlenth = len(v)
    data1=[]
    #######################读取关系文件信息################
    for i in range(0, xlenth):
        data1.append([int(v[i][10:15]),int(float(v[i][17:24])),int(v[i][28:34]),\
                      int(v[i][38:43]),int(v[i][43:48]),\
                        int(v[i][49:54]),int(v[i][62:66]),int(v[i][72:76])])
    pddata1=pd.DataFrame(data1)
    pddata1.columns=['ffid','shotline','shotpoint','chanfrom','chanto','rline','rpointfrom','rpointto']
    del data1,v
    ####################处理小sps文件################################
    print('读取第二套sps文件......')
    data2 = []
    for line in open(filelit_path,'r'):
        data2.append(line)
    ############计算头卡行数########
    i = 0
    while data2[i][0] == 'H':
        i = i + 1
    ii = i  ##计算头卡行数
    ###########读取关系文件获得文件号与桩号对应关系####
    vl = data2[ii:]
    del data2
    xlenthl = len(vl)
    datalor=[]
    #######################读取关系文件信息################
    for i in range(0, xlenthl):
        datalor.append([int(vl[i][10:15]),int(float(vl[i][17:24])),int(vl[i][28:34]),\
                        int(vl[i][38:43]),int(vl[i][43:48]),\
                        int(vl[i][49:54]),int(vl[i][62:66]),int(vl[i][72:76])])
    print('合并处理中......')
    pddata2=pd.DataFrame(datalor)
    pddata2.columns=['ffid','shotline','shotpoint','chanfrom','chanto','rline','rpointfrom','rpointto']
    df=pd.concat([pddata1,pddata2])
    df.reset_index(drop=True, inplace=True)
    df['shotlinepoint']=df['shotline']*10000+df['shotpoint']
    df=df.sort_values(by = ['shotlinepoint','rline'])
    df.reset_index(drop=True, inplace=True)
    del datalor,vl,pddata1,pddata2
    pddatal4=df.values.tolist()
    print('写入sps中...')
    f=open(filetemp_path+'_合并后.X','w+')       
    f.write('H00 SPS format version num.     SPS2.1;                                         '+"\n")
    f.write('H01 Description of survey area  cd2,,N/A,N/A;                                   '+"\n")
    f.write('H02 Date of survey              ;                                               '+"\n")
    f.write('H021Post-plot date of issue     ;                                               '+"\n")
    f.write('H022Tape/disk identifier        DISK;                                           '+"\n")
    f.write('H03 Client                      N/A;                                            '+"\n")
    f.write('H04 Geophysical contractor      N/A;                                            '+"\n")
    f.write('H05 Positioning contractor      N/A;                                            '+"\n")
    f.write('H06 Pos. proc. contractor       N/A;                                            '+"\n")
    f.write('H07 Field computer system(s)    428XL;                                          '+"\n")
    f.write('H08 Coordinate location         Center of source and of receiver pattern;       '+"\n")
    f.write('H09 Offset from coord. location 0.0M,0.0DEG;                                    '+"\n")
    f.write('H10 Clock time w.r.t. GMT       ;                                               '+"\n")
    f.write('H11 Spare                       ;                                               '+"\n")
    f.write('H12 Geodetic datum,-spheroid    ;                                               '+"\n")
    f.write('H13 Spare                       ;                                               '+"\n")
    f.write('H14 Geodetic datum parameters   ;                                               '+"\n")
    f.write('H15 Spare                       ;                                               '+"\n")
    f.write('H16 Spare                       ;                                               '+"\n")
    f.write('H17 Vertical datum description  ;                                               '+"\n")
    f.write('H18 Projection type             UTM;                                            '+"\n")
    f.write('H19 Projection zone             ;                                               '+"\n")
    f.write('H20 Description of grid units   Metres;                                         '+"\n")
    f.write('H201Factor to metre                 1.00000000;                                 '+"\n")
    f.write('H220Long. of central meridian   ;                                               '+"\n")
    f.write('H231Grid origin                 ;                                               '+"\n")
    f.write('H232Grid coord. at origin       ;                                               '+"\n")
    f.write('H241Scale factor                ;                                               '+"\n")
    f.write('H242Lat., long. scale factor    ;                                               '+"\n")
    f.write('H256Lat., long. initial line    ;                                               '+"\n")
    f.write('H257Circular bearing of H256    ;                                               '+"\n")
    f.write('H258Quadrant bearing of H256    ;                                               '+"\n")
    f.write('H259Angle from skew             ;                                               '+"\n")
    f.write('H300Project code and description;                                               '+"\n")
    f.write('H310Line number format          ;                                               '+"\n")
    f.write('H400Type,Model,Polarity         ;                                               '+"\n")
    f.write('H401Crew name,Comment           ;                                               '+"\n")
    f.write('H402Sample int.,Record Len.     1,0.000000,N/A;                                 '+"\n") 
    f.write('H403Number of channels          1,5376;                                         '+"\n")
    f.write('H404Tape type,format,density    ;                                               '+"\n")
    f.write('H405Filter_alias Hz,dB pnt,slope;                                               '+"\n")
    f.write('H406Filter_notch Hz,-3dB points ;                                               '+"\n")
    f.write('H407Filter_low Hz,dB pnt,slope  ;                                               '+"\n")
    f.write('H408Time delay FTB-SOD app Y/N  ;                                               '+"\n")
    f.write('H409Multi component recording   ;                                               '+"\n")
    f.write('H410Aux. channel 1 contents     ;                                               '+"\n")
    f.write('H411Aux. channel 2 contents     ;                                               '+"\n")
    f.write('H412Aux. channel 3 contents     ;                                               '+"\n")
    f.write('H413Aux. channel 4 contents     ;                                               '+"\n")
    f.write('H414Spare                       ;                                               '+"\n")
    f.write('H415Spare                       ;                                               '+"\n")
    f.write('H416Spare                       ;                                               '+"\n")
    f.write('H417Spare                       ;                                               '+"\n")
    f.write('H418Spare                       ;                                               '+"\n")
    f.write('H419Spare                       ;                                               '+"\n")
    f.write('H600Type,model,polarity         G1,geophone 1;                                  '+"\n")
    f.write('H601Damp coeff,natural freq.    ;                                               '+"\n")
    f.write('H602Nunits,len(X),width(Y)      ;                                               '+"\n")
    f.write('H603Unit spacing X,Y            ;                                               '+"\n")
    f.write('H604Spare                       ;                                               '+"\n")
    f.write('H605Spare                       ;                                               '+"\n")
    f.write('H606Spare                       ;                                               '+"\n")
    f.write('H607Spare                       ;                                               '+"\n")
    f.write('H608Spare                       ;                                               '+"\n")
    f.write('H700Type,model,polarity         E1,explosive 1;                                 '+"\n")
    f.write('H701Size,vert. stk fold         ;                                               '+"\n")
    f.write('H702Nunits,len(X),width(Y)      ;                                               '+"\n") 
    f.write('H703Unit spacing X,Y            ;                                               '+"\n")
    f.write('H711Nom. shot depth,charge len. ;                                               '+"\n")
    f.write('H712Nom. soil,drill method      ;                                               '+"\n")
    f.write('H713Weathering thickness        ;                                               '+"\n")
    f.write('H26      1         2         3         4         5         6         7         8'+"\n")
    for i in range(len(pddatal4)):
        ffid = int(pddatal4[i][0])
        shotline = int(pddatal4[i][1])
        shotpoint = int(pddatal4[i][2])
        chanfrom = int(pddatal4[i][3])
        chanto = int(pddatal4[i][4])
        rline = int(pddatal4[i][5])
        rpointfrom = int(pddatal4[i][6])
        rpointto = int(pddatal4[i][7])
        tt=1
        print('X1 ','     %6d%d%d%-6d       %-6d %d%5d%5d%d%5d        %-4d      %-4d   %d'\
              %(ffid,tt,tt,shotline,shotpoint,tt,chanfrom,chanto,tt,rline,rpointfrom,rpointto,tt),file=f)
    f.close()
    time_end=time.time()
    timecost = str(round(time_end-time_start,4))
    print('耗时 '+timecost+' S')
    result = showinfo('提示', 'SPS写入成功,位于第一套sps文件夹下')
    print(f'提示: {result}')    
    
root = tk.Tk()
root.resizable(0, 0)
root.geometry('500x100+400+100')
root.title('两套sps合并,绿山omni可用')
bigpath= tk.StringVar()
litpath= tk.StringVar()

result = showinfo('提示', '输入输出sps文件都是sps2.1格式,sps软件8.0版本')
print(f'提示: {result}')

label1 = tk.Label(root, text="1、第一套sps:")
label2 = tk.Label(root, text="2、第二套sps:")
label1.grid(row=0)
label2.grid(row=1)

entry1 = tk.Entry(root,width=40,textvariable = bigpath)
entry2 = tk.Entry(root, width=40,textvariable = litpath)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)



buttonForFile = tk.Button(root, text="浏览文件", command=open_bigspsfile)
buttonRun = tk.Button(root, text="浏览文件", command=open_litspsfile)
buttonForFile.grid(row=0, column=2)
buttonRun.grid(row=1, column=2)
buttonMatch = tk.Button(root, text="3、合并处理", command=mat_file)
buttonMatch.grid(row=2, column=1)

root.mainloop()

两套sps合并

上一篇:file_operations_v2.0


下一篇:pcl学习笔记--生成写pcd文件