analyseScript/Analyser/FFTAnalyser.py

52 lines
1.1 KiB
Python
Raw Permalink Normal View History

2023-05-19 17:17:57 +02:00
import xarray as xr
import numpy as np
from datetime import datetime
import xrft
import finufft
2023-05-19 17:23:20 +02:00
def fft(dataArray, **kwargs):
return xrft.fft(dataArray, **kwargs)
2023-05-19 17:36:17 +02:00
2023-05-19 17:23:20 +02:00
def ifft(dataArray, **kwargs):
return xrft.ifft(dataArray, **kwargs)
2023-05-19 17:36:17 +02:00
2023-05-19 17:23:20 +02:00
def fft_nutou(dataArray, modeNum, **kwargs):
2023-05-19 17:17:57 +02:00
2023-05-19 17:23:20 +02:00
data = dataArray.to_numpy()
data = data.astype('complex128')
2023-05-19 17:17:57 +02:00
2023-05-19 17:23:20 +02:00
time = dataArray[dataArray.dims[0]].to_numpy()
2023-05-19 17:17:57 +02:00
2023-05-19 17:23:20 +02:00
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)))
2023-05-19 17:17:57 +02:00
2023-05-19 17:23:20 +02:00
print(freqUpLim)
2023-05-19 17:17:57 +02:00
2023-05-19 17:23:20 +02:00
time = time / time.max() * 2 * np.pi
# calculate the transform
res = xr.DataArray(
data=finufft.nufft1d1(time, data, modeNum, **kwargs),
dims=['freq'],
coords={
"freq":np.linspace(-freqUpLim/2, freqUpLim/2, modeNum)
}
)
return res
2023-05-19 17:36:17 +02:00
2023-05-19 17:23:20 +02:00
def ifft_nutou(dataArray, modeNum):
pass
2023-05-19 17:17:57 +02:00