Page History
Include Page | ||||
---|---|---|---|---|
|
Table of Contents |
---|
Include Page | ||||
---|---|---|---|---|
|
1. About this Tutorial
The main objective of this session is to introduce and to explain the new Python interface for accessing LCLS data. This software framework is known as the "Interactive psana". The first idea of implementing such tool was suggested around 1.5 years ago at the joint PCDS/SRD meeting (look for Interactive Psana). Though its underlying machinery is largely based on the batch version of psana the interface to the data is simpler, more intuitive, and it requires less code to be written by a user in order to get to that CSPad image or that EPICS PV. The new framework won't work for everyone, specifically for those users who have either heavily invested into the modular code of the batch framework, or who need the performance of modules written in C++. Still our intent is to demonstrate the power of the new approach and to encourage using the tool where appropriate.
...
All examples can be found under the following directory:
Code Block |
---|
/reg/g/psdm/tutorials
|
Data Files
...
Each experiment's directory has the standard structure:
Code Block |
---|
ls -al ls -al /reg/d/psdm/XPP/xpptut13/
drwxr-sr-x 8 psdatmgr ps-data 4096 Jun 4 12:02 .
drwxrwsr-x 30 psdatmgr ps-data 4096 Jun 4 12:02 ..
drwxrwsr-x+ 3 psdatmgr ps-data 4096 Jun 5 10:53 calib
drwxrwsr-x+ 2 psdatmgr ps-data 4096 Jun 4 12:02 ftc
drwxr-sr-x 2 psdatmgr ps-data 4096 Jun 6 16:41 hdf5
drwxrwsr-x+ 2 psdatmgr ps-data 4096 Jun 4 12:02 res
drwxrwsr-x+ 2 psdatmgr ps-data 4096 Jun 4 12:03 scratch
drwxr-sr-x 2 psdatmgr ps-data 4096 Jun 6 16:33 xtc
ls -al /reg/d/psdm/XPP/xpptut13/hdf5/
drwxr-sr-x 2 psdatmgr ps-data 4096 Jun 6 16:41 .
drwxr-sr-x 8 psdatmgr ps-data 4096 Jun 4 12:02 ..
-r--r--r-- 1 psdatmgr ps-data 1765036151 Jun 6 16:39 xpptut13-r0178.h5
-r--r--r-- 1 psdatmgr ps-data 394528165 Jun 6 16:39 xpptut13-r0179.h5
-r--r--r-- 1 psdatmgr ps-data 128185688 Jun 6 16:39 xpptut13-r0180.h5
-r--r--r-- 1 psdatmgr ps-data 912811050 Jun 6 16:39 xpptut13-r0181.h5
|
...
Setting up the Environment
Make sure you can run X11 applications. Most examples of this tutorial will do a simple visualization. You can pass the -X or -Y argument to ssh to make sure you can forward the screens to your local machine, eg:
Code Block ssh -Y psexport
Log onto any machine of the interactive pools psananeh or psanafeh, eg:
Code Block ssh psananeh
Make sure you source (just once) one of the following scripts. When using the bash shell:
Code Block . /reg/g/psdm/etc/sit_env.sh
Or, when using the csh shell family:
Code Block source /reg/g/psdm/etc/sit_env.csh
Note that the default shell for most LCLS users is bash.
Run (just once) the following command which will set up a proper analysis environment for the latest analysis release:
Code Block sit_setup ana-current
At this point you are ready to go. To test that the your environment is set up correctly try running psana without any parameters. If your environment is properly set you should see something like this:
Code Block |
---|
psana
[error:2013-06-06 20:54:44.131:PSAnaApp.cpp:218] no analysis modules specified
|
...
This section presents a few simple scripts which have been developed to underline the main ideas behind the framework's API. The code of the examples along with a simple HOWTO file can be found at:
Code Block |
---|
/reg/g/psdm/tutorials/common/data_access_methods/
|
...
First try this:
Code Block |
---|
./print_event_id.py
|
Then look at the code. It will do three things:
Import the psanamodule:
Code Block import psana
Open the data set. Note the syntax for the data set specification string:
Code Block dsname = "exp=sxrtut13:run=366" ds = psana.DataSource(dsname)
Note that by default the framework will look for XTC files at the standard location where all experimental data are supposed to be. If you want to play with HDF5 (in case there is an HDF5 version of the run) you can change that string by appending h5in the end:
Code Block dsname = "exp=sxrtut13:run=366:h5"
The next thing which this code will do will be to iterate over all events. At each step you will get a reference to an event object evtand it will extract and print an identifier of the event:
Code Block for evtnum, evt in enumerate(ds.events()): id = evt.get(psana.EventId) print "%6d:" % evtnum, id
In the end you're supposed to see something like this:
Code Block |
---|
./print_event_id.py
0: XtcEventId(run=366, time=2013-04-21 04:37:39.343773772-07, fiducials=38877, ticks=329342, vector=19553)
1: XtcEventId(run=366, time=2013-04-21 04:37:39.360457259-07, fiducials=38883, ticks=331442, vector=19554)
2: XtcEventId(run=366, time=2013-04-21 04:37:39.377123777-07, fiducials=38889, ticks=330560, vector=19555)
3: XtcEventId(run=366, time=2013-04-21 04:37:39.393797466-07, fiducials=38895, ticks=329762, vector=19556)
4: XtcEventId(run=366, time=2013-04-21 04:37:39.410477971-07, fiducials=38901, ticks=331204, vector=19557)
5: XtcEventId(run=366, time=2013-04-21 04:37:39.427145705-07, fiducials=38907, ticks=331036, vector=19558)
6: XtcEventId(run=366, time=2013-04-21 04:37:39.443816588-07, fiducials=38913, ticks=329370, vector=19559)
7: XtcEventId(run=366, time=2013-04-21 04:37:39.460499778-07, fiducials=38919, ticks=331414, vector=19560)
8: XtcEventId(run=366, time=2013-04-21 04:37:39.477167658-07, fiducials=38925, ticks=330616, vector=19561)
9: XtcEventId(run=366, time=2013-04-21 04:37:39.493840079-07, fiducials=38931, ticks=329720, vector=19562)
10: XtcEventId(run=366, time=2013-04-21 04:37:39.510520348-07, fiducials=38937, ticks=331218, vector=19563)
|
...
The example can be run like this:
Code Block |
---|
./print_event_keys.py
Components of the first event found in the dataset:
EventKey(type=psana.EvrData.DataV3, src='DetInfo(NoDetector.0:Evr.0)')
EventKey(type=psana.Acqiris.DataDescV1, src='DetInfo(SxrEndstation.0:Acqiris.0)')
EventKey(type=psana.Acqiris.DataDescV1, src='DetInfo(SxrEndstation.0:Acqiris.1)')
EventKey(type=psana.Bld.BldDataEBeamV3, src='BldInfo(EBeam)')
EventKey(type=psana.Bld.BldDataPhaseCavity, src='BldInfo(PhaseCavity)')
EventKey(type=psana.Bld.BldDataFEEGasDetEnergy, src='BldInfo(FEEGasDetEnergy)')
EventKey(type=psana.Bld.BldDataGMDV1, src='BldInfo(GMD)')
EventKey(type=psana.EventId)
EventKey(type=None)
|
...
The type and the source of the output shown above will allow you to access the data you need by using the following get functions:
Code Block |
---|
obj = evt.get( psana.EvrData.DataV3, psana.Source('DetInfo(NoDetector.0:Evr.0)'))
obj = evt.get( psana.Acqiris.DataDescV1, psana.Source('DetInfo(SxrEndstation.0:Acqiris.0)'))
obj = evt.get( psana.Acqiris.DataDescV1, psana.Source('DetInfo(SxrEndstation.0:Acqiris.1)'))
obj = evt.get( psana.Bld.BldDataEBeamV3, psana.Source('BldInfo(EBeam)'))
obj = evt.get( psana.Bld.BldDataPhaseCavity, psana.Source('BldInfo(PhaseCavity)'))
obj = evt.get( psana.Bld.BldDataFEEGasDetEnergy, psana.Source('BldInfo(FEEGasDetEnergy)'))
obj = evt.get( psana.Bld.BldDataGMDV1, psana.Source('BldInfo(GMD)'))
obj = evt.get( psana.EventId)
|
...
This simple application knows about step boundaries. More over, this example illustrates how to open a data set composed of many runs (processing a series of runs at once). There are two examples in this set:
Code Block |
---|
./steps_in_runs_xtc.py
./steps_in_runs_hdf5.py
|
...
In this example we will demonstrate how to access a value of an EPICS variable. The application will monitor changes in the value and report event numbers at which changes happen:
Code Block |
---|
./scan_epics.py
|
Here are the relevant lines of code:
Code Block |
---|
epics = ds.env().epicsStore()
pv = epics.getPV('VGCP:FEE1:311:P').data()[0]
|
4. Instrument Specific Examples
For many pv's, there is only one element in the data() array. To access the first element, one can also do:
Code Block | ||
---|---|---|
| ||
pv = epics.value('VGP:FEE1:311:P')
pv = epics.value('VGP:FEE1:311:P',0)
pv = epics.getPV('VGP:FEE1:311:P').value(0) |
4. Instrument Specific Examples
This section includes a number of This section includes a number of examples which are relevant to different instruments. Their primary goal is to illustrate how to access data objects specific to each instrument.
...
The code for these examples is found at:
Code Block |
---|
/reg/g/psdm/tutorials/xcs/princeton_movie/
|
...
The code for these examples is found at:
Code Block |
---|
/reg/g/psdm/tutorials/sxr/gmd_vs_diode/
|
...
The code for these examples is found at:
Code Block |
---|
/reg/g/psdm/tutorials/cxi/cspad_imaging/
|
...
Please, run these test in the order described above:
Code Block |
---|
./dump_2x1_elements.py
./frame_reco.py
./frame_reco_calib.py
|
...
- DOXYGEN documentation for psana
- Batch version of psana
- Psana psana - Module Catalog - comprehensive catalog of psana modules in the latest Analysis Release
- Psana psana - Module Examples