My code include module segyio My document .sgy, which I should to process, contains 107591 traces and 2501 values per trace in format "float32". I should to process input sgy file and write new processed sgy file. How can I speed up my code? Maybe I should to use jit or Cython, but I don't know how. Time of calculation this code around 4-5 hours, it so long.
`> import segyio
import statistics
import numpy as np
import time
start_time = time.time()
z=int(input('How many traces would you have to change? '))
T=int(input('Choose the size of window for averaging '))
z1=list(range(z))
t1=int(T//4)
t=T-t1-t1
print('Taken into calculation', t, 'values')
t11 = len(range(t1))
t0 = ([0.0] * t11)
c=np.arange(0, 2502-t)
d=np.arange(t, 2502)
z2=iter(z1)
traces=[]
print ('Precycle', "--- %s seconds ---" % (time.time() - start_time))
with segyio.open('2M.sgy', 'r') as f:
f.mmap()
for i in z1:
full=[]
e=[]
z3 = next(z2)
a=f.trace[z3]
c1 = iter(c)
d1 = iter(d)
for i in d:
c00 = next(c1)
d00 = next(d1)
e00 = statistics.mean(a[c00:d00])
e.append(e00)
full.extend(t0)
full.extend(e)
full.extend(t0)
full=np.array([full], 'float32')
traces.append(full)
print('Changed trace', z3, "--- %s seconds ---" % (time.time() - start_time))
print('Calculation before writing', "--- %s seconds ---" % (time.time() - start_time))
spec=segyio.spec()
spec.sorting=f.sorting
spec.format=f.format
spec.samples=f.samples
spec.ilines=f.ilines
spec.xline=f.xlines
spec.tracecount=f.tracecount
with segyio.create('2M2.sgy', spec) as dst:
dst.mmap()
dst.text[0]= f.text[0]
dst.bin=f.bin
dst.header=f.header
dst.trace=traces
dst.close()
print('End', 'Full calculation time', "--- %s seconds ---" % (time.time() - start_time))`
My code include module segyio My document .sgy, which I should to process, contains 107591 traces and 2501 values per trace in format "float32". I should to process input sgy file and write new processed sgy file. How can I speed up my code? Maybe I should to use jit or Cython, but I don't know how. Time of calculation this code around 4-5 hours, it so long.
`> import segyio