forked from cortex-lab/phy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_stats.py
32 lines (22 loc) · 1.29 KB
/
cluster_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Show how to add a custom cluster histogram view showing cluster statistics."""
from phy import IPlugin, Bunch
from phy.cluster.views import HistogramView
class FeatureHistogramView(HistogramView):
"""Every view corresponds to a unique view class, so we need to subclass HistogramView."""
n_bins = 100 # default number of bins
x_max = .1 # maximum value on the x axis (maximum bin)
alias_char = 'fh' # provide `:fhn` (set number of bins) and `:fhm` (set max bin) snippets
class ExampleClusterStatsPlugin(IPlugin):
def attach_to_controller(self, controller):
def feature_histogram(cluster_id):
"""Must return a Bunch object with data and optional x_max, plot, text items.
The histogram is automatically computed by the view, this function should return
the original data used to compute the histogram, rather than the histogram itself.
"""
return Bunch(data=controller.get_features(cluster_id).data)
def create_view():
"""Create and return a histogram view."""
return FeatureHistogramView(cluster_stat=feature_histogram)
# Maps a view name to a function that returns a view
# when called with no argument.
controller.view_creator['FeatureHistogram'] = create_view