Skip to content

Commit bf5d5d1

Browse files
committed
Use abosolute import and add requirements
1 parent eee655f commit bf5d5d1

File tree

8 files changed

+55
-51
lines changed

8 files changed

+55
-51
lines changed

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
This file is part of XPPy.
33
44
XPPy is free software: you can redistribute it and/or modify
5-
it under the terms of the GNU Lesser General Public License as
6-
published by the Free Software Foundation, either version 3 of
5+
it under the terms of the GNU Lesser General Public License as
6+
published by the Free Software Foundation, either version 3 of
77
the License, or (at your option) any later version.
88
99
XPPy is distributed in the hope that it will be useful,
@@ -15,7 +15,7 @@
1515
along with XPPy. If not, see <http://www.gnu.org/licenses/>.
1616
'''
1717
from distutils.core import setup
18-
from xppy import __version__
18+
from xppy import __version__
1919

2020
setup(name='xppy',
2121
version=__version__,
@@ -25,5 +25,6 @@
2525
license='LGPL',
2626
url='http://seis.bris.ac.uk/~enxjn/xppy',
2727
platforms='All-platforms',
28-
packages=['xppy','xppy.parser','xppy.utils']
28+
packages=['xppy','xppy.parser','xppy.utils'],
29+
install_requires=['numpy', 'matplotlib'],
2930
)

xppy/parser/parse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
'''
2929
from __future__ import print_function
30+
from __future__ import absolute_import
3031
import os
3132
import numpy as np
3233

xppy/parser/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
'''
2929
from __future__ import print_function
30+
from __future__ import absolute_import
3031

3132
import os
3233
import shutil

xppy/utils/allinfo.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def __init__(self, file_name=None):
4343
self.__raw_data = None
4444
self.__branches = []
4545
self.noVar = 0
46-
# If file name is given try to load the file
46+
# If file name is given try to load the file
4747
if file_name != None and os.path.exists(file_name):
4848
self.__raw_data = np.loadtxt(file_name)
4949
# Calculate the number of variables
5050
self.noVar = int((self.__raw_data.shape[1]-5)/4)
51-
51+
5252
def loadRawData(self, file_name):
5353
'''
5454
Raw data loader
@@ -60,7 +60,7 @@ def loadRawData(self, file_name):
6060
return True
6161
else:
6262
return False
63-
63+
6464
def setRawData(self, raw_data):
6565
'''
6666
Raw data setter
@@ -85,7 +85,7 @@ def findBranches(self):
8585
'''
8686
if self.__raw_data == None:
8787
return False
88-
88+
8989
# Scan file for branches
9090
bl = []
9191
for b in self.__raw_data[:,1]:
@@ -100,8 +100,8 @@ def findBranches(self):
100100

101101
def findParts(self, branchArr):
102102
'''
103-
Finds parts in the given branch array
104-
(branch extracted by e.g. getBranch)
103+
Finds parts in the given branch array
104+
(branch extracted by e.g. getBranch)
105105
'''
106106
parts = []; last = 0
107107
for i in range(0,branchArr.shape[0]):
@@ -127,7 +127,7 @@ def getBranch(self, nr, getParts=False):
127127
'''
128128
if len(self.__branches) == 0:
129129
self.findBranches()
130-
130+
131131
try:
132132
self.__branches.index(nr)
133133
except ValueError:
@@ -140,8 +140,8 @@ def getBranch(self, nr, getParts=False):
140140
parts = self.findParts(retArr)
141141
return (retArr, parts)
142142
# Else, just return the branch array
143-
return retArr
144-
143+
return retArr
144+
145145
def getFlippedBranch(self, nr, getParts=False):
146146
'''
147147
Function returns flipped data of branch number nr;
@@ -151,7 +151,7 @@ def getFlippedBranch(self, nr, getParts=False):
151151
(b,p) = self.getBranch(nr,True)
152152
if b == None:
153153
return None
154-
154+
155155
# Find starting point
156156
i = np.ix_(b[:,2]==b[0,2],b[:,3]==b[0,3])[0].ravel()
157157
# If the branch can't be flipped, return
@@ -171,4 +171,4 @@ def getFlippedBranch(self, nr, getParts=False):
171171
parts = self.findParts(retArr)
172172
return (retArr, parts)
173173
# Else, just return the branch array
174-
return retArr
174+
return retArr

