# obspy.core.util.testing.ImageComparison

class `ImageComparison`(image_path, image_name, reltol=1, adjust_tolerance=True, plt_close_all_enter=True, plt_close_all_exit=True, style=None, no_uploads=False, *args, **kwargs)

  Bases: `obspy.core.util.base.NamedTemporaryFile`

  Handles the comparison against a baseline image in an image test.

  Note

  Baseline images are created using matplotlib version 1.3.1.

  Parameters: | image_path (str) Path to directory where the baseline image is located image_name (str) Filename (with suffix, without directory path) of the baseline image reltol (float, optional) Multiplier that is applied to the default tolerance value (i.e. 10 means a 10 times harder to pass test tolerance). adjust_tolerance (bool, optional) Adjust the tolerance based on the matplotlib version. Can optionally be turned off to simply compare two images. plt_close_all_enter (bool) Whether to close all open figures when entering context (`matplotlib.pyplot.close()` with “all” as first argument. plt_close_all_exit (bool) Whether to call `matplotlib.pyplot.close()` with “all” as first argument (close all figures) or no arguments (close active figure). Has no effect if `plt_close=False`. style (str) The Matplotlib style to use to generate the figure. When using matplotlib 1.5 or newer, the default will be `'classic'` to ensure compatibility with older releases. On older releases, the default will leave the style as is. You may wish to set it to `'default'` to enable the new style from Matplotlib 2.0, or some alternate style, which will work back to Matplotlib 1.4.0. no_uploads (bool) If set to `True` no uploads to imgur are attempted, no matter what (e.g. any options to `obspy-runtests` that would normally cause an upload attempt). This can be used to forcibly deactivate upload attempts in image tests that are expected to fail.

  The class should be used with Python’s “with” statement. When setting up, the matplotlib rcdefaults are set to ensure consistent image testing. After the plotting is completed, the `ImageComparison.compare()` method is called automatically at the end of the “with” block, comparing against the previously specified baseline image. This raises an exception (if the test fails) with the message string from `matplotlib.testing.compare.compare_images()`. Afterwards all temporary files are deleted automatically.

  Note

  If images created during the testrun should be kept after the test, set environment variable OBSPY_KEEP_IMAGES to any value before executing the test (e.g. with $ OBSPY_KEEP_IMAGES= obspy-runtests or $ OBSPY_KEEP_IMAGES= python test_sometest.py). For obspy-runtests the option “keep-images” can also be used instead of setting an environment variable. Created images and diffs for failing tests are then stored in a subfolder “testrun” under the baseline image’s directory. To only keep failed images and the corresponding diff image, additionally set environment variable OBSPY_KEEP_ONLY_FAILED_IMAGES to any value before executing the test.

  Example

      >>> from obspy import read
      >>> with ImageComparison("/my/baseline/folder", 'plot.png') as ic:
      ...     st = read()
      ...     st.plot(outfile=ic.name)
      ...     # image is compared against baseline image automatically

  Attributes

  `__abstractmethods__` | frozenset() -> empty frozenset object
  `__dict__` |
  `__doc__` | str(object=’‘) -> str
  `__module__` | str(object=’‘) -> str
  `closed` |

  Public Methods

  `close` |
  `compare` | Run a custom version
  `detach` | Disconnect this buffer from its underlying raw stream and return it.
  `fileno` | Returns underlying file descriptor if one exists.
  `flush` | Flush write buffers, if applicable.
  `isatty` | Return whether this is an ‘interactive’ stream.
  `read` |
  `read1` | Read and return up to n bytes, with at most one read() call to the underlying raw stream.
  `readable` | Return whether object was opened for reading.
  `readinto` |
  `readline` | Read and return a line from the stream.
  `readlines` | Return a list of lines from the stream.
  `seek` |
  `seekable` | Return whether object supports random access.
  `tell` |
  `truncate` | Truncate file to size bytes.
  `writable` | Return whether object was opened for writing.
  `write` |
  `writelines` |

  Private Methods

  Warning

  Private methods are mainly for internal/developer use and their API might change without notice.

  `_checkClosed` |
  `_checkReadable` |
  `_checkSeekable` |
  `_checkWritable` |
  `_copy_tempfiles` | Copies created images from tempfiles to a subfolder of baseline images.
  `_get_final_filenames` | Helper function returning the
  `_upload_images` | Uploads images to imgur unless explicitly deactivated with option no_uploads (to speed up tests that are expected to fail).

  Special Methods

  `__dir__` | default dir() implementation
  `__enter__` | Set matplotlib defaults.
  `__exit__` | Remove tempfiles and store created images if OBSPY_KEEP_IMAGES
  `__format__` | default object formatter
  `__init__` |
  `__new__` | Create and return a new object.
  `__reduce__` | helper for pickle
  `__reduce_ex__` | helper for pickle
  `__sizeof__` | size of object in memory, in bytes
  `__subclasshook__` | Abstract classes can override this to customize issubclass().

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