Added metaarray to support flowchart

Prettied up flowchart example
This commit is contained in:
Luke Campagnola 2012-04-04 21:59:37 -04:00
parent 20c40a70d5
commit d9c558105c
6 changed files with 1429 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import initExample ## Add path to library (just for examples; you do not need th
from pyqtgraph.flowchart import Flowchart
from pyqtgraph.Qt import QtGui
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import numpy as np

View File

@ -1,3 +1,7 @@
import scipy
import numpy as np
from pyqtgraph.metaarray import MetaArray
def downsample(data, n, axis=0, xvals='subsample'):
"""Downsample by averaging points together across axis.
If multiple axes are specified, runs once per axis.
@ -7,7 +11,7 @@ def downsample(data, n, axis=0, xvals='subsample'):
ma = None
if isinstance(data, MetaArray):
ma = data
data = data.view(ndarray)
data = data.view(np.ndarray)
if hasattr(axis, '__len__'):
@ -43,10 +47,10 @@ def downsample(data, n, axis=0, xvals='subsample'):
def applyFilter(data, b, a, padding=100, bidir=True):
"""Apply a linear filter with coefficients a, b. Optionally pad the data before filtering
and/or run the filter in both directions."""
d1 = data.view(ndarray)
d1 = data.view(np.ndarray)
if padding > 0:
d1 = numpy.hstack([d1[:padding], d1, d1[-padding:]])
d1 = np.hstack([d1[:padding], d1, d1[-padding:]])
if bidir:
d1 = scipy.signal.lfilter(b, a, scipy.signal.lfilter(b, a, d1)[::-1])[::-1]
@ -68,7 +72,7 @@ def besselFilter(data, cutoff, order=1, dt=None, btype='low', bidir=True):
tvals = data.xvals('Time')
dt = (tvals[-1]-tvals[0]) / (len(tvals)-1)
except:
raise Exception('Must specify dt for this data.')
dt = 1.0
b,a = scipy.signal.bessel(order, cutoff * dt, btype=btype)
@ -86,7 +90,7 @@ def butterworthFilter(data, wPass, wStop=None, gPass=2.0, gStop=20.0, order=1, d
tvals = data.xvals('Time')
dt = (tvals[-1]-tvals[0]) / (len(tvals)-1)
except:
raise Exception('Must specify dt for this data.')
dt = 1.0
if wStop is None:
wStop = wPass * 2.0
@ -148,7 +152,7 @@ def denoise(data, radius=2, threshold=4):
r2 = radius * 2
d1 = data.view(ndarray)
d1 = data.view(np.ndarray)
d2 = data[radius:] - data[:-radius] #a derivative
#d3 = data[r2:] - data[:-r2]
#d4 = d2 - d3
@ -174,7 +178,7 @@ def adaptiveDetrend(data, x=None, threshold=3.0):
if x is None:
x = data.xvals(0)
d = data.view(ndarray)
d = data.view(np.ndarray)
d2 = scipy.signal.detrend(d)

1322
metaarray/MetaArray.py Normal file

File diff suppressed because it is too large Load Diff

1
metaarray/__init__.py Normal file
View File

@ -0,0 +1 @@
from MetaArray import *

8
metaarray/license.txt Normal file
View File

@ -0,0 +1,8 @@
Copyright (c) 2010 Luke Campagnola ('luke.campagnola@%s.com' % 'gmail')
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

86
metaarray/readMeta.m Normal file
View File

@ -0,0 +1,86 @@
function f = readMeta(file)
info = hdf5info(file);
f = readMetaRecursive(info.GroupHierarchy.Groups(1));
end
function f = readMetaRecursive(root)
typ = 0;
for i = 1:length(root.Attributes)
if strcmp(root.Attributes(i).Shortname, '_metaType_')
typ = root.Attributes(i).Value.Data;
break
end
end
if typ == 0
printf('group has no _metaType_')
typ = 'dict';
end
list = 0;
if strcmp(typ, 'list') || strcmp(typ, 'tuple')
data = {};
list = 1;
elseif strcmp(typ, 'dict')
data = struct();
else
printf('Unrecognized meta type %s', typ);
data = struct();
end
for i = 1:length(root.Attributes)
name = root.Attributes(i).Shortname;
if strcmp(name, '_metaType_')
continue
end
val = root.Attributes(i).Value;
if isa(val, 'hdf5.h5string')
val = val.Data;
end
if list
ind = str2num(name)+1;
data{ind} = val;
else
data.(name) = val;
end
end
for i = 1:length(root.Datasets)
fullName = root.Datasets(i).Name;
name = stripName(fullName);
file = root.Datasets(i).Filename;
data2 = hdf5read(file, fullName);
if list
ind = str2num(name)+1;
data{ind} = data2;
else
data.(name) = data2;
end
end
for i = 1:length(root.Groups)
name = stripName(root.Groups(i).Name);
data2 = readMetaRecursive(root.Groups(i));
if list
ind = str2num(name)+1;
data{ind} = data2;
else
data.(name) = data2;
end
end
f = data;
return;
end
function f = stripName(str)
inds = strfind(str, '/');
if isempty(inds)
f = str;
else
f = str(inds(length(inds))+1:length(str));
end
end