Skip to content

Commit 5714aa4

Browse files
committed
switched phaseran() to phaseran2(). Retired the old one
1 parent 5813d13 commit 5714aa4

File tree

3 files changed

+81
-81
lines changed

3 files changed

+81
-81
lines changed

pyleoclim/core/series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,7 +4206,7 @@ def causality(self, target_series, method='liang', timespan=None, settings=None,
42064206

42074207
# pyleoclim.utils.tsmodel.ar1_sim : AR(1) simulator
42084208
# pyleoclim.utils.tsmodel.uar1_sim : maximum likelihood AR(1) simulator
4209-
# pyleoclim.utils.tsutils.phaseran2 : phase randomization
4209+
# pyleoclim.utils.tsutils.phaseran : phase randomization
42104210
# pyleoclim.utils.tsutils.random_time_axis : random time index vector according to a specific probability model
42114211

42124212
# '''
@@ -4248,7 +4248,7 @@ def causality(self, target_series, method='liang', timespan=None, settings=None,
42484248

42494249
# elif method == 'phaseran':
42504250
# if self.is_evenly_spaced() and time_pattern != "random":
4251-
# y_surr = tsutils.phaseran2(self.value, number)
4251+
# y_surr = tsutils.phaseran(self.value, number)
42524252
# else:
42534253
# raise ValueError("Phase-randomization presently requires evenly-spaced series.")
42544254

pyleoclim/core/surrogateseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def from_series(self, target_series):
110110
111111
pyleoclim.utils.tsmodel.uar1_sim : maximum likelihood AR(1) simulator
112112
113-
pyleoclim.utils.tsutils.phaseran2 : phase randomization
113+
pyleoclim.utils.tsutils.phaseran : phase randomization
114114
115115
Examples
116116
--------
@@ -140,7 +140,7 @@ def from_series(self, target_series):
140140

141141
elif self.method == 'phaseran':
142142
if target_series.is_evenly_spaced():
143-
y_surr = tsutils.phaseran2(target_series.value, self.number)
143+
y_surr = tsutils.phaseran(target_series.value, self.number)
144144
else:
145145
raise ValueError("Phase-randomization presently requires evenly-spaced series.")
146146

pyleoclim/utils/tsutils.py

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'detect_outliers_DBSCAN',
1818
'detect_outliers_kmeans',
1919
'remove_outliers',
20-
'phaseran2',
20+
'phaseran',
2121
'custom_year_averages'
2222
]
2323

@@ -1904,82 +1904,82 @@ def make_even_axis(x=None,start=None,stop=None,step=None,step_style=None,no_nans
19041904
return time_axis
19051905

19061906

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):
19831983
'''
19841984
Phase randomization of a time series y, of even or odd length.
19851985

0 commit comments

Comments
 (0)