|
17 | 17 | 'detect_outliers_DBSCAN', |
18 | 18 | 'detect_outliers_kmeans', |
19 | 19 | 'remove_outliers', |
20 | | - 'phaseran2', |
| 20 | + 'phaseran', |
21 | 21 | 'custom_year_averages' |
22 | 22 | ] |
23 | 23 |
|
@@ -1904,82 +1904,82 @@ def make_even_axis(x=None,start=None,stop=None,step=None,step_style=None,no_nans |
1904 | 1904 | return time_axis |
1905 | 1905 |
|
1906 | 1906 |
|
1907 | | -def phaseran(recblk, nsurr): |
1908 | | - ''' Simultaneous phase randomization of a set of time series |
1909 | | - |
1910 | | - It creates blocks of surrogate data with the same second order properties as the original |
1911 | | - time series dataset by transforming the original data into the frequency domain, randomizing the |
1912 | | - phases simultaneoulsy across the time series and converting the data back into the time domain. |
1913 | | - |
1914 | | - Written by Carlos Gias for MATLAB |
1915 | | -
|
1916 | | - http://www.mathworks.nl/matlabcentral/fileexchange/32621-phase-randomization/content/phaseran.m |
1917 | | -
|
1918 | | - Parameters |
1919 | | - ---------- |
1920 | | - recblk : numpy array |
1921 | | - 2D array , Row: time sample. Column: recording. |
1922 | | - An odd number of time samples (height) is expected. |
1923 | | - If that is not the case, recblock is reduced by 1 sample before the surrogate data is created. |
1924 | | - The class must be double and it must be nonsparse. |
1925 | | - |
1926 | | - nsurr : int |
1927 | | - is the number of image block surrogates that you want to generate. |
1928 | | -
|
1929 | | - Returns |
1930 | | - ------- |
1931 | | - surrblk : numpy array |
1932 | | - 3D multidimensional array image block with the surrogate datasey along the third dimension |
1933 | | -
|
1934 | | - See also |
1935 | | - -------- |
1936 | | -
|
1937 | | - pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series |
1938 | | - pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate |
1939 | | -
|
1940 | | - References |
1941 | | - ---------- |
1942 | | -
|
1943 | | - - Prichard, D., Theiler, J. Generating Surrogate Data for Time Series with Several Simultaneously Measured Variables (1994) Physical Review Letters, Vol 73, Number 7 |
1944 | | - |
1945 | | - - Carlos Gias (2020). Phase randomization, MATLAB Central File Exchange |
1946 | | - ''' |
1947 | | - # Get parameters |
1948 | | - nfrms = recblk.shape[0] |
1949 | | - |
1950 | | - if nfrms % 2 == 0: |
1951 | | - nfrms = nfrms-1 |
1952 | | - recblk = recblk[0:nfrms] |
1953 | | - |
1954 | | - len_ser = int((nfrms-1)/2) |
1955 | | - interv1 = np.arange(1, len_ser+1) |
1956 | | - interv2 = np.arange(len_ser+1, nfrms) |
1957 | | - |
1958 | | - # Fourier transform of the original dataset |
1959 | | - fft_recblk = np.fft.fft(recblk) |
1960 | | - |
1961 | | - surrblk = np.zeros((nfrms, nsurr)) |
1962 | | - |
1963 | | - # for k in tqdm(np.arange(nsurr)): |
1964 | | - for k in np.arange(nsurr): |
1965 | | - ph_rnd = np.random.rand(len_ser) |
1966 | | - |
1967 | | - # Create the random phases for all the time series |
1968 | | - ph_interv1 = np.exp(2*np.pi*1j*ph_rnd) |
1969 | | - ph_interv2 = np.conj(np.flipud(ph_interv1)) |
1970 | | - |
1971 | | - # Randomize all the time series simultaneously |
1972 | | - fft_recblk_surr = np.copy(fft_recblk) |
1973 | | - fft_recblk_surr[interv1] = fft_recblk[interv1] * ph_interv1 |
1974 | | - fft_recblk_surr[interv2] = fft_recblk[interv2] * ph_interv2 |
1975 | | - |
1976 | | - # Inverse transform |
1977 | | - surrblk[:, k] = np.real(np.fft.ifft(fft_recblk_surr)) |
1978 | | - |
1979 | | - return surrblk |
1980 | | - |
1981 | | - |
1982 | | -def phaseran2(y, nsurr): |
| 1907 | +# def phaseran(recblk, nsurr): |
| 1908 | +# ''' Simultaneous phase randomization of a set of time series |
| 1909 | +# |
| 1910 | +# It creates blocks of surrogate data with the same second order properties as the original |
| 1911 | +# time series dataset by transforming the original data into the frequency domain, randomizing the |
| 1912 | +# phases simultaneoulsy across the time series and converting the data back into the time domain. |
| 1913 | +# |
| 1914 | +# Written by Carlos Gias for MATLAB |
| 1915 | +# |
| 1916 | +# http://www.mathworks.nl/matlabcentral/fileexchange/32621-phase-randomization/content/phaseran.m |
| 1917 | +# |
| 1918 | +# Parameters |
| 1919 | +# ---------- |
| 1920 | +# recblk : numpy array |
| 1921 | +# 2D array , Row: time sample. Column: recording. |
| 1922 | +# An odd number of time samples (height) is expected. |
| 1923 | +# If that is not the case, recblock is reduced by 1 sample before the surrogate data is created. |
| 1924 | +# The class must be double and it must be nonsparse. |
| 1925 | +# |
| 1926 | +# nsurr : int |
| 1927 | +# is the number of image block surrogates that you want to generate. |
| 1928 | +# |
| 1929 | +# Returns |
| 1930 | +# ------- |
| 1931 | +# surrblk : numpy array |
| 1932 | +# 3D multidimensional array image block with the surrogate datasey along the third dimension |
| 1933 | +# |
| 1934 | +# See also |
| 1935 | +# -------- |
| 1936 | +# |
| 1937 | +# pyleoclim.utils.correlation.corr_sig : Estimates the Pearson's correlation and associated significance between two non IID time series |
| 1938 | +# pyleoclim.utils.correlation.fdr : Determine significance based on the false discovery rate |
| 1939 | +# |
| 1940 | +# References |
| 1941 | +# ---------- |
| 1942 | +# |
| 1943 | +# - Prichard, D., Theiler, J. Generating Surrogate Data for Time Series with Several Simultaneously Measured Variables (1994) Physical Review Letters, Vol 73, Number 7 |
| 1944 | +# |
| 1945 | +# - Carlos Gias (2020). Phase randomization, MATLAB Central File Exchange |
| 1946 | +# ''' |
| 1947 | +# # Get parameters |
| 1948 | +# nfrms = recblk.shape[0] |
| 1949 | +# |
| 1950 | +# if nfrms % 2 == 0: |
| 1951 | +# nfrms = nfrms-1 |
| 1952 | +# recblk = recblk[0:nfrms] |
| 1953 | +# |
| 1954 | +# len_ser = int((nfrms-1)/2) |
| 1955 | +# interv1 = np.arange(1, len_ser+1) |
| 1956 | +# interv2 = np.arange(len_ser+1, nfrms) |
| 1957 | +# |
| 1958 | +# # Fourier transform of the original dataset |
| 1959 | +# fft_recblk = np.fft.fft(recblk) |
| 1960 | +# |
| 1961 | +# surrblk = np.zeros((nfrms, nsurr)) |
| 1962 | +# |
| 1963 | +# # for k in tqdm(np.arange(nsurr)): |
| 1964 | +# for k in np.arange(nsurr): |
| 1965 | +# ph_rnd = np.random.rand(len_ser) |
| 1966 | +# |
| 1967 | +# # Create the random phases for all the time series |
| 1968 | +# ph_interv1 = np.exp(2*np.pi*1j*ph_rnd) |
| 1969 | +# ph_interv2 = np.conj(np.flipud(ph_interv1)) |
| 1970 | +# |
| 1971 | +# # Randomize all the time series simultaneously |
| 1972 | +# fft_recblk_surr = np.copy(fft_recblk) |
| 1973 | +# fft_recblk_surr[interv1] = fft_recblk[interv1] * ph_interv1 |
| 1974 | +# fft_recblk_surr[interv2] = fft_recblk[interv2] * ph_interv2 |
| 1975 | +# |
| 1976 | +# # Inverse transform |
| 1977 | +# surrblk[:, k] = np.real(np.fft.ifft(fft_recblk_surr)) |
| 1978 | +# |
| 1979 | +# return surrblk |
| 1980 | + |
| 1981 | + |
| 1982 | +def phaseran(y, nsurr): |
1983 | 1983 | ''' |
1984 | 1984 | Phase randomization of a time series y, of even or odd length. |
1985 | 1985 | |
|
0 commit comments