From 846bcd34a973d1bf1485a2ce715149362ca316c3 Mon Sep 17 00:00:00 2001 From: madilynpaul Date: Fri, 17 May 2024 10:24:04 -0600 Subject: [PATCH] Adding autocorrelation function to sampling.py. --- cmeutils/sampling.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmeutils/sampling.py b/cmeutils/sampling.py index 4f1162b..323640c 100644 --- a/cmeutils/sampling.py +++ b/cmeutils/sampling.py @@ -103,3 +103,14 @@ def is_equilibrated(data, threshold_fraction=0.50, threshold_neff=50, nskip=1): return [True, t0, g, Neff] else: return [False, None, None, None] + + +def autocorr1D(array): + """ + Takes in a linear np array, performs autocorrelation + function and returns normalized array with half the length + of the input + """ + ft = np.fft.rfft(array - np.average(array)) + acorr = np.fft.irfft(ft * np.conjugate(ft)) / (len(array) * np.var(array)) + return acorr[0 : len(acorr) // 2]