Reading GSE bulletin

Dear all,
I have been trying to work with a GSE2.0 seismic bulletin, I was trying to obtain the information of each variable (lat, lon, depth, mag, sminor, smajor, az) from each seismic events headers.

I read the documents https://docs.obspy.org/packages/autogen/obspy.io.gse2.bulletin._read_gse2.html#obspy.io.gse2.bulletin._read_gse2.

And I try the code to save the variables on dataframes to do some statistics :

year = 2000
fields = {

    'line_1': {
        
        'Date': slice(1, 11),
        
        'Time': slice(12, 22),
        
        'Latitude': slice(26, 34),
        
        'Longitude': slice(36, 44),
        
        'Depth': slice(48, 53),
        
        'Gap': slice(67, 70),
        
        'Mag1': slice(75, 78),

    },

    'line_2': {
        
        'rms': slice(7, 11),

        'az': slice(40, 46),
        
        'Smajor': slice(26, 34),
        
        'Sminor': slice(35, 39),


    },

    'arrival': {

        'Sta': slice(1, 5),
        
        'Phase': slice(24, 28),

    },

}

catalog = read_events(r'D:\Inves\Catalogs\OSC\GSE_OSC/'+year+'.txt', fields = fields)

sta = []
times = []
lats = []
lons = []
deps = []
magnitudes = []
magnitudestype = []
for event in catalog:
    if len(event.origins) != 0 and len(event.magnitudes) != 0:
        times.append(event.origins[0].time.datetime)
        lats.append(event.origins[0].latitude)
        lons.append(event.origins[0].longitude)
        deps.append(event.origins[0].depth/1000)
        magnitudes.append(event.magnitudes[0].mag)
        magnitudestype.append(event.magnitudes[0].magnitude_type )
        Smajor.append(event.origins[1].Smajor)        

However I got th error if I want to obtain the values from the 2nd line header (Smajorm Sminor, rms, az):


Traceback (most recent call last):

  File "C:\Users\Director\AppData\Local\Temp/ipykernel_16064/4187544156.py", line 62, in <module>
    Smajor.append(event.origins[1].Smajor)

IndexError: list index out of range

Would you mid please give a hand to improve the code to save the information from Smajor, Sminor, az, gap fields from the GSE2.0 seismic bulletin.

I must say that values from the first line of the header I was able to obtain.

Stay safe and best regards,
Tonino

I dont work with GSE2 bulletin, and I dont know your data but this event doesn’t have origins in it.
print(event)

@megies, Just in case I send the exmample and the code modified to run the example,


import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
from matplotlib import cm
from obspy import read_events

os.chdir(r'D:\Inves\Catalogs\OSC\GSE_OSC')

year = '2017_input.txt'


fields = {

    'line_1': {
        
        'Date': slice(1, 11),
        
        'Time': slice(12, 22),
        
        'Latitude': slice(26, 34),
        
        'Longitude': slice(36, 44),
        
        'Depth': slice(48, 53),
        
        'Gap': slice(67, 70),
        
        'Mag1': slice(75, 78),

    },

    'line_2': {
        
        'rms': slice(7, 11),

        'az': slice(40, 46),
        
        'Smajor': slice(26, 34),
        
        'Sminor': slice(35, 39),


    },

    'arrival': {

        'Sta': slice(1, 5),
        
        'Phase': slice(24, 28),

    },

}


catalog = read_events(year, fields = fields)

sta = []
times = []
lats = []
lons = []
deps = []
magnitudes = []
magnitudestype = []
Smajor = []
for event in catalog:
    if len(event.origins) != 0 and len(event.magnitudes) != 0:
        times.append(event.origins[0].time.datetime)
        lats.append(event.origins[0].latitude)
        lons.append(event.origins[0].longitude)
        deps.append(event.origins[0].depth/1000)
        magnitudes.append(event.magnitudes[0].mag)
        magnitudestype.append(event.magnitudes[0].magnitude_type )
        Smajor.append(event.origins[1].Smajor)
        
df = pd.DataFrame({'time':times,'lat':lats,'lon':lons,'depth':deps,
                   'mag':magnitudes,'type':magnitudestype})
df.sort_values(by=['time'])

2017_input.txt (26.6 KB)

I think this would be a nice example for labs that keep working with GSE2.0 format seismic bulletins
Thanks,
Tonino

Two things:

  1. you probably meant Smajor.append(event.origins[0].Smajor) (0 not 1) thats why the index error

  2. these fields seem to be hard coded stuff, I think your Smajor is never used or regarded, it’s not dynamic but hard coded items you can use there looks like, never used GSE2 bulletin or that code we have there

https://docs.obspy.org/master/_modules/obspy/io/gse2/bulletin.html?highlight=fields

@megies, Thanks for the webpage information, I will figure it out how I solve it.
Stay safe,
Tonino