Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0c2e09

Browse files
committed
STY: pep8 on fileio modules
1 parent d812b5d commit b0c2e09

7 files changed

Lines changed: 77 additions & 77 deletions

File tree

nmrglue/fileio/convert.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ def from_varian(self, dic, data, udic=None):
154154
"""
155155
# set data
156156
self._data = data
157-
if udic != None and udic[0]['encoding'].lower() == "tppi":
157+
if udic is not None and udic[0]['encoding'].lower() == "tppi":
158158
self._iproc = {"imagfactor": -1.0}
159159
else: # states, etc needs sign alt. of indirect dim.
160160
self._iproc = {"alt_id_sign": True, "imagfactor": -1.0}
161161

162162
# set the universal dictionary
163-
if udic != None:
163+
if udic is not None:
164164
self._udic = udic
165165
else:
166166
self._udic = varian.guess_udic(dic, data)
@@ -191,7 +191,7 @@ def from_rnmrtk(self, dic, data, udic=None, agilent_compatible=False):
191191
self._iproc = {}
192192

193193
# set the universal dictionary
194-
if udic != None:
194+
if udic is not None:
195195
self._udic = udic
196196
else:
197197
self._udic = rnmrtk.guess_udic(dic, data)
@@ -215,7 +215,7 @@ def from_pipe(self, dic, data, udic=None):
215215
self._iproc = {}
216216

217217
# set the universal dictionary
218-
if udic != None:
218+
if udic is not None:
219219
self._udic = udic
220220
else:
221221
self._udic = pipe.guess_udic(dic, data)
@@ -239,7 +239,7 @@ def from_sparky(self, dic, data, udic=None):
239239
self._iproc = {}
240240

241241
# set the universal dictionary
242-
if udic != None:
242+
if udic is not None:
243243
self._udic = udic
244244
else:
245245
self._udic = sparky.guess_udic(dic, data)
@@ -263,7 +263,7 @@ def from_bruker(self, dic, data, udic=None):
263263
self._iproc = {}
264264

265265
# set the universal dictionary
266-
if udic != None:
266+
if udic is not None:
267267
self._udic = udic
268268
else:
269269
self._udic = bruker.guess_udic(dic, data)

nmrglue/fileio/fileiobase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def __convert(self, val, unit=None):
180180
if type(val) == str:
181181
return self.__str2pnt(val)
182182
else:
183-
if unit == None:
183+
if unit is None:
184184
raise ValueError("invalid unit type")
185185
return self.__unit2pnt(val, unit)
186186

@@ -334,12 +334,12 @@ def open_towrite(filename, overwrite=False):
334334
creates necessary directiories as needed.
335335
"""
336336
# check if file exists and overwrite if False
337-
if os.path.exists(filename) and (overwrite == False):
337+
if os.path.exists(filename) and (overwrite is False):
338338
raise IOError("File exists, recall with overwrite=True")
339339

340340
p, fn = os.path.split(filename) # split into filename and path
341341
# create directories if needed
342-
if p != '' and os.path.exists(p) == False:
342+
if p != '' and os.path.exists(p) is False:
343343
os.makedirs(p)
344344

345345
return open(filename, 'wb')

nmrglue/fileio/pipe.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def guess_udic(dic, data):
251251
udic[i]["freq"] = True
252252

253253
if i != 0:
254-
if dic["FD2DPHASE"] == 0:
254+
if dic["FD2DPHASE"] == 0:
255255
udic[i]["encoding"] = "magnitude"
256256
elif dic["FD2DPHASE"] == 1:
257257
udic[i]["encoding"] = "tppi"
@@ -309,8 +309,8 @@ def create_dic(udic, datetimeobj=datetime.datetime.now()):
309309
dic["FDFILECOUNT"] = dic["FDF3SIZE"] * dic["FDF4SIZE"]
310310

311311
if ((dic["FDF1QUADFLAG"] == dic["FDF2QUADFLAG"] == dic["FDF3QUADFLAG"]) and
312-
(dic["FDF1QUADFLAG"] == dic["FDF4QUADFLAG"] == 1)):
313-
dic["FDQUADFLAG"] = 1.0
312+
(dic["FDF1QUADFLAG"] == dic["FDF4QUADFLAG"] == 1)):
313+
dic["FDQUADFLAG"] = 1.0
314314

315315
return dic
316316

@@ -515,7 +515,7 @@ def read(filename):
515515
return read_2D(filename)
516516
if dic["FDPIPEFLAG"] != 0: # open streams
517517
return read_stream(filename)
518-
if filemask == None: # if no filemask open as 2D
518+
if filemask is None: # if no filemask open as 2D
519519
return read_2D(filename)
520520
if order == 3:
521521
return read_3D(filemask)
@@ -562,7 +562,7 @@ def read_lowmem(filename):
562562
return read_lowmem_2D(filename)
563563
if dic["FDPIPEFLAG"] != 0: # open streams
564564
return read_lowmem_stream(filename)
565-
if filemask == None: # if no filemask open as 2D
565+
if filemask is None: # if no filemask open as 2D
566566
return read_lowmem_2D(filename)
567567
if order == 3:
568568
return read_lowmem_3D(filemask)
@@ -1090,7 +1090,7 @@ def write_slice_3D(filemask, dic, data, shape, (sz, sy, sx)):
10901090
for i, f in enumerate(fnames[sz]):
10911091

