Skip to content

Commit 8cb5870

Browse files
mdenkerapdavison
authored andcommitted
PEP8 fixes for the 0.7.0 release (#608)
1 parent f12ec64 commit 8cb5870

31 files changed

+363
-373
lines changed

.pep8speaks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pycodestyle:
22
max-line-length: 99 # Default is 79 in PEP8
33
ignore:
4+
- W503 # Change in PEP8, this warning is replaced by W504
45
- E127
56
- E128

doc/source/images/generate_diagram.py

+40-41
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ def get_rect_height(name, obj):
3232
nlines += len(getattr(obj, '_single_child_objects', []))
3333
nlines += len(getattr(obj, '_multi_child_objects', []))
3434
nlines += len(getattr(obj, '_multi_parent_objects', []))
35-
return nlines*line_heigth
35+
return nlines * line_heigth
3636

3737

3838
def annotate(ax, coord1, coord2, connectionstyle, color, alpha):
3939
arrowprops = dict(arrowstyle='fancy',
40-
#~ patchB=p,
40+
# ~ patchB=p,
4141
shrinkA=.3, shrinkB=.3,
4242
fc=color, ec=color,
4343
connectionstyle=connectionstyle,
4444
alpha=alpha)
4545
bbox = dict(boxstyle="square", fc="w")
4646
a = ax.annotate('', coord1, coord2,
47-
#xycoords="figure fraction",
48-
#textcoords="figure fraction",
47+
# xycoords="figure fraction",
48+
# textcoords="figure fraction",
4949
ha="right", va="center",
5050
size=fontsize,
5151
arrowprops=arrowprops,
@@ -55,7 +55,7 @@ def annotate(ax, coord1, coord2, connectionstyle, color, alpha):
5555

5656
def calc_coordinates(pos, height):
5757
x = pos[0]
58-
y = pos[1] + height - line_heigth*.5
58+
y = pos[1] + height - line_heigth * .5
5959

6060
return pos[0], y
6161

@@ -102,45 +102,44 @@ def generate_diagram(filename, rect_pos, rect_width, figsize):
102102
for name, pos in rect_pos.items():
103103
htotal = all_h[name]
104104
obj = objs[name]
105-
allrelationship = (list(getattr(obj, '_child_containers', [])) +
106-
list(getattr(obj, '_multi_parent_containers', [])))
105+
allrelationship = (list(getattr(obj, '_child_containers', []))
106+
+ list(getattr(obj, '_multi_parent_containers', [])))
107107

108108
rect = Rectangle(pos, rect_width, htotal,
109109
facecolor='w', edgecolor='k', linewidth=2.)
110110
ax.add_patch(rect)
111111

112112
# title green
113-
pos2 = pos[0], pos[1]+htotal - line_heigth*1.5
114-
rect = Rectangle(pos2, rect_width, line_heigth*1.5,
113+
pos2 = pos[0], pos[1] + htotal - line_heigth * 1.5
114+
rect = Rectangle(pos2, rect_width, line_heigth * 1.5,
115115
facecolor='g', edgecolor='k', alpha=.5, linewidth=2.)
116116
ax.add_patch(rect)
117117

118118
# single relationship
119119
relationship = getattr(obj, '_single_child_objects', [])
120-
pos2 = pos[1] + htotal - line_heigth*(1.5+len(relationship))
121-
rect_height = len(relationship)*line_heigth
120+
pos2 = pos[1] + htotal - line_heigth * (1.5 + len(relationship))
121+
rect_height = len(relationship) * line_heigth
122122

123123
rect = Rectangle((pos[0], pos2), rect_width, rect_height,
124124
facecolor='c', edgecolor='k', alpha=.5)
125125
ax.add_patch(rect)
126126

127127
# multi relationship
128-
relationship = (list(getattr(obj, '_multi_child_objects', [])) +
129-
list(getattr(obj, '_multi_parent_containers', [])))
130-
pos2 = (pos[1]+htotal - line_heigth*(1.5+len(relationship)) -
131-
rect_height)
132-
rect_height = len(relationship)*line_heigth
128+
relationship = (list(getattr(obj, '_multi_child_objects', []))
129+
+ list(getattr(obj, '_multi_parent_containers', [])))
130+
pos2 = (pos[1] + htotal - line_heigth * (1.5 + len(relationship))
131+
- rect_height)
132+
rect_height = len(relationship) * line_heigth
133133

134134
rect = Rectangle((pos[0], pos2), rect_width, rect_height,
135135
facecolor='m', edgecolor='k', alpha=.5)
136136
ax.add_patch(rect)
137137

138138
# necessary attr
139-
pos2 = (pos[1]+htotal -
140-
line_heigth*(1.5+len(allrelationship) +
141-
len(obj._necessary_attrs)))
139+
pos2 = (pos[1] + htotal
140+
- line_heigth * (1.5 + len(allrelationship) + len(obj._necessary_attrs)))
142141
rect = Rectangle((pos[0], pos2), rect_width,
143-
line_heigth*len(obj._necessary_attrs),
142+
line_heigth * len(obj._necessary_attrs),
144143
facecolor='r', edgecolor='k', alpha=.5)
145144
ax.add_patch(rect)
146145

@@ -149,27 +148,27 @@ def generate_diagram(filename, rect_pos, rect_width, figsize):
149148
post = '* '
150149
else:
151150
post = ''
152-
ax.text(pos[0]+rect_width/2., pos[1]+htotal - line_heigth*1.5/2.,
153-
name+post,
151+
ax.text(pos[0] + rect_width / 2., pos[1] + htotal - line_heigth * 1.5 / 2.,
152+
name + post,
154153
horizontalalignment='center', verticalalignment='center',
155-
fontsize=fontsize+2,
154+
fontsize=fontsize + 2,
156155
fontproperties=FontProperties(weight='bold'),
157156
)
158157

159-
#relationship
158+
# relationship
160159
for i, relat in enumerate(allrelationship):
161-
ax.text(pos[0]+left_text_shift, pos[1]+htotal - line_heigth*(i+2),
162-
relat+': list',
160+
ax.text(pos[0] + left_text_shift, pos[1] + htotal - line_heigth * (i + 2),
161+
relat + ': list',
163162
horizontalalignment='left', verticalalignment='center',
164163
fontsize=fontsize,
165164
)
166165
# attributes
167166
for i, attr in enumerate(obj._all_attrs):
168167
attrname, attrtype = attr[0], attr[1]
169168
t1 = attrname
170-
if (hasattr(obj, '_quantity_attr') and
171-
obj._quantity_attr == attrname):
172-
t1 = attrname+'(object itself)'
169+
if (hasattr(obj, '_quantity_attr')
170+
and obj._quantity_attr == attrname):
171+
t1 = attrname + '(object itself)'
173172
else:
174173
t1 = attrname
175174

@@ -185,9 +184,9 @@ def generate_diagram(filename, rect_pos, rect_width, figsize):
185184
else:
186185
t2 = attrtype.__name__
187186

188-
t = t1+' : '+t2
189-
ax.text(pos[0]+left_text_shift,
190-
pos[1]+htotal - line_heigth*(i+len(allrelationship)+2),
187+
t = t1 + ' : ' + t2
188+
ax.text(pos[0] + left_text_shift,
189+
pos[1] + htotal - line_heigth * (i + len(allrelationship) + 2),
191190
t,
192191
horizontalalignment='left', verticalalignment='center',
193192
fontsize=fontsize,
@@ -206,15 +205,15 @@ def generate_diagram_simple():
206205
figsize = (18, 12)
207206
rw = rect_width = 3.
208207
bf = blank_fact = 1.2
209-
rect_pos = {'Block': (.5+rw*bf*0, 4),
210-
'Segment': (.5+rw*bf*1, .5),
211-
'Event': (.5+rw*bf*4, 3.0),
212-
'Epoch': (.5+rw*bf*4, 1.0),
213-
'ChannelIndex': (.5+rw*bf*1, 7.5),
214-
'Unit': (.5+rw*bf*2., 9.9),
215-
'SpikeTrain': (.5+rw*bf*3, 7.5),
216-
'IrregularlySampledSignal': (.5+rw*bf*3, 0.5),
217-
'AnalogSignal': (.5+rw*bf*3, 4.9),
208+
rect_pos = {'Block': (.5 + rw * bf * 0, 4),
209+
'Segment': (.5 + rw * bf * 1, .5),
210+
'Event': (.5 + rw * bf * 4, 3.0),
211+
'Epoch': (.5 + rw * bf * 4, 1.0),
212+
'ChannelIndex': (.5 + rw * bf * 1, 7.5),
213+
'Unit': (.5 + rw * bf * 2., 9.9),
214+
'SpikeTrain': (.5 + rw * bf * 3, 7.5),
215+
'IrregularlySampledSignal': (.5 + rw * bf * 3, 0.5),
216+
'AnalogSignal': (.5 + rw * bf * 3, 4.9),
218217
}
219218
generate_diagram('simple_generated_diagram.svg',
220219
rect_pos, rect_width, figsize)

neo/core/dataobject.py

-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def __init__(self, name=None, description=None, file_origin=None, array_annotati
174174
**annotations)
175175

176176
def array_annotate(self, **array_annotations):
177-
178177
"""
179178
Add array annotations (annotations for individual data points) as arrays to a Neo data
180179
object.
@@ -189,7 +188,6 @@ def array_annotate(self, **array_annotations):
189188
self.array_annotations.update(array_annotations)
190189

191190
def array_annotations_at_index(self, index):
192-
193191
"""
194192
Return dictionary of array annotations at a given index or list of indices
195193
:param index: int, list, numpy array: The index (indices) from which the annotations

neo/io/axographio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ def read_block(self, **kargs):
149149

150150
blk.create_many_to_one_relationship()
151151

152-
return blk
152+
return blk

neo/io/basefromrawio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def read_block(self, block_index=0, lazy=False, signal_group_mode=None,
134134
for j in ind_abs:
135135
for key in list(self.raw_annotations['signal_channels'][i].keys()):
136136
chidx_annotations[key].append(self.raw_annotations[
137-
'signal_channels'][j][key])
137+
'signal_channels'][j][key])
138138
if 'name' in list(chidx_annotations.keys()):
139139
chidx_annotations.pop('name')
140140
chidx_annotations = check_annotations(chidx_annotations)

neo/io/blackrockio_v4.py

+35-35
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def __init__(self, filename, nsx_override=None, nev_override=None,
278278
exts = ['nsx', 'nev', 'sif', 'ccf']
279279
ext_overrides = [nsx_override, nev_override, sif_override, ccf_override]
280280
for ext, ext_override in zip(exts, ext_overrides):
281-
if ext_override is not None and self._avail_files[ext] == False:
281+
if ext_override is not None and self._avail_files[ext] is False:
282282
raise ValueError('Specified {} file {} could not be '
283283
'found.'.format(ext, ext_override))
284284

@@ -1108,8 +1108,8 @@ def __get_nsx_rec_times_variant_a(self, nsx_nb):
11081108
bytes_in_headers = self.__nsx_params[self.__nsx_spec[nsx_nb]](
11091109
'bytes_in_headers', nsx_nb)
11101110
nb_data_points = int(
1111-
(self.__get_file_size(filename) - bytes_in_headers) /
1112-
(2 * self.__nsx_basic_header[nsx_nb]['channel_count']) - 1)
1111+
(self.__get_file_size(filename) - bytes_in_headers)
1112+
/ (2 * self.__nsx_basic_header[nsx_nb]['channel_count']) - 1)
11131113

11141114
# add n_start
11151115
n_starts = [(0 * t_unit).rescale(highest_res)]
@@ -1267,8 +1267,8 @@ def __get_nsx_param_variant_a(self, param_name, nsx_nb):
12671267
nsx_parameters = {
12681268
'labels': labels,
12691269
'units': np.array(
1270-
[b'uV'] *
1271-
self.__nsx_basic_header[nsx_nb]['channel_count']),
1270+
[b'uV']
1271+
* self.__nsx_basic_header[nsx_nb]['channel_count']),
12721272
'min_analog_val': -1 * np.array(dig_factor),
12731273
'max_analog_val': np.array(dig_factor),
12741274
'min_digital_val': np.array(
@@ -1277,9 +1277,9 @@ def __get_nsx_param_variant_a(self, param_name, nsx_nb):
12771277
[1000] * self.__nsx_basic_header[nsx_nb]['channel_count']),
12781278
'timestamp_resolution': 30000,
12791279
'bytes_in_headers':
1280-
self.__nsx_basic_header[nsx_nb].dtype.itemsize +
1281-
self.__nsx_ext_header[nsx_nb].dtype.itemsize *
1282-
self.__nsx_basic_header[nsx_nb]['channel_count'],
1280+
self.__nsx_basic_header[nsx_nb].dtype.itemsize
1281+
+ self.__nsx_ext_header[nsx_nb].dtype.itemsize
1282+
* self.__nsx_basic_header[nsx_nb]['channel_count'],
12831283
'sampling_rate':
12841284
30000 / self.__nsx_basic_header[nsx_nb]['period'] * pq.Hz,
12851285
'time_unit': pq.CompoundUnit("1.0/{0}*s".format(
@@ -1310,11 +1310,11 @@ def __get_nsx_param_variant_b(self, param_name, nsx_nb):
13101310
'bytes_in_headers':
13111311
self.__nsx_basic_header[nsx_nb]['bytes_in_headers'],
13121312
'sampling_rate':
1313-
self.__nsx_basic_header[nsx_nb]['timestamp_resolution'] /
1314-
self.__nsx_basic_header[nsx_nb]['period'] * pq.Hz,
1313+
self.__nsx_basic_header[nsx_nb]['timestamp_resolution']
1314+
/ self.__nsx_basic_header[nsx_nb]['period'] * pq.Hz,
13151315
'time_unit': pq.CompoundUnit("1.0/{0}*s".format(
1316-
self.__nsx_basic_header[nsx_nb]['timestamp_resolution'] /
1317-
self.__nsx_basic_header[nsx_nb]['period']))}
1316+
self.__nsx_basic_header[nsx_nb]['timestamp_resolution']
1317+
/ self.__nsx_basic_header[nsx_nb]['period']))}
13181318

13191319
return nsx_parameters[param_name]
13201320

@@ -1336,8 +1336,8 @@ def __get_nsx_databl_param_variant_a(
13361336
# extract parameters from nsx basic extended and data header
13371337
data_parameters = {
13381338
'nb_data_points': int(
1339-
(self.__get_file_size(filename) - bytes_in_headers) /
1340-
(2 * self.__nsx_basic_header[nsx_nb]['channel_count']) - 1),
1339+
(self.__get_file_size(filename) - bytes_in_headers)
1340+
/ (2 * self.__nsx_basic_header[nsx_nb]['channel_count']) - 1),
13411341
'databl_idx': 1,
13421342
'databl_t_start': t_starts[0],
13431343
'databl_t_stop': t_stops[0]}
@@ -1410,8 +1410,8 @@ def __get_nonneural_evtypes_variant_a(self, data):
14101410
'name': 'serial_input_port',
14111411
'field': 'digital_input',
14121412
'mask':
1413-
self.__is_set(data['packet_insertion_reason'], 0) &
1414-
self.__is_set(data['packet_insertion_reason'], 7),
1413+
self.__is_set(data['packet_insertion_reason'], 0)
1414+
& self.__is_set(data['packet_insertion_reason'], 7),
14151415
'desc': "Events of the serial input port"}}
14161416

14171417
# analog input events via threshold crossings
@@ -1451,8 +1451,8 @@ def __get_nonneural_evtypes_variant_b(self, data):
14511451
'name': 'serial_input_port',
14521452
'field': 'digital_input',
14531453
'mask':
1454-
self.__is_set(data['packet_insertion_reason'], 0) &
1455-
self.__is_set(data['packet_insertion_reason'], 7),
1454+
self.__is_set(data['packet_insertion_reason'], 0)
1455+
& self.__is_set(data['packet_insertion_reason'], 7),
14561456
'desc': "Events of the serial input port"}}
14571457

14581458
return event_types
@@ -1658,7 +1658,7 @@ def __merge_time_ranges(
16581658
"".format(user_n_stops[start_stop_id]))
16591659

16601660
if (user_n_stops[start_stop_id] < min_time
1661-
or user_n_starts[start_stop_id] > max_time):
1661+
or user_n_starts[start_stop_id] > max_time):
16621662
user_n_stops.pop(start_stop_id)
16631663
user_n_starts.pop(start_stop_id)
16641664
self._print_verbose(
@@ -1721,7 +1721,7 @@ def __merge_time_ranges(
17211721
mask = (n_stops_files > start) & (n_stops_files < stop)
17221722
red_n_stops_files = np.array(n_stops_files)[mask]
17231723
merged_n_stops = [
1724-
tp * highest_res for tp in red_n_stops_files] + [stop]
1724+
tp * highest_res for tp in red_n_stops_files] + [stop]
17251725
else:
17261726
merged_n_stops = [stop]
17271727
# Define combined user and file n_starts and n_stops
@@ -1747,7 +1747,7 @@ def __merge_time_ranges(
17471747
n_stops.extend(merged_n_stops)
17481748

17491749
if len(n_starts) > len(user_n_starts) and \
1750-
len(n_stops) > len(user_n_stops):
1750+
len(n_stops) > len(user_n_stops):
17511751
self._print_verbose(
17521752
"Additional recording pauses were detected. There will be "
17531753
"more segments than the user expects.")
@@ -1826,9 +1826,9 @@ def __read_spiketrain(
18261826

18271827
if scaling == 'voltage':
18281828
st.waveforms = (
1829-
waveforms[mask] * self.__nev_params('waveform_unit') *
1830-
self.__nev_params('digitization_factor')[channel_id] /
1831-
1000.)
1829+
waveforms[mask] * self.__nev_params('waveform_unit')
1830+
* self.__nev_params('digitization_factor')[channel_id]
1831+
/ 1000.)
18321832
elif scaling == 'raw':
18331833
st.waveforms = waveforms[mask] * pq.dimensionless
18341834
else:
@@ -2008,11 +2008,11 @@ def __read_channelindex(
20082008
nev_dig_factor=self.__nev_ext_header[
20092009
b'NEUEVWAV']['digitization_factor'][get_idx],
20102010
nev_energy_threshold=self.__nev_ext_header[
2011-
b'NEUEVWAV']['energy_threshold'][get_idx] * pq.uV,
2011+
b'NEUEVWAV']['energy_threshold'][get_idx] * pq.uV,
20122012
nev_hi_threshold=self.__nev_ext_header[
2013-
b'NEUEVWAV']['hi_threshold'][get_idx] * pq.uV,
2013+
b'NEUEVWAV']['hi_threshold'][get_idx] * pq.uV,
20142014
nev_lo_threshold=self.__nev_ext_header[
2015-
b'NEUEVWAV']['lo_threshold'][get_idx] * pq.uV,
2015+
b'NEUEVWAV']['lo_threshold'][get_idx] * pq.uV,
20162016
nb_sorted_units=self.__nev_ext_header[
20172017
b'NEUEVWAV']['nb_sorted_units'][get_idx],
20182018
waveform_size=self.__waveform_size[self.__nev_spec](
@@ -2027,15 +2027,15 @@ def __read_channelindex(
20272027
# filter type codes (extracted from blackrock manual)
20282028
chidx.annotate(
20292029
nev_hi_freq_corner=self.__nev_ext_header[b'NEUEVFLT'][
2030-
'hi_freq_corner'][get_idx] /
2031-
1000. * pq.Hz,
2030+
'hi_freq_corner'][get_idx]
2031+
/ 1000. * pq.Hz,
20322032
nev_hi_freq_order=self.__nev_ext_header[b'NEUEVFLT'][
20332033
'hi_freq_order'][get_idx],
20342034
nev_hi_freq_type=flt_type[self.__nev_ext_header[
20352035
b'NEUEVFLT']['hi_freq_type'][get_idx]],
20362036
nev_lo_freq_corner=self.__nev_ext_header[
2037-
b'NEUEVFLT']['lo_freq_corner'][get_idx] /
2038-
1000. * pq.Hz,
2037+
b'NEUEVFLT']['lo_freq_corner'][get_idx]
2038+
/ 1000. * pq.Hz,
20392039
nev_lo_freq_order=self.__nev_ext_header[
20402040
b'NEUEVFLT']['lo_freq_order'][get_idx],
20412041
nev_lo_freq_type=flt_type[self.__nev_ext_header[
@@ -2051,9 +2051,9 @@ def __read_channelindex(
20512051
channel_id)
20522052
chidx.annotate(
20532053
nsx_hi_freq_corner=self.__nsx_ext_header[k][
2054-
'hi_freq_corner'][get_idx] / 1000. * pq.Hz,
2054+
'hi_freq_corner'][get_idx] / 1000. * pq.Hz,
20552055
nsx_lo_freq_corner=self.__nsx_ext_header[k][
2056-
'lo_freq_corner'][get_idx] / 1000. * pq.Hz,
2056+
'lo_freq_corner'][get_idx] / 1000. * pq.Hz,
20572057
nsx_hi_freq_order=self.__nsx_ext_header[k][
20582058
'hi_freq_order'][get_idx],
20592059
nsx_lo_freq_order=self.__nsx_ext_header[k][
@@ -2558,8 +2558,8 @@ def __str__(self):
25582558
'sampling_rate', nsx_nb)
25592559
avail_el = [
25602560
el for el in self.__nsx_ext_header[nsx_nb]['electrode_id']]
2561-
output += "\nAnalog Parameters (NS" + str(nsx_nb) + ")" \
2562-
"\n===================================="
2561+
output += "\nAnalog Parameters (NS" \
2562+
+ str(nsx_nb) + ")\n===================================="
25632563
output += "\nResolution (Hz): %i" % analog_res
25642564
output += "\nAvailable channel IDs: " + \
25652565
", ".join(["%i" % a for a in avail_el]) + "\n"

0 commit comments

Comments
 (0)