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 import finufft
class FFTAnalyser(): def fft(dataArray, **kwargs):
return xrft.fft(dataArray, **kwargs)
def __init__(self) -> None: def ifft(dataArray, **kwargs):
pass return xrft.ifft(dataArray, **kwargs)
def fft(self, dataArray, **kwargs): def fft_nutou(dataArray, modeNum, **kwargs):
return xrft.fft(dataArray, **kwargs)
def ifft(self, dataArray, **kwargs): data = dataArray.to_numpy()
return xrft.ifft(dataArray, **kwargs) data = data.astype('complex128')
def fft_nutou(self, dataArray, modeNum): time = dataArray[dataArray.dims[0]].to_numpy()
data = dataArray.to_numpy() if isinstance(time[0], type(np.datetime64(500,'s'))):
data = data.astype('complex128') 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 / time.max() * 2 * np.pi
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) # 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 def ifft_nutou(dataArray, modeNum):
res = xr.DataArray( pass
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