From 402b3e9502f0c6af6180aef5c88ea5663eb89cfe Mon Sep 17 00:00:00 2001 From: gkiar Date: Mon, 15 Aug 2016 09:57:10 -0400 Subject: [PATCH] fixed pep8ing --- ndmg/stats/graph_qc.py | 28 ++++++++++++++-------------- ndmg/stats/plot_metrics.py | 23 +++++++++++------------ ndmg/utils/bids_s3.py | 2 +- ndmg/utils/loadGraphs.py | 4 +++- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/ndmg/stats/graph_qc.py b/ndmg/stats/graph_qc.py index c6112b44a..4d81f3b55 100755 --- a/ndmg/stats/graph_qc.py +++ b/ndmg/stats/graph_qc.py @@ -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' diff --git a/ndmg/stats/plot_metrics.py b/ndmg/stats/plot_metrics.py index c4d849751..6a759af25 100644 --- a/ndmg/stats/plot_metrics.py +++ b/ndmg/stats/plot_metrics.py @@ -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): @@ -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) @@ -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]] diff --git a/ndmg/utils/bids_s3.py b/ndmg/utils/bids_s3.py index 13dec08cc..50cd11b16 100755 --- a/ndmg/utils/bids_s3.py +++ b/ndmg/utils/bids_s3.py @@ -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: diff --git a/ndmg/utils/loadGraphs.py b/ndmg/utils/loadGraphs.py index 75e744c97..8be18a7a6 100644 --- a/ndmg/utils/loadGraphs.py +++ b/ndmg/utils/loadGraphs.py @@ -26,6 +26,7 @@ import sys import os + def loadGraphs(filenames, verb=False): """ Given a list of files, returns a dictionary of graphs @@ -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: