The model we believe to be way of the future for LCLS analysis (and FEL/lightsource analysis around the world) is that users be able to put together simple/short python "building blocks" to quickly express the complexity of their experiment. Many of these building blocks are publicly available on the web, and so can be reused around the world.
This section will show short/simple working example scripts that demonstrate the most common building blocks (at the time of this writing, the longest is 26 lines). Follow these building-block steps (in order) to learn how to access your data (you only need to know your experiment name (e.g. cxi86715) and a run number). These examples do not show all possible complex uses of the building blocks, but we include links to more detailed documentation where appropriate.
For clarity, examples are intentionally kept brief with minimal graphics, and some are inefficient from a programmatic point of view. Also, the examples use the new simpler DataSource "smd" mode which will only work for experiments after October 2015 (although the analysis group can generate the appropriate files for older experiments).
All scripts shown in this section can be copied from this directory:
/reg/g/psdm/tutorials/examplePython
They are maintained in the svn user repository named "examplePython".
For reference, here we include a 39-line example script that incorporates several of the building blocks (described with the comments after the "#" character). See the topics available by expanding the topics box on the left of this confluence page to learn how to modify this to match your application.
from psana import * ds = DataSource('exp=xpptut15:run=54:idx') # run online/offline det = Detector('cspad', ds.env()) # simple detector interface from mpi4py import MPI # large-scale parallelization rank = MPI.COMM_WORLD.Get_rank() size = MPI.COMM_WORLD.Get_size() img = None for run in ds.runs(): times = run.times() mylength = len(times)//size mytimes= times[rank*mylength:(rank+1)*mylength] for n,t in enumerate(mytimes): evt = run.event(t) # random access if img is None: img = det.image(evt) # many complex run-dependent calibrations else: img += det.image(evt) if n>5: break import numpy as np img_all = np.empty_like(img) MPI.COMM_WORLD.Reduce(img,img_all) if rank==0: from pypsalg.AngularIntegrationM import * # algorithms ai = AngularIntegratorM() ai.setParameters(img_all.shape[0],img_all.shape[1], mask=np.ones_like(img_all)) bins,intensity = ai.getRadialHistogramArrays(img_all) from psmon import publish # real time plotting from psmon.plots import Image publish.local = True img = Image(0,"CsPad",img_all) publish.send('image',img) MPI.Finalize()