xppy/utils/data.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
def getOrbit(data, start=None, eps=1e-4, col=1):
3535
'''
3636
Function extracts single orbit from given data and returns it.
37-
The orbit is ectracted from 'start' with accuracy of the end
38-
point less than eps. The compared data is taken from
37+
The orbit is ectracted from 'start' with accuracy of the end
38+
point less than eps. The compared data is taken from
3939
the column col.
4040
'''
4141
# If no starting point is specified, start from the minimal value
@@ -45,7 +45,7 @@ def getOrbit(data, start=None, eps=1e-4, col=1):
4545
stop = start+1
4646
avr = data[:,col].min() + \
4747
(np.abs(data[:,col].max()) + np.abs(data[:,col].min()))/2
48-
crossAvr = False
48+
crossAvr = False
4949
for i in range(start+1,data.shape[0]):
5050
# Orbit have to cross maximu avarege value firs
5151
if not crossAvr:
@@ -70,8 +70,8 @@ def arcLength(data):
7070

7171
def resample1d(data, ns):
7272
'''
73-
Function resamples the given data (1d line [x,y] data) using even
74-
arc lenght (linear interpolation). New (resampled) data is returned.
73+
Function resamples the given data (1d line [x,y] data) using even
74+
arc lenght (linear interpolation). New (resampled) data is returned.
7575
'''
7676
# Calculating arc lenght of the bit and the whole data
7777
tot_alen = arcLength(data)
@@ -98,20 +98,20 @@ def resample1d(data, ns):
9898

9999
def findSpikes(data, cols=[0,1], threshold=20, sampleThr=3):
100100
'''
101-
Function finds spikes in the given two data columns data.
102-
Threshold is a slope of the tangent line. SampleThr is
101+
Function finds spikes in the given two data columns data.
102+
Threshold is a slope of the tangent line. SampleThr is
103103
minimal number of samples where slope is greater then threshold.
104104
Threshold value according to (Naundorf et al. 2006).
105105
'''
106106
if len(cols) != 2:
107107
raise ValueError('List should contain to columns!')
108-
108+
109109
st = 0 # Number of samples above threshold
110110
# List contain begining, top and end of the spike i
111111
spb = []; spm = []; spe = []
112112
# Last slope
113113
sl_last = 0
114-
# Spike flag (0 - nothing, 1 - passed begining,
114+
# Spike flag (0 - nothing, 1 - passed begining,
115115
# 2 - passed midpoint, 3 - on the way down (on steep slope))
116116
spf = 0
117117
for i in range(1,data.shape[0]):
@@ -128,7 +128,7 @@ def findSpikes(data, cols=[0,1], threshold=20, sampleThr=3):
128128
spf = 2
129129
sl_last = sl
130130
continue
131-
131+
132132
# Looking for the steep slope down
133133
if spf == 2:
134134
if np.abs(sl) > threshold and np.sign(sl) == -1:
@@ -172,7 +172,7 @@ def findADP(data, cols=[0,1], threshold=20, sampleThr=3):
172172
dx,dy = data[spe[i],cols] - data[spe[i]-1,cols]
173173
# Slope of tangent line
174174
sl_last = dy/dx
175-
# If we have more spikes, look for ADP till the begining
175+
# If we have more spikes, look for ADP till the begining
176176
# of the next spike, else look till the end of the data
177177
if i+1 < len(spe):
178178
j_end = spb[i+1]
@@ -197,13 +197,13 @@ def ISI(data, cols=[0,1], threshold=20, sampleThr=3):
197197
of ISI for the given pair. The ISI is calculated for the peak of the spikes.
198198
Threshold value according to (Naundorf et al. 2006).
199199
'''
200-
200+
201201
(spb, spm, spe) = findSpikes(data, cols, threshold, sampleThr)
202-
202+
203203
# ISI can be calculated for at least 2 spikes
204204
if len(spm) < 2:
205205
return None
206-
206+
207207
return np.diff(data[spm,cols[0]])
208208

209209
def getDVDT(data, cols=[0,1]):
@@ -214,14 +214,14 @@ def getDVDT(data, cols=[0,1]):
214214
return np.diff(data[:,cols[1]])/np.diff(data[:,cols[0]])
215215

216216
def getThreshold(data, cols=[0,1]):
217-
'''
217+
'''
218218
Function returns a threshold time and value for the first spike in the spike train.
219219
Threshold is defined as dV/dt crossing of 20 V/s (Naundorf et al. 2006).
220220
'''
221221
dv = getDVDT(data, cols)
222-
222+
223223
i = (dv >= 20).nonzero()[0][0]
224-
224+
225225
return data[i,:]
226226

