Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

psana2 is also available in JupyterHub here in the kernel named "LCLS-II py3": https://pswww.slac.stanford.edu/jupyterhub/hub/home

NOTE: 

Environment

To obtain the environment to run psana2, execute the following:

...

It also works on one core with: python example.py (useful for debugging).  See MPI rank/task diagram here to understand what different mpi ranks are doing.

This mechanism by defaults produces "aligned" datasets where missing values are padded (with NaN's for floats, and -99999 for integers).  To create an unaligned dataset (without padding) prefix the name of the variable with "unaligned_".

...

NOTE: In python, if you want to exit early you often use a "break" statement.  When running psana-python with mpi parallelization, however, not all cores will see this statement, and the result will be that your job will hang at the end.  To avoid this use the "max_events" keyword argument to DataSource .  For example: "DataSource(exp='tmoc00118',run=123,max_events=10)"(see example below).

Code Block
languagepy
from psana import DataSource
import numpy as np
import os

#from OPTIONALmpi4py callback, usually used for realtime plots
# called back on each SRV node, for every smd.event() call below
def test_callback(data_dict):
    print(data_dict)

# this import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
 
# sets the number of h5 files to write. 1 is sufficient for 120Hz operation
# optional: only needed if you are saving h5.
os.environ['PS_SRV_NODES']='1'

ds = DataSource(exp='tmoc00118', run=123=222, dir='/cds/data/psdm/prj/public01/xtc', max_events=10010)
# batch_size hereis optional. specifies how often the dictionary of informationsmall
# isuser sentdata to the SRV nodesis gathered
smd = ds.smalldata(filename='mymysmallh5.h5', batch_size=5, callbacks=[test_callback])

for run =in next(ds.runs())

# necessary (instead of "None") since some ranks may not receive events
# and the smd.sum() below could fail
arrsum = np.zeros((2), dtype=np.int)
for evt in run.events():
    myones = np.ones_like(arrsum)
    :
    opal = run.Detector('tmo_opal1')
    ebeam = run.Detector('ebeam')
 
    runsum  = 0
    for evt in run.events():
        img = opal.raw.image(evt)
        photonEnergy = ebeam.raw.ebeamPhotonEnergy(evt)
        if img is None or photonEnergy is None: continue
        evtsum = np.sum(img)
        # pass either dictionary or kwargs
        smd.event(evt, myfloatevtsum=2.0evtsum, arrintphotonEnergy=myonesphotonEnergy)
    arrsum    runsum += myones

 evtsum # beware of datatypes when summing: can overflow
 
    # optional summary data for whole run
    if smd.summary:
        smd.sum(arrsum)runsum) # sum across all mpi cores
        # pass either dictionary or kwargs
        smd.save_summary({'summarysum_over_arrayrun' : arrsumrunsum}, summary_int=1)
    smd.done()

Running in Parallel

...