Skip to content

Commit c06e1a0

Browse files
authored
Merge pull request #18 from olivercliff/stylizing
Stylizing with Python black and CamelCase
2 parents 5cefdbd + bad40b7 commit c06e1a0

File tree

14 files changed

+1767
-1635
lines changed

14 files changed

+1767
-1635
lines changed

demos/simple_demo.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44
from pyspi.calculator import Calculator
55
import matplotlib.pyplot as plt
66

7-
dataset = np.random.randn(3,1000) # Generate multivariate data with 3 processes and 100 observations
7+
dataset = np.random.randn(
8+
3, 1000
9+
) # Generate multivariate data with 3 processes and 100 observations
810

9-
calc = Calculator(dataset=dataset,fast=True) # Instantiate the calculator with only fast SPIs (set fast=False to compute all SPIs)
10-
calc.compute() # Compute all SPIs
11+
calc = Calculator(
12+
dataset=dataset, fast=True
13+
) # Instantiate the calculator with only fast SPIs (set fast=False to compute all SPIs)
1114

12-
print(f'Obtained results table of shape {calc.table.shape}:')
13-
print(calc.table) # Print the table of results.
15+
calc.compute() # Compute all SPIs
1416

15-
R = calc.table['cov_EmpiricalCovariance'] # Extract the results for an individual SPI (we're using covariance here)
17+
print(f"Obtained results table of shape {calc.table.shape}:")
18+
print(calc.table) # Print the table of results.
19+
20+
R = calc.table[
21+
"cov_EmpiricalCovariance"
22+
] # Extract the results for an individual SPI (we're using covariance here)
1623

1724
plt.imshow(R)
1825
plt.colorbar()
19-
plt.ylabel('Process')
20-
plt.xlabel('Process')
21-
plt.show()
26+
plt.ylabel("Process")
27+
plt.xlabel("Process")
28+
plt.show()

pyspi/base.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
import warnings, copy
44

55
"""
6-
Base class for pairwise statistics.
7-
8-
The child classes should either overload the mpi method (if it computes the full mpi)
9-
or the bivariate method if it computes only pairwise statisticss
10-
"""
11-
12-
"""
13-
Some parsing functions for decorating so that we can either input the processes directly or use the data structure
6+
Some parsing functions for decorating so that we can either input the time series directly or use the data structure
147
"""
158
def parse_univariate(function):
169
def parsed_function(self,data,i=None,inplace=True):
@@ -20,7 +13,7 @@ def parsed_function(self,data,i=None,inplace=True):
2013
elif not inplace:
2114
# Ensure we don't write over the original
2215
data = copy.deepcopy(data)
23-
16+
2417
if i is None:
2518
if data.n_processes == 1:
2619
i = 0
@@ -36,15 +29,15 @@ def parsed_function(self,data,data2=None,i=None,j=None,inplace=True):
3629
if not isinstance(data,Data):
3730
if data2 is None:
3831
raise TypeError('Input must be either a pyspi.data object or two 1D-array inputs.'
39-
f' Received {type(data)} and {type(data2)}.')
32+
f' Received {type(data)} and {type(data2)}.')
4033
data1 = data
4134
data = Data()
4235
data.add_process(data1)
4336
data.add_process(data2)
4437
elif not inplace:
4538
# Ensure we don't write over the original
4639
data = copy.deepcopy(data)
47-
40+
4841
if i is None and j is None:
4942
if data.n_processes == 2:
5043
i,j = 0,1
@@ -74,8 +67,8 @@ def parsed_function(self,data,inplace=True):
7467

7568
return parsed_function
7669

77-
class directed:
78-
""" Directed statistics
70+
class Directed:
71+
""" Base class for directed statistics
7972
"""
8073

8174
name = 'Bivariate base class'
@@ -125,7 +118,9 @@ def get_group(self,classes):
125118
pass
126119
return None
127120

128-
class undirected(directed):
121+
class Undirected(Directed):
122+
""" Base class for directed statistics
123+
"""
129124

130125
name = 'Base class'
131126
identifier = 'base'
@@ -136,17 +131,20 @@ def ispositive(self):
136131

137132
@parse_multivariate
138133
def multivariate(self,data):
139-
A = super(undirected,self).multivariate(data)
140-
134+
A = super(Undirected,self).multivariate(data)
135+
141136
li = np.tril_indices(data.n_processes,-1)
142137
A[li] = A.T[li]
143138
return A
144139

145-
# Maybe this would be more pythonic as decorators or something?
146-
class signed:
140+
class Signed:
141+
""" Base class for signed SPIs
142+
"""
147143
def issigned(self):
148144
return True
149-
150-
class unsigned:
145+
146+
class Unsigned:
147+
""" Base class for unsigned SPIs
148+
"""
151149
def issigned(self):
152150
return False

0 commit comments

Comments
 (0)