How to read .txt files in obspy?

Good afternoon, I am a beginner using the Obspy library and I hope you can help me. I need to create a spectrogram from a txt file in which I have two columns. The first column contains data for time (sec) and the second column contains data for acceleration (cm / sec2). Is it possible to read this file using obspy?

Hi, just try it out. If ObsPy cannot read the file you have to load it in another way (e.g. with numpy) or parse it on your own. With the data at hand you can create Traces and Streams from scratch. Please check out the docs.

Dear @edemqs,

The first step will be related to read the data using numpy, as an example I share some code.

import os
import numpy as np
import matplotlib.pyplot as plt
from itertools import islice

with open(Z, 'r') as z:
    for line in itertools.islice(z, 112, None):  # 112 Skip headers in case of SCM format
        z = [x.strip() for x in z if x.strip()]
        z_ = [tuple(map(float,x.split())) for x in z[1:]]
        T_z = [x[0] for x in z_] # time
        A_z = [x[1] for x in z_] # amplitude

axis_font = {'fontname':'Arial', 'size':'9'}


ax1 = fig.add_axes([0.13, 0.65, 0.85, 0.40]) #[left down width high]
ax1.plot(T_z, A_z, 'r')
ax1.set_ylabel('[C]', **axis_font)

And then you need to create a Stream() to keep working with Obspy

Stay safe