From 2fde7bbfc9cc752cdbec52067df8a24b8c7ab6c2 Mon Sep 17 00:00:00 2001 From: Pauluhn Anuschka Date: Tue, 12 May 2015 14:55:01 +0200 Subject: [PATCH] Startup --- script/GaussianFit.py | 40 ++++++++++++++++++++++++++++++++++++++++ script/local.py | 26 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 script/GaussianFit.py create mode 100644 script/local.py diff --git a/script/GaussianFit.py b/script/GaussianFit.py new file mode 100644 index 0000000..ba4d94c --- /dev/null +++ b/script/GaussianFit.py @@ -0,0 +1,40 @@ +""" +Multi-peak search and gaussian fitting +""" + +from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list + +start = 0 +end = 30 +step_size = 0.2 + +result= lscan(sout,sinp,start,end,[step_size,],0.05) + +readable = result.getReadable(0) +positions = result.getPositions(0) + +threshold = (min(readable) + max(readable))/2 +min_peak_distance = 5.0 + +peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance) +print "Peak indexes: " + str(peaks) +print "Peak x: " + str(map(lambda x:positions[x], peaks)) +print "Peak y: " + str(map(lambda x:readable[x], peaks)) + + + +gaussians = fit_gaussians(readable, positions, peaks) + + +plots = plot([readable],["Multi-peak search"],[positions] ) +for i in range(len(peaks)): + peak = peaks[i] + (norm, mean, sigma) = gaussians[i] + if abs(mean - positions[peak]) < min_peak_distance: + print "Peak -> " + str(mean) + plots[0].addMarker(mean, None, "N="+str(round(norm,2)), None) + else: + print "Invalid gaussian fit: " + str(mean) + + + diff --git a/script/local.py b/script/local.py new file mode 100644 index 0000000..a39ef85 --- /dev/null +++ b/script/local.py @@ -0,0 +1,26 @@ +import random + + +class SimulatedOutput(Writable): + def getName(self): + return "SimulatedOutput" + + def write(self, value): + pass + + +class SimulatedInput(Readable): + def __init__(self): + self.x = 0.0 + + def getName(self): + return "SimulatedInput" + + def read(self): + self.x = self.x + 0.2 + noise = (random.random() - 0.5) / 20.0 + return math.sin(self.x) + noise + + +sout = SimulatedOutput() +sinp = SimulatedInput() \ No newline at end of file