Skip to content

Commit

Permalink
fixed pep8ing
Browse files Browse the repository at this point in the history
  • Loading branch information
gkiar committed Aug 15, 2016
1 parent 68c55d8 commit 402b3e9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
28 changes: 14 additions & 14 deletions ndmg/stats/graph_qc.py
Expand Up @@ -57,50 +57,50 @@ def compute_metrics(fs, outdir, atlas, verb=False):
# Number of non-zero edges (i.e. binary edge count)
print("Computing: NNZ")
nnz = OrderedDict((subj, len(nx.edges(graphs[subj]))) for subj in graphs)
write(outdir, 'number_non_zeros', nnz, atlas)
write(outdir, 'number_non_zeros', nnz, atlas)

# Degree sequence
print("Computing: Degree Seuqence")
temp_deg = OrderedDict((subj, np.array(nx.degree(graphs[subj]).values()))
for subj in graphs)
for subj in graphs)
deg = density(temp_deg)
write(outdir, 'degree_distribution', deg, atlas)
write(outdir, 'degree_distribution', deg, atlas)

# Edge Weights
print("Computing: Edge Weight Sequence")
temp_ew = OrderedDict((subj, [graphs[subj].get_edge_data(e[0], e[1])['weight']
for e in graphs[subj].edges()]) for subj in graphs)
temp_ew = OrderedDict((s, [graphs[s].get_edge_data(e[0], e[1])['weight']
for e in graphs[s].edges()]) for s in graphs)
ew = density(temp_ew)
write(outdir, 'edge_weight_distribution', ew, atlas)
write(outdir, 'edge_weight_distribution', ew, atlas)

# Clustering Coefficients
print("Computing: Clustering Coefficient Sequence")
temp_cc = OrderedDict((subj, nx.clustering(graphs[subj]).values())
for subj in graphs)
for subj in graphs)
ccoefs = density(temp_cc)
write(outdir, 'clustering_coefficients', ccoefs, atlas)
write(outdir, 'clustering_coefficients', ccoefs, atlas)

# Scan Statistic-1
print("Computing: Scan Statistic-1 Sequence")
temp_ss1 = scan_statistic(graphs, 1)
ss1 = density(temp_ss1)
write(outdir, 'scan_statistic_1', ss1, atlas)
write(outdir, 'scan_statistic_1', ss1, atlas)

# Eigen Values
print("Computing: Eigen Value Sequence")
laplac = OrderedDict((subj, nx.normalized_laplacian_matrix(graphs[subj]))
for subj in graphs)
for subj in graphs)
eigs = OrderedDict((subj, np.sort(np.linalg.eigvals(laplac[subj].A))[::-1])
for subj in graphs)
write(outdir, 'eigen_sequence', eigs, atlas)
for subj in graphs)
write(outdir, 'eigen_sequence', eigs, atlas)

# Betweenness Centrality
print("Computing: Betweenness Centrality Sequence")
nxbc = nx.algorithms.betweenness_centrality # For PEP8 line length...
temp_bc = OrderedDict((subj, nxbc(graphs[subj]).values())
for subj in graphs)
for subj in graphs)
centrality = density(temp_bc)
write(outdir, 'betweenness_centrality', centrality, atlas)
write(outdir, 'betweenness_centrality', centrality, atlas)

outf = outdir + '/' + atlas + '_summary.png'

Expand Down
23 changes: 11 additions & 12 deletions ndmg/stats/plot_metrics.py
Expand Up @@ -19,24 +19,23 @@
# Created by Greg Kiar on 2016-05-11.
# Email: gkiar@jhu.edu

import numpy as np
import networkx as nx
import matplotlib
matplotlib.use('Agg') #very important this is above pyplot import

import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import time
import json
import sys
import os
import numpy as np
import networkx as nx
import matplotlib; matplotlib.use('Agg') # very important above pyplot import
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick

font = {'weight' : 'bold',
'size' : 14}
font = {'weight': 'bold',
'size': 14}
matplotlib.rc('font', **font)

cols = '#000000'


class plot_metrics():

def __init__(self, nnz, deg, ew, ccoefs, ss1, eigs, centrality, outf):
Expand Down Expand Up @@ -93,7 +92,7 @@ def plotting(self):
plt.savefig(self.outf, bbox_inches='tight')
# plt.show()

metadata = {"subjects" : self.nnz.keys(),
metadata = {"subjects": self.nnz.keys(),
"date": time.asctime(time.localtime())}
with open(os.path.splitext(self.outf)[0]+'_info.json', 'w') as fp:
json.dump(metadata, fp)
Expand Down Expand Up @@ -135,8 +134,8 @@ def plot_helper(self, data, tit, typ='hi'):
def rand_jitter(self, arr):
stdev = .03*(max(arr)-min(arr)+2)
return arr + np.random.randn(len(arr)) * stdev
def factors(self, N):

def factors(self, N):
factors = [subitem for subitem in [(i, N//i)
for i in range(1, int(N**0.5) + 1)
if N % i == 0 and i > 1]]
Expand Down
2 changes: 1 addition & 1 deletion ndmg/utils/bids_s3.py
Expand Up @@ -34,7 +34,7 @@ def get_data(bucket, remote_path, local, subj=None):
if bucket not in bkts:
sys.exit("Error: could not locate bucket. Available buckets: " +
", ".join(bkts))

cmd = "".join(['aws s3 cp --recursive s3://', bucket, '/',
remote_path])
if subj is not None:
Expand Down
4 changes: 3 additions & 1 deletion ndmg/utils/loadGraphs.py
Expand Up @@ -26,6 +26,7 @@
import sys
import os


def loadGraphs(filenames, verb=False):
"""
Given a list of files, returns a dictionary of graphs
Expand All @@ -38,7 +39,8 @@ def loadGraphs(filenames, verb=False):
- Toggles verbose output statements
"""
# Initializes empty dictionary
if type(filenames) is not list: filenames = [filenames]
if type(filenames) is not list:
filenames = [filenames]
gstruct = OrderedDict()
for idx, files in enumerate(filenames):
if verb:
Expand Down

0 comments on commit 402b3e9

Please sign in to comment.