Python Forum

Full Version: Python numpy fft from data file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I'm new to Python and I'm not sure. trying to do a python fft with a data file.

It cans plot the data file in the time domain like the code above. set a start time and end time in data.trim to display a plot.

Error in numpy's fft function.

No friendly explanation found on Google or on any site, Noted similar code but got many errors.

Is code simple and is there a simple workaround?

data file type is miniseed(mseed) file.

from obspy import read, UTCDateTime
from numpy as np

def check_file(fname) :

    print("Check : ", fname)

    data = read(fname)
    myS = UTCDateTime("2020-01-06T00:30:00")
    myE = myS + 120
    data.trim(myS, myE)

    ### time domain plot
    data.plot()


    ### test1. frequency domain plot. It is error
    #y = np.fft(data)
    #y.plot()

    ### test2. frequency domain plot. error 2
    #fftdata = np.fft.fft(data)
    #frequ = np.fft.fftfreq(len(fftdata))
    #plt.plot(frequ,fftdata)
    #plt.show()


check_file('data file')
(Feb-06-2020, 01:37 AM)magnet1 Wrote: [ -> ]Hello,
I'm new to Python and I'm not sure. trying to do a python fft with a data file.

It cans plot the data file in the time domain like the code above. set a start time and end time in data.trim to display a plot.

Error in numpy's fft function.

No friendly explanation found on Google or on any site, Noted similar code but got many errors.

Is code simple and is there a simple workaround?



from obspy import read, UTCDateTime
from numpy as np

def check_file(fname) :

    print("Check : ", fname)

    data = read(fname)
    myS = UTCDateTime("2020-01-06T00:30:00")
    myE = myS + 120
    data.trim(myS, myE)

    ### time domain plot
    data.plot()


    ### test1. frequency domain plot. It is error
    #y = np.fft(data)
    #y.plot()

    ### test2. frequency domain plot. error 2
    #fftdata = np.fft.fft(data)
    #frequ = np.fft.fftfreq(len(fftdata))
    #plt.plot(frequ,fftdata)
    #plt.show()


check_file('data file')