Skip to content

Commit

Permalink
2to3
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwright committed Sep 29, 2017
1 parent c43916b commit 0c3db48
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ __pycache__/

# 2to3 remains

*.bak
*.bak*

# C extensions
*.so
Expand Down
38 changes: 19 additions & 19 deletions sandbox/diffracCl/diffracCl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
if "win" in sys.platform:
timer = time.clock
dll = ctypes.CDLL("diffracCl.dll")
print "# time.clock", sys.platform, sys.version
print("# time.clock", sys.platform, sys.version)
else:
timer = time.time
dll = ctypes.CDLL("./diffracCl.so")
print "# time.time", sys.platform, sys.version
print("# time.time", sys.platform, sys.version)

import pyopencl.version
print "# pyopencl:",pyopencl.version.VERSION
print("# pyopencl:",pyopencl.version.VERSION)

class myCL:
def __init__(self, npx):
self.ctx = cl.create_some_context()
for d in self.ctx.devices:
print "#",d.platform.name
print "#",d.vendor
print "#",d.name
print("#",d.platform.name)
print("#",d.vendor)
print("#",d.name)
self.npx = npx
self.queue = cl.CommandQueue(self.ctx)
self.pars = numpy.zeros(14, dtype=numpy.float32)
Expand Down Expand Up @@ -155,7 +155,7 @@ def make_pars( parfile ):
example.popCorn()
pars = make_pars(sys.argv[1])
example.setpars( pars )
print "# Init", timer()-start
print("# Init", timer()-start)
times = []
# Warmup
tth, eta = example.execute()
Expand All @@ -164,31 +164,31 @@ def make_pars( parfile ):
tth, eta = example.execute()
times.append(timer()-start)
times = numpy.array(times)
print "# mean min max std"
print "%.4f %.4f %.4f %.4f"%( times.mean(), times.min(),
times.max(), times.std())
print("# mean min max std")
print("%.4f %.4f %.4f %.4f"%( times.mean(), times.min(),
times.max(), times.std()))
t = numpy.median(times)
print "%.1f ms, %.1f fps,"%(1e3*t,1.0/t),
print tth.max(),tth.min()
print("%.1f ms, %.1f fps,"%(1e3*t,1.0/t), end=' ')
print(tth.max(),tth.min())
eta_cl = eta.copy()
eta_ct = eta.copy()
tth_cl = tth.copy()
tth_ct = tth.copy()
o = ctp( npx )
times = numpy.array( o.compute( tth_ct, eta_ct, pars ) )

print "# ctypes module, hopefully with openmp"
print "# mean min max std"
print "%.4f %.4f %.4f %.4f"%( times.mean(), times.min(),
times.max(), times.std())
print("# ctypes module, hopefully with openmp")
print("# mean min max std")
print("%.4f %.4f %.4f %.4f"%( times.mean(), times.min(),
times.max(), times.std()))
t = numpy.median(times)
print "%.1f ms, %.1f fps,"%(1e3*t,1.0/t),
print tth.max(),tth.min()
print("%.1f ms, %.1f fps,"%(1e3*t,1.0/t), end=' ')
print(tth.max(),tth.min())

# Check same ness
eta_err = (abs(eta_cl - eta_ct)).mean()
tth_err = (abs(tth_cl - tth_ct)).mean()
print "Mean diff tth,eta",tth_err,eta_err
print("Mean diff tth,eta",tth_err,eta_err)
if len(sys.argv)>2:
from matplotlib.pylab import imshow, figure, show, colorbar, title
figure(1)
Expand Down
56 changes: 28 additions & 28 deletions sandbox/ev78/integrate_them.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os, time, fabio, numpy
import pyFAI
print pyFAI.__file__
print(pyFAI.__file__)
SOLID_ANGLE = True
#print "PATH:", sys.path

Expand All @@ -19,12 +19,12 @@ class darkflood(object):
"""
def __init__(self, darkfile=None, floodfile=None):
if darkfile is None:
print "Warning: no dark supplied"
print("Warning: no dark supplied")
self.darkobj = None
else:
self.darkobj = fabio.open(darkfile)
if floodfile is None:
print "Warning: no flood supplied"
print("Warning: no flood supplied")
self.floodmult = None
else:
self.floodobj = fabio.open(floodfile)
Expand Down Expand Up @@ -57,7 +57,7 @@ def edffilenameseries(stem, first=None, last=None, glob=False, extn=".edf"):
yield fname
num += 1
if first is not None and last is None:
print "Starting with image",first,"then incrementing"
print("Starting with image",first,"then incrementing")
num = first
while 1:
fname = "%s%04d%s"%( stem, num, extn )
Expand All @@ -73,9 +73,9 @@ def calcfrom1d( integrator, tth, I, shape):
Computes a 2D image from a 1D integrated profile
"""
ttha = integrator.twoThetaArray(shape)
print ttha.ravel().shape
print tth.shape
print I.shape
print(ttha.ravel().shape)
print(tth.shape)
print(I.shape)
calcimage = numpy.interp( ttha.ravel(),
tth*numpy.pi/180,
I )
Expand All @@ -97,7 +97,7 @@ def determineparfile( fname ):
return "pyfai"
if bytes.find("X-BEAM CENTRE") != -1:
return "fit2d"
print bytes
print(bytes)
raise Exception("Parameters not recognised in file: %s"%(fname))

