Skip to content

Commit

Permalink
lgtm linting in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwright committed Aug 29, 2019
1 parent 14714ff commit 5a90a95
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 94 deletions.
2 changes: 1 addition & 1 deletion ImageD11src/ImageD11_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import queue as Queue

import threading
global stop_now
# global stop_now
stop_now = False

class ImageD11_thread(threading.Thread):
Expand Down
13 changes: 6 additions & 7 deletions ImageD11src/blobcorrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def readfit2dfloats(filep, nfl):
i = i + 14
if j == nfl:
break
i = i + 1
return ret

class correctorclass: #IGNORE:R0902
Expand Down Expand Up @@ -197,8 +196,8 @@ def readfit2dspline(self, name):
if myline[:7] != "SPATIAL":
raise SyntaxError(name + \
": file does not seem to be a fit2d spline file")
myline = fin.readline() # BLANK LINE
myline = fin.readline() # VALID REGION
fin.readline() # BLANK LINE
fin.readline() # VALID REGION
myline = fin.readline() # the actual valid region,
# assuming xmin,ymin,xmax,ymax
logging.debug("xmin,ymin,xmax,ymax, read: "+myline)
Expand All @@ -210,8 +209,8 @@ def readfit2dspline(self, name):
logging.debug("gridspace, xsize, ysize: "+myline)
self.gridspacing, self.xsize, self.ysize = \
[float(z) for z in myline.split()]
myline = fin.readline() # BLANK
myline = fin.readline() # X-DISTORTION
fin.readline() # BLANK
fin.readline() # X-DISTORTION
myline = fin.readline() # two integers nx1,ny1
logging.debug("nx1, ny1 read: "+myline)
nx1, ny1 = [int(z) for z in myline.split()]
Expand All @@ -220,8 +219,8 @@ def readfit2dspline(self, name):
ty1 = numpy.array(readfit2dfloats(fin, ny1), numpy.float32)
cf1 = numpy.array(readfit2dfloats(fin, (nx1 - 4) * (ny1 - 4)),
numpy.float32)
myline = fin.readline() #BLANK
myline = fin.readline() # Y-DISTORTION
fin.readline() #BLANK
fin.readline() # Y-DISTORTION
myline = fin.readline() # two integers nx2, ny2
nx2 , ny2 = [int(z) for z in myline.split()]
tx2 = numpy.array(readfit2dfloats(fin, nx2), numpy.float32)
Expand Down
1 change: 1 addition & 0 deletions ImageD11src/correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def correct(data_object,
# direction of a previously radially transformed image
# Gives the liquid contribution
med = numpy.median( picture )
# FIXME
if True: # Suboption - save the median or not?
obj = fabio.deconstruct_filename( data_object.header['filename'] )
obj.extension = ".bkm"
Expand Down
2 changes: 1 addition & 1 deletion ImageD11src/eps_sig_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def compute_write_eps_sig(self,outputfile):
except:
print("couldn't compute stress! please check the crystal_symmetry parameters and elastic constants")
writestress = False
pass


''' writing down the results'''

Expand Down
30 changes: 15 additions & 15 deletions ImageD11src/fft_index_refac.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,21 @@ def slow_score(self):



sm = np.zeros( (len(diff), len(diff)), np.float)
for k in range(len(diff)):
i = order[k]
sm[i,i] = np.dot(diff[i], diff[i])
for k in range(len(diff)-1):
i = order[k]
for l in range(i+1, len(diff)):
j = order[l]
sm[i,j] = np.dot(diff[i],diff[j])/sm[i,i]/sm[j,j]
sm[j,i] = sm[i,j]
for i in range(len(diff)):
sm[i,i] = 1.
print(sm[:5,:5])
print("Scoring takes",time.time()-start)
return sm
# sm = np.zeros( (len(diff), len(diff)), np.float)
# for k in range(len(diff)):
# i = order[k]
# sm[i,i] = np.dot(diff[i], diff[i])
# for k in range(len(diff)-1):
# i = order[k]
# for l in range(i+1, len(diff)):
# j = order[l]
# sm[i,j] = np.dot(diff[i],diff[j])/sm[i,i]/sm[j,j]
# sm[j,i] = sm[i,j]
# for i in range(len(diff)):
# sm[i,i] = 1.
# print(sm[:5,:5])
# print("Scoring takes",time.time()-start)
# return sm

#####
# To Do
Expand Down
3 changes: 1 addition & 2 deletions ImageD11src/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def updatecolfile(self):
elif "xc" in self.cf.titles:
pks = self.cf.xc, self.cf.yc
else:
raise "peaks file misses xc or sc"
raise Exception("peaks file misses xc or sc")
xl,yl,zl = transform.compute_xyz_lab( pks,
**self.transformpars.parameters)
self.cf.addcolumn(xl,"xl")
Expand Down Expand Up @@ -132,7 +132,6 @@ def assigntorings(self):
"""
Assign the g-vectors to hkl rings that are in self.unitcell
"""
dsr = self.unitcell.ringds
self.cf.ring[:]=-1
self.cf.ringerr[:]=42.
tol = self.transformpars.get( "fit_tolerance" )
Expand Down
1 change: 0 additions & 1 deletion ImageD11src/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ def find(self):
# found=0
hits=[]
start = time.time()
start=time.time()
mtol = -tol # Ugly interface - set cosine tolerance negative for all
# instead of best
for i in range(len(i1)):
Expand Down
10 changes: 3 additions & 7 deletions ImageD11src/peaksearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,9 @@ def fso(f0,f1):
# Make a blobimage the same size as the first image to process


# List comprehension - convert remaining args to floats - must be unique list
thresholds_list = [float(t) for t in options.thresholds]
try:
thresholds_list = list(set(thresholds_list))
except:
import sets
thresholds_list = list(sets.Set(thresholds_list))
# List comprehension - convert remaining args to floats
# must be unique list so go via a set
thresholds_list = list( set( [float(t) for t in options.thresholds] ) )
thresholds_list.sort()

li_objs={} # label image objects, dict of
Expand Down
2 changes: 1 addition & 1 deletion ImageD11src/refinegrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def readubis(self, filename):
print(filename, type(filename))
raise
for i, g in enumerate(ul):
name = filename + "_" + str(i)
# name = filename + "_" + str(i)
# Hmmm .... multiple grain files?
name = i
self.grainnames.append(i)
Expand Down
3 changes: 1 addition & 2 deletions ImageD11src/rotdex.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def fit_ub_t( ub, translation, hkl, peaks_Cxyz, beam_Cxyz, wavelength):
dg[i+9] = dgobsdt[i] # translation at 9,10,11
gcalc = np.dot( ubnew , hkl ) # 3xn
gdiff = gcalc - gobs
if 0:
print((gdiff*gdiff).ravel().sum(),tnew)
# print((gdiff*gdiff).ravel().sum(),tnew)
dg.shape = 12,3*npk
mat = np.dot( dg, dg.T )
rhs = np.dot( dg, gdiff.ravel() )
Expand Down
2 changes: 1 addition & 1 deletion ImageD11src/rsv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from __future__ import print_function. division
from __future__ import print_function, division

"""
Reciprocal Space Volume
Expand Down
1 change: 0 additions & 1 deletion ImageD11src/silxGui/silx_sptview.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def warn(self, message):
silx.gui.qt.QMessageBox.warning(None, "Warning", message)

if __name__=="__main__":
global app
qapp = silx.gui.qt.QApplication([])
s=sptview( sys.argv[1] )
s.window.show()
Expand Down
6 changes: 2 additions & 4 deletions ImageD11src/sym_u.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ def m_to_string(m):
"""
st = []
for i in range(3):
needplus = 0 # ???
for v,s in zip([ [ 1,0,0] , [ 0,1,0], [0,0,1] ],
"xyz"):
c = np.dot(v,m.T[i])
if abs(c)>0:
st.append( "%s%s"%(fmt(c),s))
needplus = 1
if i<2:
st.append(",")
return "".join(st)
Expand Down Expand Up @@ -267,8 +265,8 @@ def __init__(self, tol = 1e-5):
"""
Identity is to not move at all
"""
self.group = [ np.zeros(3, np.float) ]
self.tol = tol
group.__init__(self,tol)

def op(self, x, y):
"""
Means of generating new thing from two others
Expand Down
30 changes: 15 additions & 15 deletions ImageD11src/tkGui/twodplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ def keypress(self,*arg):

def bindkeys(self):
return
self.bind_all('<Left>' ,lambda e: self.keypress(self.a.panx,1 ) )
self.bind_all('<Right>',lambda e: self.keypress(self.a.panx,-1) )
self.bind_all('<Up>' ,lambda e: self.keypress(self.a.pany,-1 ) )
self.bind_all('<Down>' ,lambda e: self.keypress(self.a.pany,1) )
self.bind_all('<Shift-Left>' ,lambda e: self.keypress(self.a.zoomx,-1 ) )
self.bind_all('<Shift-Right>',lambda e: self.keypress(self.a.zoomx,1) )
self.bind_all('<Shift-Up>' ,lambda e: self.keypress(self.a.zoomy,1 ) )
self.bind_all('<Shift-Down>' ,lambda e: self.keypress(self.a.zoomy,-1) )
self.bind_all('<Next>' , lambda e : self.keypress(self.autoscale) )
self.bind_all('<Prior>', lambda e : self.keypress(self.autoscaley, e ) )
# self.bind_all('<Left>' ,lambda e: self.keypress(self.a.panx,1 ) )
# self.bind_all('<Right>',lambda e: self.keypress(self.a.panx,-1) )
# self.bind_all('<Up>' ,lambda e: self.keypress(self.a.pany,-1 ) )
# self.bind_all('<Down>' ,lambda e: self.keypress(self.a.pany,1) )
# self.bind_all('<Shift-Left>' ,lambda e: self.keypress(self.a.zoomx,-1 ) )
# self.bind_all('<Shift-Right>',lambda e: self.keypress(self.a.zoomx,1) )
# self.bind_all('<Shift-Up>' ,lambda e: self.keypress(self.a.zoomy,1 ) )
# self.bind_all('<Shift-Down>' ,lambda e: self.keypress(self.a.zoomy,-1) )
# self.bind_all('<Next>' , lambda e : self.keypress(self.autoscale) )
# self.bind_all('<Prior>', lambda e : self.keypress(self.autoscaley, e ) )

def autoscaley(self,e):
print(dir(self.a.dataLim))
Expand Down Expand Up @@ -215,17 +215,17 @@ def replot(self):
self.a.set_title(item.d["title"])
try:
if "plottype" in item.d:
ret = self.a.hist(item.y,item.x)
self.a.hist(item.y,item.x)
elif item.x.shape[0]>self.maxpoints:
if self.quiet=="No":
if messagebox.askyesno("Slow plotting workaround","Shall I plot only the first %d points for increased speed?"%(self.maxpoints)):
ret = self.a.plot(item.x[:self.maxpoints],item.y[:self.maxpoints],**po)
self.a.plot(item.x[:self.maxpoints],item.y[:self.maxpoints],**po)
else:
ret = self.a.plot(item.x,item.y,**po)
self.a.plot(item.x,item.y,**po)
else:
ret = self.a.plot(item.x[:self.maxpoints],item.y[:self.maxpoints],**po)
self.a.plot(item.x[:self.maxpoints],item.y[:self.maxpoints],**po)
else:
ret = self.a.plot(item.x,item.y,**po)
self.a.plot(item.x,item.y,**po)
except:
print("plotting exception ignored")
raise
Expand Down
34 changes: 34 additions & 0 deletions find_all_files_interfacing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

import os

apui = []
syui = []
noui = []

root = "."
for dirName, subdirList, fileList in os.walk(root):
if True in [dirName.find(s)>=0 for s in ("__","build",".git",".vscode") ]:
continue
for f in fileList:
if f.endswith(".py"):
p = os.path.join(dirName, f)
s = open( p , "r" ).read()
if "optparse" in s or "add_option" in s:
apui.append( p )
elif "argv" in s:
syui.append( p )
else:
noui.append( p )

print("Neither:")
for f in noui:
print(f)


print("argv:")
for f in syui:
print(f)

print("optparse:")
for f in apui:
print(f)
1 change: 0 additions & 1 deletion lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ extraction:
python:
python_setup:
version: 3

2 changes: 1 addition & 1 deletion sandbox/CRL.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
# x^2 + y^2 = 2*Ry
# ... x>>y : x^2 = 2Ry
# so Y = x^2/(2R)
x = np.linspace( -.5e-3, .5e-3, 100)
#x = np.linspace( -.5e-3, .5e-3, 100)
x = np.linspace( -25e-6, 25e-6, 100)
#pl.plot( 1e6*x, 1e6*x*x/(2*R_SI), "-" )
E = 40
Expand Down
18 changes: 9 additions & 9 deletions sandbox/abonnin/make_point_sino.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def fit_sino( omega, obs, debug=False ):
print("# spot3d_id omega xpos intensity")
for i in range(len(usedpks)):
print("%-7d %8.1f %9.5f %15g"%(usedpks[i], omused[i], xposused[i], intens[i]))
if 0:
pl.clf()
pl.title("Grain number %d"%(ng))
pl.plot(om, xpos,"o")
pl.plot(omused, xposused,"o")
pl.plot(omused, calc,"+")
pl.ion()
pl.show()
pl.savefig("grainfit_%d.png"%(ng))
# if 0:
# pl.clf()
# pl.title("Grain number %d"%(ng))
# pl.plot(om, xpos,"o")
# pl.plot(omused, xposused,"o")
# pl.plot(omused, calc,"+")
# pl.ion()
# pl.show()
# pl.savefig("grainfit_%d.png"%(ng))
ng += 1
6 changes: 3 additions & 3 deletions sandbox/art.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from __future__ import print_function
from __future__ import print_function, division


"""
Expand Down Expand Up @@ -57,7 +57,7 @@ def update_wtd( recon, proj, angle, msk, dbg=True ):
cImageD11.put_incr( npcalc_proj, idx_hi, wt_hi )
cImageD11.put_incr( npcalc_proj, idx_lo, wt_lo )
npcalc_proj = np.where(npcalc_proj >0 ,npcalc_proj, 1)
update = np.zeros( r.shape, np.float32)
# update = np.zeros( r.shape, np.float32)
update = wt_hi*np.take( error/npcalc_proj, idx_hi )
update += wt_lo*np.take( error/npcalc_proj, idx_lo )

Expand All @@ -78,7 +78,7 @@ def update_wtd( recon, proj, angle, msk, dbg=True ):
#pl.colorbar()
#pl.show()

update = update
# update = update
update.shape = recon.shape
print(update.sum(),error.sum(), end=' ')
if dbg:
Expand Down
10 changes: 5 additions & 5 deletions sandbox/cleanbg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from __future__ import print_function
from __future__ import print_function, division
#!/usr/bin/python2.7

import numpy as np, fabio
Expand Down Expand Up @@ -43,7 +43,7 @@ def cleanbg( stem, nimages, newstem ):
print(i,name)
bg = np.clip( buffy.min( axis = 0 ), 90, 65535 ) - 90
# Deal with images up to bufsize/2
for i in range(bufsize/2):
for i in range(bufsize//2):
outname = newstem + "%04d.edf"%(i)
print("write",outname, buffo[i].name)
np.subtract( buffo[i].data , bg, buffo[i].data )
Expand All @@ -64,15 +64,15 @@ def cleanbg( stem, nimages, newstem ):
buffy[bp] = o.data.copy()
bg = np.clip( buffy.min( axis = 0 ), 90, 65535 ) - 90
# Out image is i - bufsize/2
op = (i-bufsize/2-1)%bufsize
op = (i-bufsize//2-1)%bufsize
np.subtract( buffo[op].data , bg, buffo[op].data )
outname = newstem + "%04d.edf"%(i-bufsize/2-1)
print(i,outname, buffo[op].name)
buffo[op].write( outname )
n=i
for i in range(bufsize/2):
for i in range(bufsize//2):
outname = newstem + "%04d.edf"%(n+i-bufsize/2)
bp = (n+i-bufsize/2)%bufsize
bp = (n+i-bufsize//2)%bufsize
print("write",outname, buffo[bp].name)
np.subtract( buffo[bp].data , bg, buffo[bp].data )
buffo[bp].write( outname )
Expand Down
2 changes: 1 addition & 1 deletion sandbox/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def updatecolfile(self):
elif "xc" in self.cf.titles:
pks = self.cf.xc, self.cf.yc
else:
raise "peaks file misses xc or sc"
raise Exception("peaks file misses xc or sc")
xl,yl,zl = transform.compute_xyz_lab( pks,
**self.transformpars.parameters)
self.cf.addcolumn(xl,"xl")
Expand Down
Loading

0 comments on commit 5a90a95

Please sign in to comment.