# obspy.io.zmap - ZMAP read and write support for ObsPy

This module provides read and write support for the ZMAP format.

copyright: | The ObsPy Development Team (devs@obspy.org)
license: | GNU Lesser General Public License, Version 3 (https://www.gnu.org/copyleft/lesser.html)

## Usage Example

The ZMAP reader and writer hooks into the standard ObsPy event handling mechanisms including format autodetection.

    >>> from obspy.core.event import read_events
    >>> cat = read_events('/path/to/zmap_events.txt')
    >>> print(cat)
    2 Event(s) in Catalog:
    2012-04-04T14:21:42.300000Z | +41.818,  +79.689 | 4.4 None
    2012-04-04T14:21:42.300000Z | +41.822,  +79.684 | 5.1 None
    >>> cat.write('example.txt', format='ZMAP')

## Reading ZMAP

Reading ZMAP is lenient, i.e. `obspy.io.zmap` will try to import a file even if it doesn’t strictly conform to 10 or 13 column ZMAP. Namely the following deviations from standard ZMAP format are acceptable:

- Less or more than 10 or 13 columns. Extra columns are ignored. Missing values are set to `None`.
- Integer years without a fractional part. If the fractional part is present, the date/time is computed from the year column. All other date/time fields are ignored. If the year column is an integer number, date and time are computed from all date/time related fields.

Note that ZMAP format autodetection in `read_events()` only works with strictly 10 or 13 column files. To read non-standard ZMAP files, the `format='ZMAP'` keyword argument must be provided.

When reading ZMAP, the following mappings are used for uncertainties

- Column 11 (Horizontal error): stored in `origin.origin_uncertainty.horizontal_uncertainty` with `preferred_description` set accordingly.
- Column 12 (Depth error): stored in `origin.depth_errors.uncertainty`
- Column 13 (Magnitude error): stored in `magnitude.mag_errors.uncertainty`

## Writing ZMAP

When writing to ZMAP, the preferred origin and magnitude are used to fill the origin and magnitude columns. Any missing values are exported as `'NaN'`.

Extended ZMAP

Writing extended ZMAP, is supported by using the keyword argument `with_uncertainties`.

If `OriginUncertainty` specifies a horizontal uncertainty the value for column 11 is extracted from there. Uncertainty ellipse and confidence ellipsoid are not currently supported. If no horizontal uncertainty is given, `Origin`‘s `latitude_errors` and `longitude_errors` are used instead. Depth and magnitude errors are always read from the respective `_errors` attribute in `Origin`.

## The ZMAP Format

ZMAP is a simple 10 column CSV file (technically TSV) format for basic catalog data. It originates from ZMAP, a Matlab® based earthquake statistics package (see [Wiemer2001]). Since ZMAP files are purely numerical they are easily imported into Matlab® using the `dlmread` function.

Column # | Value
--- | ---
1 | Longitude [deg]
2 | Latitude [deg]
3 | Decimal year (e.g., 2005.5 for July 2nd, 2005)
4 | Month
5 | Day
6 | Magnitude
7 | Depth [km]
8 | Hour
9 | Minute
10 | Second

CSEP (http://www.cseptesting.org) defines an extension to the format to include uncertainties. The extended CSEP format has the following extra columns:

Column # | Value
--- | ---
11 | Horizontal error
12 | Depth error
13 | Magnitude error

## Modules

`core` | ZMAP read/write support.

### Thank you!

We would like to thank our contributors, whose efforts make this software what it is. These people have helped by writing code and documentation, and by testing. They have created and maintained this product, its associated libraries and applications, our build tools and our web sites.

#### Contributors

- Ackerley, Nick
- Allgeyer, Sebastien
- Ammon, Charles J.
- Antunes, Emanuel
- Arnarsson, Ólafur St.
- Bank, Markus
- Barsch, Robert
- Behr, Yannik
- Bernardi, Fabrizio
- Bernauer, Felix
- Bes de Berc, Maxime
- Beyreuther, Moritz
- Boltz, Shawn
- Bonaimé, Sébastien
- Carothers, Lloyd
- Chamberlain, Calum
- Chambers, Derrick
- Chen, Zhao
- Clark, Adam
- Danecek, Peter
- Egdorf, Sven
- Engels, Fabian
- Ermert, Laura
- Eulenfeld, Tom

- Fabbri, Tommaso
- Falco, Nicholas
- Fee, Jeremy
- Grellier, Clément
- Grunberg, Marc
- Hammer, Conny
- Heimann, Sebastian
- Heiniger, Lukas
- Hope, Gaute
- Igel, Heiner
- Inza, Adolfo
- Isken, Marius
- Ketchum, David
- Koymans, Mathijs
- Kremers, Simon
- Kress, Victor
- Krieger, Lars
- Krischer, Lion
- Kula, Damian
- Käufl, Paul
- Köhler, Andreas
- Lecocq, Thomas
- Leeman, John
- Legovini, Paride

- Lesage, Philippe
- Li, Yulin
- Lomax, Anthony
- Lopes, Rui L.
- MacCarthy, Jonathan
- Maggi, Alessia
- Martin, Henri
- Medlin, Andrew
- Megies, Tobias
- Meschede, Matthias
- Michelini, Alberto
- Miller, Nathaniel C.
- Morgenstern, Bernhard
- Nof, Ran Novitsky
- Panning, Mark P.
- Parker, Tom
- Pestourie, Romain
- Rapagnani, Giovanni
- Reyes, Celso
- Ringler, Adam
- Rothenhäusler, Nicolas
- Russo, Emiliano
- Sales de Andrade, Elliott

- Satriano, Claudio
- Saul, Joachim
- Scheingraber, Chris
- Schneider, Simon
- Sippl, Christian
- Snoke, Arthur
- Stange, Stefan
- Stähler, Simon C.
- Sullivan, Benjamin
- Tian, Dongdong
- Trabant, Chad
- Trani, Luca
- Uieda, Leonardo
- Walker, Andrew
- Walther, Marcus
- Wassermann, Joachim
- Williams, Mark C.
- Winkelman, Andrew
- Zaccarelli, Riccardo
- Zad, Seyed Kasra Hosseini
- Zhu, Lijun
- van Driel, Martin
- van Wijk, Kasper

#### Funds

ObsPy was partially funded by the

- German Science Foundation (DFG) via grant DFG IG 16/9-1
- German Ministry for Education and Research (BMBF), GEOTECHNOLOGIEN grant 03G0646H.
- NERA project (Network of European Research Infrastructures for Earthquake Risk Assessment and Mitigation) under the European Community's Seventh Framework Programme (FP7/2007-2013) grant agreement n° 262330
- Leibniz Institute for Applied Geophysics (LIAG)
- VERCE EU-FP7 project (no. 283543)