class fit2dcakepars:
Expand Down Expand Up @@ -153,7 +153,7 @@ def __init__(self, fname ):
key, value = line.split(" = ")
value = value.rstrip() # get rid of trailing \n
except:
print "$$$%s$$$"% (line)
print("$$$%s$$$"% (line))
raise
if value == "None":
value = None
Expand All @@ -163,7 +163,7 @@ def setparameter( self, key, value ):
if key in self.option_names:
self.options[key] = value
else:
print "Failure to set {%s}=%s"%( key, value)
print("Failure to set {%s}=%s"%( key, value))
def __getitem__(self, key):
return self.options[key]
def __setitem__(self, key, value):
Expand All @@ -179,7 +179,7 @@ def display(tth, I, img):
imshow(img,vmin=-.21,vmax=.21)
colorbar()
show()
raw_input("continue?")
input("continue?")

def integrate_them( o ):
"""
Expand All @@ -200,9 +200,9 @@ def integrate_them( o ):
if ptype == "pyfai":
integrator.load( o.parfile )
if o.dark is not None:
print "Using dark from command line",o.dark
print("Using dark from command line",o.dark)
if o.flood is not None:
print "Using dark from command line",o.flood
print("Using dark from command line",o.flood)
elif ptype == "fit2d":
f2d = fit2dcakepars( o.parfile )
if f2d["SPATIAL DIS."][0] not in ["Y","y"]:
Expand All @@ -220,20 +220,20 @@ def integrate_them( o ):
)
integrator.rot3=0
integrator.reset()
print integrator.param, integrator.detector.pixel1
print(integrator.param, integrator.detector.pixel1)
# First choice is command line. Then from pars if supplied
if o.dark is None:
if f2d["DARK CURRENT"][0] in ["Y","y"]:
o.dark = f2d["DC FILE"]
print "Using dark from fit2d parameter file",o.dark
print("Using dark from fit2d parameter file",o.dark)
else:
print "Using dark from command line",o.dark
print("Using dark from command line",o.dark)
if o.flood is None:
if f2d["FLAT-FIELD"][0] in ["Y","y"]:
o.flood = f2d["FF FILE"]
print "Using flood from fit2d parameter file",o.flood
print("Using flood from fit2d parameter file",o.flood)
else:
print "Using flood from command line",o.flood
print("Using flood from command line",o.flood)
# Should be in fabio utilities
df = darkflood( o.dark, o.flood )
# Should be in fabio
Expand All @@ -242,19 +242,19 @@ def integrate_them( o ):
# Command line is first priority for make
if o.mask is not None:
mask = fabio.open( o.mask ).data
print "Using mask", o.mask
print("Using mask", o.mask)
# assume poni file deals with this independently?
elif ptype == "fit2d": # try in fit2d parfile
if f2d["USE MASK"][0] in ['y','Y']:
mask = fabio.open( f2d["MASK FILE"] ).data
print "Using mask",f2d["MASK FILE"]
print("Using mask",f2d["MASK FILE"])
else:
mask = None
if mask is not None:
print "mask mean:",mask.mean()
print("mask mean:",mask.mean())
integrator.write(os.path.splitext(o.parfile)[0]+".poni")
for f in fs:
print "Processing",f,
print("Processing",f, end=' ')
try:
fo = df.correct( fabio.open(f) )
except:
Expand Down Expand Up @@ -288,7 +288,7 @@ def integrate_them( o ):
#delta_dummy=delta_dummy # precision of dummy
)

print "wrote",outFile
print("wrote",outFile)
if o.backcalc:
calcimage = calcfrom1d( integrator, tth, I, fo.data.shape ) * integrator._polarization
err = (calcimage - fo.data) * (1-mask)/(calcimage+mask)
Expand Down Expand Up @@ -325,10 +325,10 @@ def fitcen( data, cim , mask=None ):
try:
imat = numpy.linalg.inv( [ [ mxx, mxy], [mxy, myy] ] )
shft = numpy.dot( imat, [rx, ry] )
print "Image offset estimate (pixels)", shft
print "Intensity mean, min, max errors", (diff*diff).mean(), diff.min(), diff.max()
print("Image offset estimate (pixels)", shft)
print("Intensity mean, min, max errors", (diff*diff).mean(), diff.min(), diff.max())
except:
print "Cannot estimate beam centre error"
print("Cannot estimate beam centre error")


def get_options(parser):
Expand Down Expand Up @@ -402,13 +402,13 @@ def polstuff():
except:
if o is not None:
o.print_help()
print "\nHere is the problem:\n"
print("\nHere is the problem:\n")
raise
integrate_them( options )

# calcimage = calcfrom1d( integrator, tth, I, data.shape, mask)

print pyFAI.__file__
print(pyFAI.__file__)



Expand Down
10 changes: 5 additions & 5 deletions sandbox/ev78/makevols.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def readtxt(fname):
ctrs = "diffty pico3 notsrcu".split()
h["pico3"]=1
h["notsrcu"]=1
for line in open(fname).xreadlines():
for line in open(fname):
if line[0] == "#":
if cnext is not None:
h[cnext] = float(line.split()[cindex])
Expand Down Expand Up @@ -45,8 +45,8 @@ def decidegrid(vals):
if y!=y0: break
blocksize = i
if len(vals) % blocksize != 0:
print "Blocksize seems to be",blocksize,
print "you have",len(vals),"images. Problem."
print("Blocksize seems to be",blocksize, end=' ')
print("you have",len(vals),"images. Problem.")
vals.shape = vals.shape[0]/blocksize,blocksize,vals.shape[1]
# Find the best angular grid mapping onto this
a0=vals[0,:,1]
Expand Down Expand Up @@ -103,13 +103,13 @@ def writehdf(fname, blob, tth, vp):
HOME = "/data/visitor/ev78/id11"
os.chdir(HOME)
stem = sys.argv[1]
print stem
print(stem)
txtfile = "%s/%s.txt"%(stem,stem)
# file with motor positions and image filenames
vals = readtxt(txtfile)
# figure array dimensions
vals, offset = decidegrid(vals)
print vals.shape
print(vals.shape)
# Read 1D integrated data (pyFAI was already run on it)
xaxis, blob = readdat( "%s/%s"%(stem,stem), vals)

Expand Down
8 changes: 4 additions & 4 deletions sandbox/ev78/rad.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def make_indices(self):
arshape = self.dims[0]/2+1, self.dims[1]
nv = (arshape[0]-1)*2
nh = arshape[0]
print "NV,NH",nv,nh
print("NV,NH",nv,nh)
self.ftimshape = (nv, nh)
self.ftimlen = nv*nh
n1 = (self.dims[0]/2+1)*self.dims[1]
Expand Down Expand Up @@ -110,7 +110,7 @@ def find_offset(a1, a2):
pylab.plot(a1)
pylab.plot(a2[::-1])
pylab.show()
print numpy.argmax(c)/2.0
print(numpy.argmax(c)/2.0)
1/0
return numpy.argmax(c)/2.0

Expand All @@ -136,7 +136,7 @@ def difftomo(N=256):
ipk = s[s.shape[0]/2,s.shape[1]/2].argmax()
offset = find_offset( s[:,0,ipk], s[:,-1,ipk] )
ioff = int(numpy.round(offset))
print "Offset (centre pixel) seems to be",offset,ioff
print("Offset (centre pixel) seems to be",offset,ioff)
recon = numpy.zeros((N,N,s.shape[2]),numpy.float32)
i0 = numpy.zeros(s.shape[2],numpy.float32)
for i in range(s.shape[2]):
Expand All @@ -157,7 +157,7 @@ def difftomo(N=256):
pylab.subplot(122)
pylab.imshow(s[:,:,i] - i0[i])
pylab.colorbar()
raw_input("next?")
input("next?")
grp = h["DiffTomo/NXdata"]
savearray( i0, "recon_bg", grp )
savearray( recon, "recon", grp)
Expand Down
14 changes: 7 additions & 7 deletions sandbox/ev78/watch_direcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@


def process(stem):
print "Checking",stem,
print("Checking",stem, end=' ')
sys.stdout.flush()
os.chdir(os.path.join(HOME, stem))
fl = glob.glob("*")
edfs = filter(lambda s:s.endswith("edf"), fl)
dats = filter(lambda s:s.endswith("dat"), fl)
print len(edfs)
edfs = [s for s in fl if s.endswith("edf")]
dats = [s for s in fl if s.endswith("dat")]
print(len(edfs))
if len(edfs)!=len(dats):
os.system("../process2x2.sh %s"%(stem))

Expand All @@ -40,12 +40,12 @@ def process(stem):
try:
num = int(num)
except:
print "dirname does not start with a number",dirname
print("dirname does not start with a number",dirname)
continue
stem = dirname.replace("_edna","")
process(stem)
lastone = checked.keys()
lastone = list(checked.keys())
lastone.sort()
print "sleeping"
print("sleeping")
time.sleep(10)

Loading

0 comments on commit 0c3db48

Please sign in to comment.