227227
def getTau(data, cols=[0,1]):
@@ -232,8 +232,8 @@ def getTau(data, cols=[0,1]):
232232
function does not detect the beginning of current injection by itself.
233233
'''
234234
d = np.abs(data[:,cols].copy())
235-
v_63 = 0.63*(d[:,cols[1]].max() - d[:,cols[1]].min()) + d[0,cols[1]]
235+
v_63 = 0.63*(d[:,cols[1]].max() - d[:,cols[1]].min()) + d[0,cols[1]]
236236

237-
# Index of the 63% crossing
237+
# Index of the 63% crossing
238238
i_63 = (d[:,cols[1]] >= v_63).nonzero()[0][0]
239239
return d[i_63,cols[1]] - d[0,cols[1]]

xppy/utils/diagram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ def read_diagram(diag):
4444
elif diag[i,3] == 4:
4545
diag_ret[i,[4,8]] = diag[i,[1,2]]
4646
diag_ret[:,0] = diag[:,0]
47-
47+
4848
return diag_ret

xppy/utils/output.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def __init__(self, ode_file='', file_name='output.dat'):
4040
'''
4141
self.__raw_data = None # Content of data file
4242
self.__desc = None # Data descriptor, read from the ode_file
43-
43+
4444
if os.path.exists(file_name):
4545
self.__raw_data = np.loadtxt(file_name)
46-
46+
4747
if os.path.exists(ode_file):
4848
self.__desc = parse.readOdeVars(ode_file)
49-
50-
49+
50+
5151
def loadRawData(self, file_name='output.dat'):
5252
'''
5353
Raw data loader
@@ -57,7 +57,7 @@ def loadRawData(self, file_name='output.dat'):
5757
return True
5858
else:
5959
return False
60-
60+
6161
def setRawData(self, raw_data):
6262
'''
6363
Raw data setter
@@ -82,37 +82,37 @@ def readOdeVars(self, ode_file):
8282
'''
8383
self.__desc = parse.readOdeVars(ode_file)
8484
return True
85-
85+
8686
def setDesc(self, desc):
8787
'''
8888
Variable descriptor setter
8989
'''
9090
self.__desc = desc
91-
91+
9292
def getDesc(self):
9393
'''
9494
Variable descriptor getter
9595
'''
9696
return self.__desc
97-
97+
9898
def __getitem__(self, name):
99-
# TODO Maybe do it more efficiently
99+
# TODO Maybe do it more efficiently
100100
# Sequence value
101101
if type(name) is tuple:
102102
if type(name[1]) is str:
103-
j = self.__desc[name[1]]
103+
j = self.__desc[name[1]]
104104
elif type(name[1]) is list:
105105
j = []
106106
for n in name[1]:
107107
if type(n) is int:
108108
j.append(n)
109109
elif type(n) is str:
110-
j.append(self.__desc[n])
110+
j.append(self.__desc[n])
111111
else:
112112
j = name[1]
113113
i = name[0]
114114
return self.__raw_data[i,j]
115-
# Single value
115+
# Single value
116116
elif type(name) is str:
117117
j = self.__desc[name]
118118
return self.__raw_data[:,j]
@@ -126,14 +126,14 @@ def __getitem__(self, name):
126126
elif type(n) is str:
127127
j.append(self.__desc[n])
128128
return self.__raw_data[:,j]
129-
129+
130130
else:
131131
raise IndexError('Index does not exist!')
132-
132+
133133
def __str__(self):
134134
ret = 'Columns:'
135135
for i in range(self.__raw_data.shape[1]):
136-
ret += ' %i:%s'%(i,self.__desc[i])
136+
ret += ' %i:%s'%(i,self.__desc[i])
137137
ret += '\nData:\n'+str(self.__raw_data)
138-
138+
139139
return ret

xppy/utils/plot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
'''
2929
from __future__ import print_function
30+
from __future__ import absolute_import
3031

3132
import numpy as np #@UnresolvedImport
3233
from xppy.utils import allinfo

0 commit comments

Comments
 (0)