Commit 48633f35 authored by Ian Bowman's avatar Ian Bowman
Browse files

Calculates matrix column totals

parent b29529db
......@@ -449,3 +449,11 @@ def new_indices(roi_name_npa, sorted_cmt_str_lst):
new_indices.append(roi_name_npa.tolist().index(roi_name))
return new_indices
#returns total numbers at various columns
def col_totals(ctx_mat_npa):
col_totals = []
for col in xrange(ctx_mat_npa.shape[1]):
col_totals.append(np.sum(ctx_mat_npa[:,col]))
return col_totals
......@@ -3,6 +3,7 @@ from src import hpf_plot, hpf_utils
import os
import numpy as np
import bct
import math
class TestHpfPlot(unittest.TestCase):
def setUp(self):
......@@ -16,6 +17,29 @@ class TestHpfPlot(unittest.TestCase):
[1, 0, 0, 0],
[1, 0, 1, 0]])
def test_col_totals(self):
y_bounds = [-0.5, 1.5, 4.5]
exp_mat_col_totals = [2, 1, 2, 0]
self.assertEqual(exp_mat_col_totals,
hpf_plot.col_totals(self.ctx_mat_npa))
exp_submat_col_totals = [[0, 0, 1, 0],
[2, 1, 1, 0]]
lower_bound = -1
submat_col_totals = []
for idx, y_bound in enumerate(y_bounds):
upper_bound = int(math.floor(y_bound))
if upper_bound > 0:
assert(lower_bound >= 0)
submat_col_totals.append(hpf_plot.col_totals(
self.ctx_mat_npa[lower_bound:upper_bound,:]))
lower_bound = max(upper_bound, 0)
self.assertEqual(exp_submat_col_totals, submat_col_totals)
def test_sparse_mat_rep(self):
exp_sparse_mat_rep = \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment