From f8958c4c31c29ae0571b3e0285d47e6b72c9427e Mon Sep 17 00:00:00 2001 From: Tal Wrii Date: Fri, 9 Sep 2016 19:56:10 -0500 Subject: [PATCH 1/2] autocorr -- calculate autocorrelation --- bin/autocorr | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 bin/autocorr diff --git a/bin/autocorr b/bin/autocorr new file mode 100755 index 0000000..faa2647 --- /dev/null +++ b/bin/autocorr @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# autocorr.py +# Tal Wrii + +""" + This file is part of Datatools. + + Datatools is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Datatools is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Datatools. If not, see . +""" + +import sys, os +import numpy + +name = os.path.basename(sys.argv[0]) +usage = \ +"""Usage: %s + +Work out the autocorrelation of the data. This can be used to detect +non-independence of samples (e.g periodicity, seasonal effects, +"continuity of data") + +Example: + cat tutorial/x.dat | %s | plot """ % (name,name) + +if __name__ == '__main__': + if '-h' in sys.argv or '--help' in sys.argv: + sys.exit(usage) + + data = [ float(x) for x in sys.stdin if x.strip() ] + convolution = numpy.correlate(data, data, mode='full') + correlation = convolution[convolution.size //2:] / numpy.inner(data, data) + for value in correlation: + print value From 7fe63273911b76883e15d56d806c5501439ef89e Mon Sep 17 00:00:00 2001 From: Tal Wrii Date: Mon, 12 Sep 2016 14:58:35 -0500 Subject: [PATCH 2/2] autocorr -- python3 support --- bin/autocorr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/autocorr b/bin/autocorr index faa2647..fd17608 100755 --- a/bin/autocorr +++ b/bin/autocorr @@ -20,6 +20,8 @@ along with Datatools. If not, see . """ +from __future__ import print_function + import sys, os import numpy @@ -42,4 +44,4 @@ if __name__ == '__main__': convolution = numpy.correlate(data, data, mode='full') correlation = convolution[convolution.size //2:] / numpy.inner(data, data) for value in correlation: - print value + print(value)