python – How to combine waveform data file (.mseed)?

I am using Obspy a python package to download the earthquake data on hourly basis. Obspy package, download 3 files for each hour with same name except the component N, E, Z. For example: 6D.ABR8..HHN__20041201T000001Z__20041201T060001Z.mseed 6D.ABR8..HHE__20041201T000001Z__20041201T060001Z.mseed 6D.ABR8..HHZ__20041201T000001Z__20041201T060001Z.mseed

I used the following script to merge these files:

import obspy
input_fnames = [f"6D.ABR8..HH{c}__20041201T000001Z.mseed" for c in list("ENZ")]
output_fname = "combined.mseed"

traces = []
for file in input_fnames:
  stream = obspy.read(file)
  traces.append(stream[0])
combined = obspy.Stream(traces)
combined.write(output_fname, format="MSEED")  


May someone suggest me how I can to modify this script for bulk of data with different files names.

Example file names and expected output file names are as as follows:

#First set of files
6D.ABR8..HHN__20041201T000001Z__20041201T060001Z.mseed 6D.ABR8..HHE__20041201T000001Z__20041201T060001Z.mseed 6D.ABR8..HHZ__20041201T000001Z__20041201T060001Z.mseed

#expected output
6D.ABR8.__20041201T000001Z__20041201T060001Z.mseed 

#second set of files
6D.ASR8..HHN__20061201T000001Z__20061201T060001Z.mseed 6D.ASR8..HHE__20061201T000001Z__20061201T060001Z.mseed 6D.ASR8..HHZ__20061201T000001Z__20061201T060001Z.mseed
#expected output
6D.ASR8.__20061201T000001Z__20061201T060001Z.mseed

# third set of files
6D.YAR8..HHN__20081201T000001Z__20081201T060001Z.mseed 6D.YAR8..HHE__20081201T000001Z__20081201T060001Z.mseed 6D.YAR8..HHZ__20081201T000001Z__20081201T060001Z.mseed
# expected output
#6D.YAR8.__20081201T000001Z__20081201T060001Z.mseed

Thank you!

Read more here: Source link