if verbosity>9: X,Y= np.meshgrid(ybins,qaxis); info = {'desc': 'DEBUG: input WQmap + bin borders (red lines)', 'xperchan':ybin, 'yperchan':dqx, 'ylabel':'q', 'yunits':'1/A', 'yoffset' :qaxis[0]}; WQB = WQBrowser(yqmap.T,info,aspect='auto'); WQB.axis.plot(X,Y,'r'); plt.show(); # 4. rebinning for each line y = np.arange(Ny)*ybin; EQmap =[]; for iq, q in enumerate(qaxis): # rebin spectrum at q line = yqmap[:,iq]; spectrum = rebin.rebin(y,line,ybins); EQmap.append(spectrum); EQmap=np.asarray(EQmap).T; # first index E, second q ehistory+="\nRebinning for Emin=%8.5f, Emax=%8.5f, dE=%8.5f"%(E.min(), E.max(),dE); # DEBUG: plot calibrated Eqmap if verbosity>9: info = {'desc': 'DEBUG: rebinned WQmap', 'xperchan':dE, 'ylabel':'E', 'yunits':'eV', 'yperchan':dqx,'ylabel':'q', 'yunits':'1/A', 'yoffset' :qaxis[0]}; WQB = WQBrowser(EQmap.T,info,aspect='auto'); plt.show(); # 5. save E-q map as readable tif outfile = '%s-calibrated.tif'%(filename.split('/')[-1].split('.pkl')[0]); print 'write to file %s'%outfile;
info = {'desc': 'DEBUG: input image', 'xperchan':xbin, 'yperchan':ybin}; WQB = WQBrowser(img,info,aspect='auto'); WQB.axis.plot(X,Y,'r'); WQB.axis.plot(X0,Y0,'g'); plt.show(); # 4. rebinning for each line ret = []; s2x = trafo.Seq(u2x,s2u); # combined trafo s->u->x for n,line in enumerate(img): y = ybin*n+ybin/2.; x = np.arange(Nx,dtype=float); # otherwise rounding errors for neg. x _,t = s2x.inverse(0,y); # linearized coord. of horizontal line xbins,_y= s2x.transform(sbins,[t]*len(sbins)); assert np.allclose(_y,y); ret.append(rebin.rebin(x*xbin,line,xbins)); ret=np.asarray(ret); if verbosity>9: info=[]; info.append({'desc': 'DEBUG: rebinned image', 'yperchan':ybin, 'xperchan': dq, 'xunits':'1/A', 'xlabel':'q', 'xoffset':q[0]}); info.append({'desc': 'DEBUG: rebinned image (reversed q-axis)', 'yperchan':ybin, 'xperchan': -dq, 'xunits':'1/A', 'xlabel':'-q', 'xoffset':q[-1]}); fig = WQStackBrowser([ret,ret],info,aspect='auto'); plt.show(); # 5. save undistorted w-q map # 5.1 save as TIFF (readable by DM3, ImageJ) tiffile = '%s-rebinned%dx%d.tif'%(filename.split('/')[-1].split('.tif')[0], ret.shape[0],ret.shape[1]);
'yperchan': dqx, 'ylabel': 'q', 'yunits': '1/A', 'yoffset': qaxis[0] } WQB = WQBrowser(yqmap.T, info, aspect='auto') WQB.axis.plot(X, Y, 'r') plt.show() # 4. rebinning for each line y = np.arange(Ny) * ybin EQmap = [] for iq, q in enumerate(qaxis): # rebin spectrum at q line = yqmap[:, iq] spectrum = rebin.rebin(y, line, ybins) EQmap.append(spectrum) EQmap = np.asarray(EQmap).T # first index E, second q history = "\nRebinning for Emin=%8.5f, Emax=%8.5f, dE=%8.5f" % (E.min(), E.max(), dE) # DEBUG: plot calibrated Eqmap if verbosity > 9: info = { 'desc': 'DEBUG: rebinned WQmap', 'xperchan': dE, 'xlabel': 'E', 'xunits': 'eV', 'yperchan': dqx, 'ylabel': 'q', 'yunits': '1/A',