DataAnalysis2022/ObsPy/05_Event_metadata.ipynb

2 lines
5.5 KiB
Plaintext
Raw Normal View History

2024-06-10 12:15:28 +02:00
{"cells":[{"cell_type":"markdown","metadata":{},"source":["<div style='background-image: url(\"../images/header.svg\") ; padding: 0px ; background-size: cover ; border-radius: 5px ; height: 250px'>\n"," <div style=\"float: right ; margin: 50px ; padding: 20px ; background: rgba(255 , 255 , 255 , 0.7) ; width: 50% ; height: 150px\">\n"," <div style=\"position: relative ; top: 50% ; transform: translatey(-50%)\">\n"," <div style=\"font-size: xx-large ; font-weight: 900 ; color: rgba(0 , 0 , 0 , 0.8) ; line-height: 100%\">ObsPy Tutorial</div>\n"," <div style=\"font-size: large ; padding-top: 20px ; color: rgba(0 , 0 , 0 , 0.5)\">Handling Event Metadata</div>\n"," </div>\n"," </div>\n","</div>"]},{"cell_type":"markdown","metadata":{},"source":["Seismo-Live: http://seismo-live.org\n","\n","##### Authors:\n","* Lion Krischer ([@krischer](https://github.com/krischer))\n","* Tobias Megies ([@megies](https://github.com/megies))\n","---"]},{"cell_type":"markdown","metadata":{},"source":["![](images/obspy_logo_full_524x179px.png)"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["%matplotlib inline\n","import matplotlib.pyplot as plt\n","plt.style.use('ggplot')\n","plt.rcParams['figure.figsize'] = 12, 8"]},{"cell_type":"markdown","metadata":{},"source":["- for event metadata, the de-facto standard is [QuakeML (an xml document structure)](https://quake.ethz.ch/quakeml/)\n","- QuakeML files can be read using **`read_events()`**"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["from obspy import read_events\n","\n","catalog = read_events(\"./data/event_tohoku_with_big_aftershocks.xml\")\n","print(catalog)"]},{"cell_type":"markdown","metadata":{},"source":["- **`read_events()`** function returns a **`Catalog`** object, which is\n","a collection of **`Event`** objects."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["print(type(catalog))\n","print(type(catalog[0]))"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["event = catalog[0]\n","print(event)"]},{"cell_type":"markdown","metadata":{},"source":["- Event objects are again collections of other resources.\n","- the nested ObsPy Event class structure (Catalog/Event/Origin/Magnitude/FocalMechanism/...) is closely modelled after QuakeML\n","<img src=\"images/Event.svg\" width=90%>"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["print(type(event.origins))\n","print(type(event.origins[0]))\n","print(event.origins[0])"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["print(type(event.magnitudes))\n","print(type(event.magnitudes[0]))\n","print(event.magnitudes[0])"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# try event.<Tab> to get an idea what \"children\" elements event has"]},{"cell_type":"markdown","metadata":{},"source":["- The Catalog object contains some convenience methods to make\n","working with events easier.\n","- for example, the included events can be filtered with various keys."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["largest_magnitude_events = catalog.filter(\"magnitude >= 7.8\")\n","print(largest_magnitude_events)"]},{"cell_type":"markdown","metadata":{},"source":["- There is a basic preview plot using the matplotlib basemap module."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["catalog.plot(projection=\"local\");"]},{"cell_type":"markdown","metadata":{},"source":["- a (modified) Catalog can be output to file (currently there is write support for QuakeML only)"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["largest_magnitude_events.write(\"/tmp/large_events.xml\", format=\"QUAKEML\")\n","!ls -l /tmp/large_events.xml"]},{"cell_type":"markdown","metadata":{},"source":["- the event type classes can be used to build up Events/Catalogs/Picks/.. from scratch in custom processing work