Chapter 5 Data folder structure
To use the waveform archive for the moment tensor computations using Grond we need to reorganise the data for the Grond project specifics, which will be described in details in Chapter 8.
After the waveform download, Squirrel created the following folder structures:
Year/
-- Network/
-- Station/
-- Component/
network.station.location.component.year.julian_date.mseed
For Grond we need to put all the waveform files into one folder to create the following layout:
Event_year_month_day/
-- Waveforms/
network.station.location.component.year.julian_date.mseed
To reorganise the folders use the script Reorganise_folders_4_grond.ipynb.
First, we load the required libraries:
import os
import glob, shutil
import datetime
Change rootdir to the path to the original archive created by Squirrel and set the folder name and path for the reorganised folders:
# set the path for the waveform archive
rootdir = '/Users/localadmin/SHARPSeisTools/05_reorganise_folders/waveform_archive'
#set the path for the reorganised archive
work_dir=os.getcwd()
data_dir ="waveform_archieve_grond"
data_path=os.path.join(work_dir,data_dir)
try:
os.mkdir(data_path)
print("The new data directory is created!")
except FileExistsError:
print("The directory already exists")
# directory already exists
pass
Reorganise the miniSEED files to a different folder structure by running the following code:
for subdir, dirs, files in os.walk(rootdir):
for file in files:
file_path= os.path.join(subdir, file)
new_dir = 'event_'+file[len(file)-8:]
if not "DS_Store" in file:
string=file[len(file)-8:]
year=int(string.split(".")[0])
days=int(string.split(".")[1])
date=datetime.date(year, 1, 1) + datetime.timedelta(days - 1)
new_dir = 'event_'+str(date)
try:
os.mkdir(os.path.join(data_path,new_dir))
except FileExistsError:
print("The directory already exists")
pass
waveforms_dir="waveforms"
waveforms_path=os.path.join(data_path,new_dir,waveforms_dir)
try:
os.mkdir(waveforms_path)
except FileExistsError:
print("The directory already exists")
# directory already exists
pass
shutil.move(file_path, os.path.join(waveforms_path))