1 line
5.7 KiB
Plaintext
1 line
5.7 KiB
Plaintext
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["<div style='background-image: url(\"../share/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 flows and to share them with other researchers in the de facto standard format QuakeML"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from obspy import UTCDateTime\n", "from obspy.core.event import Catalog, Event, Origin, Magnitude\n", "from obspy.geodetics import FlinnEngdahl\n", "\n", "cat = Catalog()\n", "cat.description = \"Just a fictitious toy example catalog built from scratch\"\n", "\n", "e = Event()\n", "e.event_type = \"not existing\"\n", "\n", "o = Origin()\n", "o.time = UTCDateTime(2014, 2, 23, 18, 0, 0)\n", "o.latitude = 47.6\n", "o.longitude = 12.0\n", "o.depth = 10000\n", "o.depth_type = \"operator assigned\"\n", "o.evaluation_mode = \"manual\"\n", "o.evaluation_status = \"preliminary\"\n", "o.region = FlinnEngdahl().get_region(o.longitude, o.latitude)\n", "\n", "m = Magnitude()\n", "m.mag = 7.2\n", "m.magnitude_type = \"Mw\"\n", "\n", "m2 = Magnitude()\n", "m2.mag = 7.4\n", "m2.magnitude_type = \"Ms\"\n", "\n", "# also included could be: custom picks, amplitude measurements, station magnitudes,\n", "# focal mechanisms, moment tensors, ...\n", "\n", "# make associations, put everything together\n", "cat.append(e)\n", "e.origins = [o]\n", "e.magnitudes = [m, m2]\n", "m.origin_id = o.resource_id\n", "m2.origin_id = o.resource_id\n", "\n", "print(cat)\n", "cat.write(\"/tmp/my_custom_events.xml\", format=\"QUAKEML\")\n", "!cat /tmp/my_custom_events.xml"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}}, "nbformat": 4, "nbformat_minor": 2} |