implentment FFT function
This commit is contained in:
parent
8f1383f550
commit
759f772976
55
Analyser/FFTAnalyser.py
Normal file
55
Analyser/FFTAnalyser.py
Normal file
@ -0,0 +1,55 @@
|
||||
import xarray as xr
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import xrft
|
||||
import finufft
|
||||
|
||||
|
||||
class FFTAnalyser():
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def fft(self, dataArray, **kwargs):
|
||||
return xrft.fft(dataArray, **kwargs)
|
||||
|
||||
def ifft(self, dataArray, **kwargs):
|
||||
return xrft.ifft(dataArray, **kwargs)
|
||||
|
||||
def fft_nutou(self, dataArray, modeNum):
|
||||
|
||||
data = dataArray.to_numpy()
|
||||
data = data.astype('complex128')
|
||||
|
||||
time = dataArray[dataArray.dims[0]].to_numpy()
|
||||
|
||||
if isinstance(time[0], type(np.datetime64(500,'s'))):
|
||||
time = time.astype(float)
|
||||
time = time - time[0]
|
||||
freqUpLim = 1 / np.min(np.abs(time - np.roll(time, 1))) * 1e9
|
||||
else:
|
||||
time = time.astype(float)
|
||||
time = time - time[0]
|
||||
freqUpLim = 1 / np.min(np.abs(time - np.roll(time, 1)))
|
||||
|
||||
print(freqUpLim)
|
||||
|
||||
time = time / time.max() * 2 * np.pi
|
||||
|
||||
# calculate the transform
|
||||
res = xr.DataArray(
|
||||
data=finufft.nufft1d1(time, data, modeNum),
|
||||
dims=['freq'],
|
||||
coords={
|
||||
"freq":np.linspace(-freqUpLim/2, freqUpLim/2, modeNum)
|
||||
}
|
||||
)
|
||||
|
||||
return res
|
||||
|
||||
def ifft_nutou(self, dataArray, modeNum):
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user