From 334ef39a21d0d3566d7c273676ba16b3c817d467 Mon Sep 17 00:00:00 2001
From: Philippe Roy <borghor@yahoo.ca>
Date: Thu, 12 Sep 2024 16:03:50 -0400
Subject: [PATCH] Create autocorrelation.jl

---
 src/autocorrelation.jl | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 src/autocorrelation.jl

diff --git a/src/autocorrelation.jl b/src/autocorrelation.jl
new file mode 100644
index 0000000..992e3c7
--- /dev/null
+++ b/src/autocorrelation.jl
@@ -0,0 +1,27 @@
+function autocorrelation(xout, xin; lags=30)    
+    xout .= LongMemory.autocorrelation(Array(xin), lags)   
+end
+
+
+"""
+    autocorrelation(ds; lags=30)
+
+Compute the autocorrelation of a dataset `ds` along the time dimension.
+
+# Arguments
+- `ds`: The input dataset.
+- `lags`: The number of lags to compute autocorrelation for. Default is 30.
+
+# Returns
+The autocorrelation of the input dataset `ds` along the time dimension.
+
+"""
+function autocorrelation(ds; lags=30)
+
+    # Dimensions
+    indims = InDims("Ti")
+    outdims = OutDims(Dim{:lags}(collect(1:lags)))    
+
+    return mapCube(Climat.autocorrelation, ds, indims=indims, outdims=outdims, lags=lags, nthreads=Threads.nthreads())
+
+end