10921092
#print "i:",i,"f:",f
1093-
if os.path.isfile(f) == False:
1093+
if os.path.isfile(f) is False:
10941094
# file doesn't exist, create a empty one
10951095
ndata = np.zeros((dy, dx), dtype=data.dtype)
10961096
write_single(f, dic, data, False)
@@ -1544,12 +1544,12 @@ def dic2fdata(dic):
15441544
# and the longer strings (typically blank)
15451545
fdata[286:290] = struct.unpack('4f', struct.pack('16s', dic["FDSRCNAME"]))
15461546
fdata[290:294] = struct.unpack('4f', struct.pack('16s',
1547-
dic["FDUSERNAME"]))
1547+
dic["FDUSERNAME"]))
15481548
fdata[297:312] = struct.unpack('15f', struct.pack('60s', dic["FDTITLE"]))
15491549
fdata[312:352] = struct.unpack('40f', struct.pack('160s',
1550-
dic["FDCOMMENT"]))
1550+
dic["FDCOMMENT"]))
15511551
fdata[464:472] = struct.unpack('8f', struct.pack('32s',
1552-
dic["FDOPERNAME"]))
1552+
dic["FDOPERNAME"]))
15531553

15541554
return fdata
15551555

@@ -1765,7 +1765,7 @@ def __init__(self, filemask, order=(0, 1, 2), fcheck=False):
17651765
# check that all files exist if fcheck is set
17661766
if fcheck:
17671767
for i in range(1, lenZ + 1):
1768-
if os.path.exists(filemask % i) == False:
1768+
if os.path.exists(filemask % i) is False:
17691769
raise IOError("File not found: " + str(filemask % i))
17701770

17711771
# check last axis quadrature
@@ -1973,7 +1973,7 @@ def __init__(self, filemask, order=(0, 1, 2, 3), fcheck=False):
19731973
fname = filemask % (ai * lenZ + zi + 1)
19741974
else:
19751975
fname = filemask % (ai + 1, zi + 1)
1976-
if os.path.exists(fname) == False:
1976+
if os.path.exists(fname) is False:
19771977
raise IOError("File not found: " + str(fname))
19781978

19791979
# check last axis quadrature
@@ -2015,7 +2015,7 @@ def __fgetitem__(self, (sA, sZ, sY, sX)):
20152015

20162016
# create an empty array to store the selected slice
20172017
out = np.empty((len(ach), len(zch), len(ych), len(xch)),
2018-
dtype=self.dtype)
2018+
dtype=self.dtype)
20192019

20202020
# read in the data file by file, trace by trace
20212021
for ai, a in enumerate(ach):
@@ -2109,7 +2109,7 @@ def __fgetitem__(self, (sA, sZ, sY, sX)):
21092109

21102110
# create an empty array to store the selected slice
21112111
out = np.empty((len(ach), len(zch), len(ych), len(xch)),
2112-
dtype=self.dtype)
2112+
dtype=self.dtype)
21132113

21142114
# read in the data trace by trace
21152115
for ai, a in enumerate(ach):

nmrglue/fileio/rnmrtk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def create_dic(udic, dim_order=None):
163163
dic['quad'] = [udic[i]['encoding'].lower() for i in dim_order]
164164

165165
# xfirst and xstep are freq domains values, correct later for time domain
166-
dic['xfirst'] = [-0.5 * i for i in dic['sw']]
166+
dic['xfirst'] = [-0.5 * i for i in dic['sw']]
167167
dic['xstep'] = [udic[i]['sw'] / udic[i]['size'] for i in dim_order]
168168

169169
# these we guess on, they may be incorrect
@@ -565,7 +565,7 @@ def __init__(self, filename, fshape, cplex, big, order=None):
565565
Create and set up
566566
"""
567567
# check and set order
568-
if order == None:
568+
if order is None:
569569
order = range(len(fshape))
570570
self.order = order
571571

@@ -587,7 +587,7 @@ def __fcopy__(self, order):
587587
Create a copy
588588
"""
589589
n = rnmrtk_nd(self.filename, self.filename, self.fshape, self.cplex,
590-
self.big, order)
590+
self.big, order)
591591
return n
592592

593593
def __fgetitem__(self, slices):
@@ -775,7 +775,7 @@ def write_par(par_file, dic, overwrite):
775775
f.write('Format Big-endian IEEE-Float\n')
776776

777777
l = "Layout " + " ".join([j + ":" + str(i) for i, j in
778-
zip(*dic['layout'])])
778+
zip(*dic['layout'])])
779779
f.write(l + "\n")
780780
f.close()
781781

nmrglue/fileio/sparky.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def __init__(self, filename, order=None):
574574
self.lentX = self.dic["w2"]["bsize"]
575575

576576
# check order
577-
if order == None:
577+
if order is None:
578578
order = (0, 1)
579579

580580
# finalize
@@ -706,7 +706,7 @@ def __init__(self, filename, order=None):
706706
self.lentX = self.dic["w3"]["bsize"]
707707

708708
# check order
709-
if order == None:
709+
if order is None:
710710
order = (0, 1, 2)
711711

712712
# finalize
@@ -1182,7 +1182,7 @@ def untile_data3D(data, (lentZ, lentY, lentX), (lenZ, lenY, lenX)):
11821182
maxT = (ntile + 1) * tsize
11831183

11841184
out[minZ:maxZ, minY:maxY, minX:maxX] = \
1185-
data[minT:maxT].reshape(t_tup)
1185+
data[minT:maxT].reshape(t_tup)
11861186

11871187
return out[:lenZ, :lenY, :lenX]
11881188

nmrglue/fileio/table.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ def insert_column(rec, N, col, name=None, format=None):
342342
col = np.array(col)
343343

344344
# get name and format parameter from column if not provided
345-
if name == None:
346-
if col.dtype.names != None:
345+
if name is None:
346+
if col.dtype.names is not None:
347347
name = col.dtype.names
348348
else:
349349
raise ValueError("Must provide a name for the column")
350-
if format == None:
350+
if format is None:
351351
format = col.dtype.str
352352

353353
# insert the new column (name, format) to the table dtypes

0 commit comments

Comments
 (0)