austinholland / PhasePApy

Python Seismic Phase Picker and Associator
88 stars 46 forks source link

QuakeML #12

Open shicks-seismo opened 7 years ago

shicks-seismo commented 7 years ago

Hi Austin

Do you have any plans to export picks and locations (from the associator) into QuakeML format?

Thanks, Steve

austinholland commented 7 years ago

That is something that could occur down the road. I will leave this issue open.

shicks-seismo commented 7 years ago

Hi Austin,

I managed to figure this out in the end. Feel free to use / adapt.

# Import required modules and set-up arrays
from obspy.core.event import Catalog, Event, Pick, CreationInfo, \
                             WaveformStreamID
creation_string = CreationInfo(agency_id = "soton", \
                               agency_uri = "smi:de.erdbeben-in-bayern/agency", \
                               creation_time = UTCDateTime.now(), \
                               version = "ObsPyck 0.4.1.post0, \
                               ObsPy 1.0.2", author = "sph1r17")
catalog = Catalog()
catalog.creation_info = creation_string
event = Event()
event.creation_info = creation_string

..... run picker ....

                # Add picks to event (for xml file)
                for j in range(len(picks)):

                # Prepare pick->event hierachy for obspy xml output
                    stream_id = WaveformStreamID(network_code = network, \
                                station_code = stations[n_sta], \
                                location_code = "", \
                                channel_code = channels[n_cha][0:3])
                    pick = Pick(time = picks[j], waveform_id = stream_id, \
                                phase_hint = "P", \
                                creation_info = creation_string)
                    event.picks.append(pick)

# Write QuakeML file
catalog.append(event)
catalog.write("example.xml", format="QUAKEML")