I got 10 data files which have 24 traces (MASW results).
I need to stack 10 data files and made the code but the append part in the code to stack.
Could you please edit the append part to stack in the code?
Or if you know the way to stack output files in geopsy program, please let me know.
import os
from obspy import read, Stream, Trace
import matplotlib.pyplot as plt
import pandas as pd
path='/path/to/folder/'
Jo_list=os.listdir(path)
stack_format='_stack.dat'
usual_format='.dat'
for jo in Jo_list:
file_list=os.listdir(path+jo)
real_list=[]
#The part to extract file list that I need
for file in file_list:
if file.endswith(usual_format):
real_list+=[file]
if file.endswith(stack_format):
real_list.remove(file)
print(real_list)
stream = read(path+jo+'/'+real_list[0])
new_stream = Stream()
# Loop over each trace in the first file
for i in range(len(stream)):
# Extract the trace data and header information
data = stream[i].data
header = stream[i].stats
# Loop over the remaining files
for j in range(1, len(real_list)):
# Read the file into a Stream object
tmp_stream = read(path+jo+'/'+real_list[j])
# Loop over each trace in the file
for k in range(len(tmp_stream)):
# Check if the header information matches
if tmp_stream[k].stats == header:
# Extract the matching trace data and append it to the data from the first trace
data += tmp_stream[k].data
# Create a new Trace object from the combined data and header information and append it to a new Stream object
new_trace = Trace(data=data, header=header)
new_stream.append(new_trace)
plt.plot(new_stream)
plt.title(jo)
plt.show()