#!/usr/bin/env python # A hack to transform xyz column data (traveltime, velocity) to # the very strange claritas .nmo format. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU program General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # program General Public License for more details. # # You should have received a copy of the GNU program General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # TODO: add option (with optparse) to shift traveltimes (other than the first). # this will make it easy to handle the OBS style 1/2 way traveltime. Also add # option to write out trace numbers instead of offset (cause Claritas cracks under # the pressure of using offsets). import sys import fileinput from string import * if len(sys.argv) != 3: print """ Error: usage is 'zelt_vm2claritas.py [input] [output]'. Used to convert 'offset(km), traveltime(s), velocity(km/s)' ascii column data to a claritas .nmo format. Can handle non xyz headers. """ #print len(sys.argv) sys.exit() inFile, outFile = sys.argv[1:3] inputData = [] resultData = [] # Checking of input data, should be 3 columns of numbers (offset, depth[or tt], velocity), for line in fileinput.input(inFile): fields = line.split() if len(fields) != 3: continue try: fields = map(float, (fields)) except ValueError: continue inputData.append(fields) allProfiles = [] singleProfile = [] # assigning each offset to its seperate list inside a larger list (list in a list) for point in range(0, len(inputData)): currentOffset = inputData[point][0] prevOffset = inputData[point - 1][0] if currentOffset == prevOffset: singleProfile.append(inputData[point]) # if its a different offset, start a new sub-list and put values in it else: singleProfile = [] singleProfile.append(inputData[point]) allProfiles.append(singleProfile) # if there was only one offset, then it should still be appended to the superlist # for simplicity later on. if len(allProfiles) == 0: allProfiles.append(singleProfile) # # Delete every 3rd, 5th, 7th, ..., nth element, because they are not useful in the # # .nmo file. # for profile in allProfiles: # i = 1 # while 1: # i += 1 # if i < len(profile): # del profile[i] # else: # break outFileObj = open(outFile, "w") # Write out the .nmo header fluff # if the first column of the input file doesn't represent offset, this should # be changed accordingly. outFileObj.write("""NMO PRIMARY KEY : OFFSET SECONDARY KEY : ??? INTERPOLATION KEY : Interpolate/End Created: |KEYVAL|{T1 |V1} |{T2 |V2} |{T3 |V3} |{T4 |V4}... | """) # # Taking the average velocity of each layer. Perhaps unnecessary, so excluded. # for i in range(len(inputData) - 1): # inputData[i][1] = (inputData[i][1] + inputData[i + 1][1]) / 2 # For each clump of 4 lines in the input file, write them to one line # in the output file. for profile in allProfiles: inputLen = len(profile) step = 4 for i in range(0, inputLen, step): # Have to skip offsets of exactly "-1", because Claritas is to pie crusts what a # porsche is to cars. if int(profile[i][0]) == -1: continue # For the first line only, write out the "cdp" (or offset), else write an equal # amount of space. if i == 0: offset = str(int(profile[i][0])) whiteSpace = abs(7 - len(offset)) # must stick in some blank space so everything is alligned vertically # Changed 'offset' from an int to a float, because Claritas can handle it. # changing everything to strings, so its left justified. outFileObj.write(" %s%s" %(offset, " " * whiteSpace)) else: # sticking in space to fill in the column in which offset isn't written. - crazy format. outFileObj.write(" ") for j in range(step): if i + j < inputLen: #print "depth (or time):", profile[i + j][1]*1000, "velocity:", profile[i + j][2]*1000 # Writing of the nmo format, columns have to be left justified, and therefore # have to be converted to strings, hence the ugly syntax. outFileObj.write("%s %s " %((str(int(profile[i + j][1]*1000))).ljust(6),\ (str(int(profile[i + j][2]*1000))).ljust(6))) outFileObj.write("\n") outFileObj.close()