You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Simple 9-line script

import psana
ds = psana.DataSource('exp=xpptut15:run=54:smd')
det = psana.Detector('cspad',ds.env())
for nevent,evt in enumerate(ds.events()):
    # includes pedestal subtraction, common-mode correction
    # bad-pixel suppression, and geometry
    img = det.image(evt)
    break
import matplotlib.pyplot as plt
plt.imshow(img,vmin=-2,vmax=2)
plt.show()

 

Script with advanced graphics

Similar script with elaborated matplotlib graphics working in style of event browser

  • makes large image figure
  • add color bar
  • draw events in the event loop
  • hold control on image for the last event (10)
import psana
ds = psana.DataSource('exp=xpptut15:run=54:smd')
det = psana.Detector('cspad',ds.env())

##-----------------------------
# graphics initialization
import matplotlib.pyplot as plt
fig  = plt.figure(figsize=(13,12), dpi=80, facecolor='w', edgecolor='w', frameon=True)
axim = fig.add_axes((0.05,  0.03, 0.87, 0.93))
axcb = fig.add_axes((0.923, 0.03, 0.02, 0.93))
plt.ion() # do not hold control on show() in the event loop
##-----------------------------

for nevent,evt in enumerate(ds.events()):
    if nevent>10 : break

    img = det.image(evt)

    ##-----------------------------
    # graphics
    axim.cla()                                         # clear image axes if necessary...
    ave, rms = img.mean(), img.std()                   # evaluate average intensity and rms over image pixels
    imsh = axim.imshow(img, interpolation='nearest', aspect='auto', origin='upper',\
                       vmin=ave-1*rms, vmax=ave+2*rms) # make object which produces image in axes
    colb = fig.colorbar(imsh, cax=axcb)                # make colorbar object associated with figure
    fig.canvas.set_window_title('Event %d' % nevent)   # set window title
    fig.canvas.draw()                                  # redraw canvas
    plt.show()                                         # show plot (need it for the 1st plot only)

plt.ioff() # hold control on show() at the end
plt.show()
##-----------------------------
  • No labels