Chapter 7 Event files
An event file comprise of information on preliminary time, origin location and sometimes a reference mechanism attached to it.
7.1 Make event files
For the creation of the event files, we will use a CSV file (NS_primes_M3.5_1990.csv), which contains the extracted time of the event, coordinates of the hypocentre (latitude, longitude), magnitude, and depth from the information listed in the newly created North Sea catalogue (NS_in_poly_excluded_explosions_v4_cleaned.isf).
Figure 7.1: A short summary with the information on event hypocentre (latitude, longitude), magnitude and depth extracted from the North Sea catalogue.
Using script 01_Make_event_files.ipynb, we can create event files for all events listed in the previous table.
Activate the environment using:
conda activate gmtobsrocko
Then open Jupyter Notebook using Jupyter Lab by typing in a command line:
jupyter lab
and then opening the corresponding ipynb file.
First, we will import the required Python libraries:
import os
import pandas as pd
from obspy.core import UTCDateTime
import math
Next, we are going to set the name of the directory for the events file and the path to the table containing the extracted information from the North sea catalogue (NS_primes_M3.5_1990.csv) and read the table into Pandas data frame:
#set the current working directory
work_dir=os.getcwd()
#set the directory for the event files
events_dir="event_files"
events_path=os.path.join(work_dir,events_dir)
#check whether the directory exists and if not, create it
try:
os.mkdir(events_path)
print("The new data directory is created!")
except FileExistsError:
print("The directory already exists")
pass
#set a path to the table with information form the North Sea catalogue
Earthquake_list = "NS_primes_M3.5_1990.csv"
Earthquake_list_path = os.path.join(work_dir,Earthquake_list)
# read a csv file into a pandas dataframe
colnames=['Time','lat','lon','depth','ML','Mw','Mb','Md','Ms','Mc','OrigID','catID']
Earthquake_list_df= pd.read_csv(Earthquake_list_path,header=None,names=colnames,skiprows=[0])
Earthquake_list_df=Earthquake_list_df.rename(columns=lambda x: x.strip())
Make event files by running the following cell:
for index_1, row_1 in Earthquake_list_df.iterrows():
file_name=row_1['event_name']
file_complete_name=os.path.join(events_dir, file_name)
time=UTCDateTime(row_1['Time']).time
date=UTCDateTime(row_1['Time']).date
if math.isnan(row_1['depth']):
depth = row_1['depth']
else:
depth = int(row_1['depth'])
#if the depth is 0, then it is substituted with a default 10 km value
if depth == 0:
depth = 10
with open(file_complete_name, 'w+') as f:
f.write("name = " + row_1['event_name'] + "\n")
f.write("time = " + str(date) + " " + str(time) + "\n")
f.write("latitude = "+ str("{:.2f}".format(row_1['lat']))+ "\n")
f.write("longitude = "+ str("{:.2f}".format(row_1['lon']))+ "\n")
f.write("magnitude = "+ str("{:.2f}".format(row_1['ML']))+ "\n")
f.write("depth = "+ str(depth*1000)+ "\n")
f.write("--------------------------------------------")
An example of such file can be found below:
name = event_2022-03-25_04-56-36
time = 2022-03-25 04:56:36.760000
latitude = 58.45
longitude = 1.69
magnitude = 3.40
depth = 10
--------------------------------------------
In addition to mandatory fields such as the time of the event, coordinates of the hypocentre (latitude, longitude), magnitude, and depth, a previously known reference moment tensor solution can also be included.
name = gfz2022fots
time = 2022-03-21 05:32:56.440
latitude = 61.53
longitude = 2.53
magnitude = 5.24
moment = 8.12831e+16
depth = 25000
mnn = 5.8e+15
mee = -9.06e+16
mdd = 8.48e+16
mne = 3.8e+15
mnd = 1.92e+16
med = -1.23e+16
strike1 = 14.4797
dip1 = 50.5574
rake1 = 106.183
strike2 = 169.929
dip2 = 42.1267
rake2 = 71.2844
--------------------------------------------