{"id":9997,"library":"obspy","title":"ObsPy","description":"ObsPy is an open-source Python framework for seismological observatories, providing tools for data acquisition, processing, and analysis. It is designed to work with various seismological data formats and interact with data centers. The current stable version is 1.5.0, with new releases typically occurring a few times per year, focusing on bug fixes, performance improvements, and new features.","status":"active","version":"1.5.0","language":"en","source_language":"en","source_url":"https://github.com/obspy/obspy","tags":["seismology","geophysics","data analysis","signal processing","time series","seismic data"],"install":[{"cmd":"pip install obspy","lang":"bash","label":"Basic installation"},{"cmd":"conda install -c conda-forge obspy","lang":"bash","label":"Recommended for full functionality"}],"dependencies":[{"reason":"Required for plotting functionality (e.g., `Stream.plot()`, `Trace.plot()`).","package":"matplotlib","optional":true},{"reason":"Required for reading/writing StationXML metadata.","package":"lxml","optional":true},{"reason":"Core dependency for signal processing functions.","package":"scipy","optional":false},{"reason":"Core dependency for numerical operations and data arrays.","package":"numpy","optional":false}],"imports":[{"symbol":"read","correct":"from obspy import read"},{"note":"While `from obspy import Stream` works via internal aliases, `from obspy.core import Stream` is the canonical path and clarifies its origin.","wrong":"from obspy import Stream","symbol":"Stream","correct":"from obspy.core import Stream"},{"note":"Similar to `Stream`, `from obspy.core import Trace` is the canonical path.","wrong":"from obspy import Trace","symbol":"Trace","correct":"from obspy.core import Trace"},{"symbol":"UTCDateTime","correct":"from obspy import UTCDateTime"},{"note":"Many signal processing utilities were reorganized or moved to `obspy.signal.filter` in ObsPy 1.1.0. Check `obspy.signal` documentation for specific function locations.","wrong":"from obspy.signal.util import filter_function","symbol":"filter","correct":"from obspy.signal.filter import filter_function"}],"quickstart":{"code":"from obspy import read, UTCDateTime\nimport os\n\n# ObsPy often requires C-compiled dependencies for full functionality and speed.\n# It is highly recommended to install via Anaconda/Miniconda: \n# conda install -c conda-forge obspy\n\n# Example: Reading a MiniSEED file from a URL\ntry:\n    # This URL provides a small example MiniSEED file.\n    # For local files, replace with your path: st = read(\"path/to/your/file.mseed\")\n    st = read(\"https://examples.obspy.org/BW.KW1..EHZ.D.2010.010.mseed\")\n    print(f\"\\nSuccessfully loaded stream: {st}\")\n    \n    # Accessing the first trace in the stream\n    trace = st[0]\n    print(f\"First trace metadata: {trace.stats}\")\n    print(f\"Start time: {trace.stats.starttime}, End time: {trace.stats.endtime}\")\n    print(f\"Sampling rate: {trace.stats.sampling_rate} Hz\")\n    print(f\"Number of samples: {trace.stats.npts}\")\n    \n    # Accessing the data array (NumPy array)\n    print(f\"First 5 data points: {trace.data[:5]}\")\n    \n    # Apply a basic filter (requires scipy)\n    st.filter('lowpass', freq=0.5)\n    print(f\"\\nStream after lowpass filter: {st}\")\n    \n    # For plotting, matplotlib is required:\n    # try:\n    #     st.plot()\n    #     print(\"Plot generated (if matplotlib installed).\")\n    # except ImportError:\n    #     print(\"Install 'matplotlib' (pip install matplotlib) to enable plotting.\")\n\nexcept Exception as e:\n    print(f\"\\nFailed to read example data. Error: {e}\")\n    print(\"Please ensure you have an active internet connection or try a local file.\")\n    # Fallback to creating a dummy stream if download fails\n    from obspy.core import Stream, Trace\n    import numpy as np\n    \n    print(\"Creating a dummy stream for demonstration...\")\n    UTC_DT = UTCDateTime(\"2023-01-01T00:00:00.000Z\")\n    stats = {'network': 'XX', 'station': 'DUM', 'location': '00',\n             'channel': 'BHZ', 'starttime': UTC_DT, 'delta': 0.01,\n             'sampling_rate': 100.0, 'npts': 1000}\n    dummy_trace = Trace(data=np.random.rand(stats['npts']), header=stats)\n    dummy_st = Stream([dummy_trace])\n    print(f\"Dummy stream created: {dummy_st}\")","lang":"python","description":"This quickstart demonstrates how to read seismic data using `obspy.read()`, access `Stream` and `Trace` objects, and perform a basic filter operation. It also includes error handling for network issues and creates a dummy stream if needed. Note that plotting functionality requires the `matplotlib` library."},"warnings":[{"fix":"Use `conda install -c conda-forge obspy` in a Conda environment. If using `pip`, ensure all necessary system libraries (e.g., FFTW, HDF5, LAPACK/BLAS) are available and correctly linked for performance-critical components.","message":"ObsPy has many underlying C/Fortran dependencies for performance and specific data formats. While `pip install obspy` works, for a robust and fully-featured installation, especially on Windows or macOS, `conda install -c conda-forge obspy` is strongly recommended by the developers to handle these compiled dependencies smoothly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `matplotlib` separately: `pip install matplotlib` or `conda install matplotlib`.","message":"Plotting capabilities in ObsPy (e.g., `Stream.plot()`, `Trace.plot()`) rely on `matplotlib`. If `matplotlib` is not installed, these methods will raise an `ImportError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment is version 3.8 or higher. If you have legacy code, consider migrating to Python 3 or using an older ObsPy version (not recommended).","message":"ObsPy dropped support for Python 2.x starting with version 1.1.0. Current versions (1.5.0+) require Python 3.8 or newer. Attempting to use ObsPy 1.1.0+ with Python 2.x will result in syntax errors or `ModuleNotFoundError`.","severity":"breaking","affected_versions":"1.1.0+"},{"fix":"Consult the ObsPy documentation for the specific function you are using. Update import paths according to the new module structure (e.g., `from obspy.signal.util import some_func` might become `from obspy.signal.array_util import some_func`).","message":"Many utility functions within `obspy.signal` were reorganized or moved in ObsPy 1.1.0. For example, some functions previously in `obspy.signal.util` might now be in `obspy.signal.array_util` or `obspy.signal.filter`.","severity":"breaking","affected_versions":"1.1.0+"},{"fix":"Convert all time strings or `datetime` objects to `obspy.UTCDateTime` instances before assigning them to `Trace.stats.starttime` or using them in ObsPy functions. E.g., `from obspy import UTCDateTime; starttime = UTCDateTime('2023-01-01T00:00:00Z')`.","message":"Always use `obspy.UTCDateTime` for handling time and dates within ObsPy to avoid common pitfalls with timezones, precision, and comparisons that can arise from using Python's native `datetime` objects directly with seismic data structures.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install ObsPy using `pip install obspy` or `conda install -c conda-forge obspy`.","cause":"The ObsPy library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'obspy'"},{"fix":"Install `matplotlib` in your environment: `pip install matplotlib` or `conda install matplotlib`.","cause":"Attempting to use plotting methods (e.g., `Stream.plot()`) without `matplotlib` installed.","error":"ImportError: No module named 'matplotlib'"},{"fix":"Double-check the file path and filename. Ensure the file exists and the path is absolute or correct relative to your script's working directory. Use `os.path.exists('myfile.mseed')` to verify.","cause":"The `obspy.read()` function cannot find the specified file, likely due to an incorrect file path, a misspelled filename, or the file not existing at the given location.","error":"IOError: [Errno 2] No such file or directory: 'myfile.mseed'"},{"fix":"Explicitly convert `UTCDateTime` objects to strings using `str()` or `strftime()` before concatenating them with other strings, e.g., `print('Time: ' + str(my_datetime))`.","cause":"Attempting to concatenate a string and an `obspy.UTCDateTime` object without explicitly converting the `UTCDateTime` to a string first.","error":"TypeError: unsupported operand type(s) for +: 'str' and 'UTCDateTime'"},{"fix":"Consult the ObsPy documentation (docs.obspy.org) for the version you are using to find the correct method name or its new location. This often occurs when migrating code from older ObsPy versions (pre-1.0) or when specific functions were refactored into submodules.","cause":"Attempting to use an API method that has been removed, renamed, or moved to a different module in a newer ObsPy version.","error":"AttributeError: 'Stream' object has no attribute 'some_method_from_old_version'"}]}