# 30. Cross Correlation Pick Correction

This example shows how to align the waveforms of phase onsets of two earthquakes in order to correct the original pick times that can never be set perfectly consistent in routine analysis. A parabola is fit to the concave part of the cross correlation function around its maximum, following the approach by [Deichmann1992].

To adjust the parameters (i.e. the used time window around the pick and the filter settings) and to validate and check the results the options plot and filename can be used to open plot windows or save the figure to a file.

See the documentation of `xcorr_pick_correction()` for more details.

The example will print the time correction for pick 2 and the respective correlation coefficient and open a plot window for correlations on both the original and preprocessed data:

    No preprocessing:
      Time correction for pick 2: -0.014459
      Correlation coefficient: 0.92
    Bandpass prefiltering:
      Time correction for pick 2: -0.013025
      Correlation coefficient: 0.98

    from __future__ import print_function

    import obspy
    from obspy.signal.cross_correlation import xcorr_pick_correction

    # read example data of two small earthquakes
    path = "https://examples.obspy.org/BW.UH1..EHZ.D.2010.147.%s.slist.gz"
    st1 = obspy.read(path % ("a", ))
    st2 = obspy.read(path % ("b", ))
    # select the single traces to use in correlation.
    # to avoid artifacts from preprocessing there should be some data left and
    # right of the short time window actually used in the correlation.
    tr1 = st1.select(component="Z")[0]
    tr2 = st2.select(component="Z")[0]
    # these are the original pick times set during routine analysis
    t1 = obspy.UTCDateTime("2010-05-27T16:24:33.315000Z")
    t2 = obspy.UTCDateTime("2010-05-27T16:27:30.585000Z")

    # estimate the time correction for pick 2 without any preprocessing and open
    # a plot window to visually validate the results
    dt, coeff = xcorr_pick_correction(t1, tr1, t2, tr2, 0.05, 0.2, 0.1, plot=True)
    print("No preprocessing:")
    print("  Time correction for pick 2: %.6f" % dt)
    print("  Correlation coefficient: %.2f" % coeff)
    # estimate the time correction with bandpass prefiltering
    dt, coeff = xcorr_pick_correction(t1, tr1, t2, tr2, 0.05, 0.2, 0.1, plot=True,
                                      filter="bandpass",
                                      filter_options={'freqmin': 1, 'freqmax': 10})
    print("Bandpass prefiltering:")
    print("  Time correction for pick 2: %.6f" % dt)
    print("  Correlation coefficient: %.2f" % coeff)

(Source code)

(png, hires.png)

(png, hires.png)

### 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)