This commit is contained in:
Jianshun Gao 2023-05-19 17:23:20 +02:00
parent 759f772976
commit 8fddd8bb21

View File

@ -8,48 +8,43 @@ import xrft
import finufft
class FFTAnalyser():
def fft(dataArray, **kwargs):
return xrft.fft(dataArray, **kwargs)
def __init__(self) -> None:
pass
def ifft(dataArray, **kwargs):
return xrft.ifft(dataArray, **kwargs)
def fft(self, dataArray, **kwargs):
return xrft.fft(dataArray, **kwargs)
def fft_nutou(dataArray, modeNum, **kwargs):
def ifft(self, dataArray, **kwargs):
return xrft.ifft(dataArray, **kwargs)
data = dataArray.to_numpy()
data = data.astype('complex128')
def fft_nutou(self, dataArray, modeNum):
time = dataArray[dataArray.dims[0]].to_numpy()
data = dataArray.to_numpy()
data = data.astype('complex128')
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)))
time = dataArray[dataArray.dims[0]].to_numpy()
print(freqUpLim)
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)))
time = time / time.max() * 2 * np.pi
print(freqUpLim)
# calculate the transform
res = xr.DataArray(
data=finufft.nufft1d1(time, data, modeNum, **kwargs),
dims=['freq'],
coords={
"freq":np.linspace(-freqUpLim/2, freqUpLim/2, modeNum)
}
)
time = time / time.max() * 2 * np.pi
return res
# 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
def ifft_nutou(dataArray, modeNum):
pass