advise from pylint

This commit is contained in:
Martin Diehl 2020-03-22 17:03:28 +01:00
parent 1dfdd264b7
commit bbce3456e8
5 changed files with 142 additions and 143 deletions

View File

@ -75,7 +75,7 @@ class Result:
self.mat_physics += f['/'.join([self.increments[0],'materialpoint',m])].keys() self.mat_physics += f['/'.join([self.increments[0],'materialpoint',m])].keys()
self.mat_physics = list(set(self.mat_physics)) # make unique self.mat_physics = list(set(self.mat_physics)) # make unique
self.selection= {'increments': self.increments, self.selection = {'increments': self.increments,
'constituents': self.constituents,'materialpoints': self.materialpoints, 'constituents': self.constituents,'materialpoints': self.materialpoints,
'con_physics': self.con_physics, 'mat_physics': self.mat_physics 'con_physics': self.con_physics, 'mat_physics': self.mat_physics
} }
@ -129,7 +129,7 @@ class Result:
iterator = map(float,choice) iterator = map(float,choice)
choice = [] choice = []
for c in iterator: for c in iterator:
idx=np.searchsorted(self.times,c) idx = np.searchsorted(self.times,c)
if np.isclose(c,self.times[idx]): if np.isclose(c,self.times[idx]):
choice.append(self.increments[idx]) choice.append(self.increments[idx])
elif np.isclose(c,self.times[idx+1]): elif np.isclose(c,self.times[idx+1]):
@ -141,12 +141,12 @@ class Result:
if action == 'set': if action == 'set':
self.selection[what] = valid self.selection[what] = valid
elif action == 'add': elif action == 'add':
add=existing.union(valid) add = existing.union(valid)
add_sorted=sorted(add, key=lambda x: int("".join([i for i in x if i.isdigit()]))) add_sorted = sorted(add, key=lambda x: int("".join([i for i in x if i.isdigit()])))
self.selection[what] = add_sorted self.selection[what] = add_sorted
elif action == 'del': elif action == 'del':
diff=existing.difference(valid) diff = existing.difference(valid)
diff_sorted=sorted(diff, key=lambda x: int("".join([i for i in x if i.isdigit()]))) diff_sorted = sorted(diff, key=lambda x: int("".join([i for i in x if i.isdigit()])))
self.selection[what] = diff_sorted self.selection[what] = diff_sorted
@ -350,7 +350,7 @@ class Result:
groups.append(group) groups.append(group)
else: else:
match = [e for e_ in [glob.fnmatch.filter(f[group].keys(),s) for s in sets] for e in e_] match = [e for e_ in [glob.fnmatch.filter(f[group].keys(),s) for s in sets] for e in e_]
if len(set(match)) == len(sets) : groups.append(group) if len(set(match)) == len(sets): groups.append(group)
return groups return groups
@ -359,17 +359,17 @@ class Result:
message = '' message = ''
with h5py.File(self.fname,'r') as f: with h5py.File(self.fname,'r') as f:
for i in self.iterate('increments'): for i in self.iterate('increments'):
message+='\n{} ({}s)\n'.format(i,self.times[self.increments.index(i)]) message += '\n{} ({}s)\n'.format(i,self.times[self.increments.index(i)])
for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']): for o,p in zip(['constituents','materialpoints'],['con_physics','mat_physics']):
for oo in self.iterate(o): for oo in self.iterate(o):
message+=' {}\n'.format(oo) message += ' {}\n'.format(oo)
for pp in self.iterate(p): for pp in self.iterate(p):
message+=' {}\n'.format(pp) message += ' {}\n'.format(pp)
group = '/'.join([i,o[:-1],oo,pp]) # o[:-1]: plural/singular issue group = '/'.join([i,o[:-1],oo,pp]) # o[:-1]: plural/singular issue
for d in f[group].keys(): for d in f[group].keys():
try: try:
dataset = f['/'.join([group,d])] dataset = f['/'.join([group,d])]
message+=' {} / ({}): {}\n'.\ message += ' {} / ({}): {}\n'.\
format(d,dataset.attrs['Unit'].decode(),dataset.attrs['Description'].decode()) format(d,dataset.attrs['Unit'].decode(),dataset.attrs['Description'].decode())
except KeyError: except KeyError:
pass pass
@ -425,7 +425,7 @@ class Result:
for pa in path: for pa in path:
label = pa.split('/')[2] label = pa.split('/')[2]
if (pa.split('/')[1] == 'geometry'): if pa.split('/')[1] == 'geometry':
dataset = np.array(f[pa]) dataset = np.array(f[pa])
continue continue

