From 42e7388912974323c7ed8ea46afb7ce0a624e9a6 Mon Sep 17 00:00:00 2001 From: basvandenberg Date: Sat, 22 Nov 2014 23:56:23 +0100 Subject: [PATCH] add aditional histogram data to json output --- spice/featmat.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spice/featmat.py b/spice/featmat.py index 8769834..115d6b9 100644 --- a/spice/featmat.py +++ b/spice/featmat.py @@ -660,10 +660,13 @@ def ttest(self, labeling_name, label0, label1, object_is=None): return ts def histogram_data(self, feat_id, labeling_name, class_ids=None, - num_bins=40, standardized=False): + num_bins=40, standardized=False, title=None): # test num_bins > 0 + if(title is None): + title = '' + # get labeling data try: labeling = self.labeling_dict[labeling_name] @@ -711,17 +714,26 @@ def histogram_data(self, feat_id, labeling_name, class_ids=None, bin_edges = list(numpy.arange(min_val, max_val, step)) bin_edges.append(max_val) + max_count = 0 hists = {} for lab in hist_data.keys(): h, e = numpy.histogram(hist_data[lab], bin_edges) hists[lab] = list(h) + max_count = max(max_count, max(h)) + result = {} + result['feature-id'] = feat_id + result['title'] = title result['x-label'] = feat_name result['legend'] = class_ids for lab in class_ids: result[lab] = hists[lab] + result['min-value'] = min_val + result['max-value'] = max_val + result['max-count'] = max_count + result['bin-edges'] = bin_edges return result @@ -732,7 +744,7 @@ def histogram_json(self, feat_id, labeling_name, class_ids=None, title = '' hist_data = self.histogram_data(feat_id, labeling_name, class_ids, - standardized=standardized) + standardized=standardized, title=title) return json.dumps(hist_data) def save_histogram(self, feat_id, labeling_name, class_ids=None,