summaryrefslogtreecommitdiff
path: root/simpl/plot
diff options
context:
space:
mode:
Diffstat (limited to 'simpl/plot')
-rw-r--r--simpl/plot/__init__.py59
-rw-r--r--simpl/plot/colours.py23
2 files changed, 27 insertions, 55 deletions
diff --git a/simpl/plot/__init__.py b/simpl/plot/__init__.py
index 2118745..a7aad8e 100644
--- a/simpl/plot/__init__.py
+++ b/simpl/plot/__init__.py
@@ -1,23 +1,8 @@
-# Copyright (c) 2009 John Glover, National University of Ireland, Maynooth
-#
-# This program 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 2 of the License, or
-# (at your option) any later version.
-#
-# This program 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 this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
import simpl
import matplotlib.pyplot as plt
import colours
+
def plot_frame_peaks(peaks):
"Plot peaks in one frame"
x_values = []
@@ -27,13 +12,15 @@ def plot_frame_peaks(peaks):
y_values.append(peak.amplitude)
plt.plot(x_values, y_values, 'ro')
+
def _plot_frame_peaks(peaks, frame_number, max_amp=0):
"Plot one frame, which is a list of Peak objects"
for peak in peaks:
plt.plot(frame_number, int(peak.frequency), linestyle="None",
marker="o", markersize=2, markeredgewidth=None,
- markerfacecolor=colours.pbj(peak.amplitude/max_amp))
-
+ markerfacecolor=colours.pbj(peak.amplitude / max_amp))
+
+
def plot_peaks(frames):
"Plot peaks found by a peak detection algorithm"
# Get the maximum peak amplitude, used to select an appropriate
@@ -44,12 +31,13 @@ def plot_peaks(frames):
max_amp = max(max_amp, max([p.amplitude for p in frame.peaks]))
# If no max amp then no peaks so return
if not max_amp:
- print "Warning: no peaks to plot"
+ print "Warning: no peaks with an amplitude of > 0 to plot, returning"
return
for frame_number, frame in enumerate(frames):
_plot_frame_peaks(frame.peaks, frame_number, max_amp)
-
+
+
def plot_partials(frames, show_peaks=False):
"Plot partials created by a partial tracking algorithm"
# Get the maximum peak amplitude, used to select an appropriate
@@ -60,7 +48,7 @@ def plot_partials(frames, show_peaks=False):
max_amp = max(max_amp, max([p.amplitude for p in frame.peaks]))
# If no max amp then no peaks so return
if not max_amp:
- print "Warning: no peaks to plot"
+ print "Warning: no peaks with an amplitude of > 0 to plot, returning"
return
# Create Partial objects from frames
@@ -86,22 +74,21 @@ def plot_partials(frames, show_peaks=False):
for p in live_partials:
if p:
partials.append(p)
-
+
peaks = [[] for f in range(num_frames)]
for partial in partials:
- x_values = []
- y_values = []
- avg_amp = 0.0
- num_peaks = 0
- for peak_number, peak in enumerate(partial.peaks):
- x_values.append(partial.starting_frame + peak_number)
- y_values.append(int(peak.frequency))
- avg_amp += peak.amplitude
- num_peaks += 1
- peaks[partial.starting_frame + peak_number].append(peak)
- avg_amp /= num_peaks
- plt.plot(x_values, y_values, color=colours.pbj(avg_amp/max_amp))
+ x_values = []
+ y_values = []
+ avg_amp = 0.0
+ num_peaks = 0
+ for peak_number, peak in enumerate(partial.peaks):
+ x_values.append(partial.starting_frame + peak_number)
+ y_values.append(int(peak.frequency))
+ avg_amp += peak.amplitude
+ num_peaks += 1
+ peaks[partial.starting_frame + peak_number].append(peak)
+ avg_amp /= num_peaks
+ plt.plot(x_values, y_values, color=colours.pbj(avg_amp / max_amp))
if show_peaks:
- plot_peaks(frames)
-
+ plot_peaks(frames)
diff --git a/simpl/plot/colours.py b/simpl/plot/colours.py
index b85d48d..5efc86b 100644
--- a/simpl/plot/colours.py
+++ b/simpl/plot/colours.py
@@ -1,19 +1,3 @@
-# Copyright (c) 2010 John Glover, National University of Ireland, Maynooth
-#
-# This program 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 2 of the License, or
-# (at your option) any later version.
-#
-# This program 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 this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
# These colour maps are based on the colour schemes in gheat:
# http://code.google.com/p/gheat/
@@ -223,13 +207,15 @@ pbj_colours = [
[0.820, 0.357, 0.094]
]
+
def classic(heat):
if heat < 0.0:
return classic_colours[0]
elif heat > 1.0:
return classic_colours[-1]
else:
- return classic_colours[int(heat * (len(classic_colours)-1))]
+ return classic_colours[int(heat * (len(classic_colours) - 1))]
+
def pbj(heat):
if heat < 0.0:
@@ -237,5 +223,4 @@ def pbj(heat):
elif heat > 1.0:
return pbj_colours[-1]
else:
- return pbj_colours[int(heat * (len(pbj_colours)-1))]
-
+ return pbj_colours[int(heat * (len(pbj_colours) - 1))]