{"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install obspy"],"cli":null},"imports":["from obspy import read","from obspy.core import Stream","from obspy.core import Trace","from obspy import UTCDateTime","from obspy.signal.filter import filter_function"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}