View File

@ -365,8 +365,7 @@ class Rotation:
@staticmethod @staticmethod
def fromAverage(rotations, def fromAverage(rotations,weights = None):
weights = []):
""" """
Average rotation. Average rotation.
@ -387,7 +386,7 @@ class Rotation:
raise TypeError("Only instances of Rotation can be averaged.") raise TypeError("Only instances of Rotation can be averaged.")
N = len(rotations) N = len(rotations)
if weights == [] or not weights: if not weights:
weights = np.ones(N,dtype='i') weights = np.ones(N,dtype='i')
for i,(r,n) in enumerate(zip(rotations,weights)): for i,(r,n) in enumerate(zip(rotations,weights)):

View File

@ -327,9 +327,9 @@ class Table:
seen = set() seen = set()
labels = [] labels = []
for l in [x for x in self.data.columns if not (x in seen or seen.add(x))]: for l in [x for x in self.data.columns if not (x in seen or seen.add(x))]:
if(self.shapes[l] == (1,)): if self.shapes[l] == (1,):
labels.append('{}'.format(l)) labels.append('{}'.format(l))
elif(len(self.shapes[l]) == 1): elif len(self.shapes[l]) == 1:
labels += ['{}_{}'.format(i+1,l) \ labels += ['{}_{}'.format(i+1,l) \
for i in range(self.shapes[l][0])] for i in range(self.shapes[l][0])]
else: else:

View File

@ -103,7 +103,7 @@ class VTK:
Spatial position of the points. Spatial position of the points.
""" """
vtk_points= vtk.vtkPoints() vtk_points = vtk.vtkPoints()
vtk_points.SetData(np_to_vtk(points)) vtk_points.SetData(np_to_vtk(points))
geom = vtk.vtkPolyData() geom = vtk.vtkPolyData()
@ -168,11 +168,11 @@ class VTK:
Filename for writing. Filename for writing.
""" """
if (isinstance(self.geom,vtk.vtkRectilinearGrid)): if isinstance(self.geom,vtk.vtkRectilinearGrid):
writer = vtk.vtkXMLRectilinearGridWriter() writer = vtk.vtkXMLRectilinearGridWriter()
elif(isinstance(self.geom,vtk.vtkUnstructuredGrid)): elif isinstance(self.geom,vtk.vtkUnstructuredGrid):
writer = vtk.vtkXMLUnstructuredGridWriter() writer = vtk.vtkXMLUnstructuredGridWriter()
elif(isinstance(self.geom,vtk.vtkPolyData)): elif isinstance(self.geom,vtk.vtkPolyData):
writer = vtk.vtkXMLPolyDataWriter() writer = vtk.vtkXMLPolyDataWriter()
default_ext = writer.GetDefaultFileExtension() default_ext = writer.GetDefaultFileExtension()
@ -234,17 +234,17 @@ class VTK:
ren = vtk.vtkRenderer() ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow() window = vtk.vtkRenderWindow()
renWin.AddRenderer(ren) window.AddRenderer(ren)
ren.AddActor(actor) ren.AddActor(actor)
ren.SetBackground(0.2,0.2,0.2) ren.SetBackground(0.2,0.2,0.2)
renWin.SetSize(Environment().screen_width,Environment().screen_height) window.SetSize(Environment().screen_width,Environment().screen_height)
iren = vtk.vtkRenderWindowInteractor() iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin) iren.SetRenderWindow(window)
iren.Initialize() iren.Initialize()
renWin.Render() window.Render()
iren.Start() iren.Start()