Infrastructure
Problems accessing data, or data seems to have disappeared
Two things to check:
- Have you been given access to view the data?
- Has the data been removed due to the data retention policy?
For the first, new users to an experiment need to ask the experiment POC to add them to the experiment. After this is done, you must log out and log back in for the change to take affect.
For the second, when analysis code that used to work stops working, check to see if the xtc is visible. For example, if you are analyzing run 68 of xpptut13, take a look in the xtc directory for that experiment, i.e:
ls /reg/d/psdm/xpp/xpptut13/xtc
If the directory is visible but run 68 is not there, it maybe that the data was removed due to the Data Retention Policy. The data is still available on disk and can be restored using the Web Portal of Experiments.
If the xtc directory is not visible, make sure you are running on a node that can see the data (i.e, you are on a psana node, rather than a psdev or pslogin node). If it is still not visible, email pcds-help@slac.stanford.edu.
How do I use the LCLS batch farm?
Follow the instructions here: Submitting Batch Jobs
How do I keep programs running if a ssh connection fails
See if you can use the LSF batch nodes for your work. If not, three unix programs to help with this are tmux, nohup and screen. None of these programs will preserve a graphical program, or a X11 connection, so run your programs in terminal mode.
tmux
For example, with tmux, if one does
ssh psexport
ssh psana
# suppose we have landed on psanacs040 and that there is a matlab license here
tmux
matlab --nosplash --nodesktop
If you lose the connection to psanacs040, you can go back to that node and reattach:
ssh psexport
ssh psanacs040
tmux attach
You need to remember the node you ran tmux on. If you are running matlab, you can run the matlab license script with the --show-users parameter to see where you are running it:
/reg/common/package/scripts/matlic --show-users
nohup
You could run a batch process with nohup (no hangup) as follows
nohup myprogram
For example, suppose we want to run a Python script that prints to the screen and save its output (the below syntax is for the bash shell):
nohup python myscript.py > myoutput 2>&1 &
Here we are capturing the output of the program in myoutput, along with anything it writes to stderr (the 2>&1), then putting it in the background. The job will persist after you logout. You can take a look at the output in the file myoutput the next day. As with tmux you will need to remember the node you launched nohup on.
Why did my batch job failed? I'm getting 'command not found'
Before running your script, make sure you can run something, for instance do
bsub -q psnehq pwd
(substitute the appropriate queue for psnehq). If you created a script and are running
bsub -q psnehq myscript
Then it maybe that the current directory is not in your path, run
bsub -q psnehq ./myscript
Check that myscript is executable by yourself, check that you have the correct #! line to start the script.
sit_setup fails in script using ssh
Users have run into issues in the following scenario
- writing a script that uses ssh to get to another node
- uses sit_setup to set up the environment for that node (in the script)
The issue is that sit_setup is an alias (defined by /reg/g/psdm/etc/ana_env.sh). In bash aliases are not expanded by default in non-interactive shells so you have two options:
- '. /reg/g/psdm/bin/sit_setup.sh' instead of sit_setup
- change the shell behavior by saying 'shopt expand_aliases'
Typically option 1) works best.
Psana
Topics specific to Psana
Where is my epics variable?
Make sure it is a epics variable - it may be a control monitor variable. An easy way to see what is in the file is to use psana modules that dump data. For instance:
psana -m psana_examples.DumpEpics exp=cxitut13:run=0022
will show what epics variables are defined. Likewise
psana -m psana_examples.DumpControl exp=xpptut13:run=0179
will almost always show what control variables are defined. It defaults to use the standard Source "ProcInfo()" for control data. It is possible (though very unlikely) for control data to come from a different source. One can use the EventKeys module to see all Source's present, and then specify the source for DumpControl through a config file.
How do I access data inside a Psana class?
Look for an example in the psana_examples package that dumps this class. There should be both a C++ and Python module that dumps data for the class.
How do I find out the experiment number (expNum) or experiment?
Psana stores both the experiment and expNum in the environment object - Env that Modules are passed, or that one obtains from the DataSource in interactive Psana. See Interactive Analysis document and the C++ reference for Psana::Env
Why isn't there anything in the Psana Event?
This may be due to a problem in the DAQ software that was used during the experiment. The DAQ software may have incorrectly been setting the L3 trim flag. This flag is supposed to be set for events that should not processed (perhaps they did not meet a scientific criteria involving beam energy). When the flag is set, there should be very little in the xtc datagram - save perhaps epics updates. Psana (as of release ana-0.10.2 from October 2013) will by default not deliver these events to the user. The bug is that the flag was set when there was valid data. To force psana to look inside datagram's where L3T was set, use the option l3t-accept-only. To use this option from the command line do:
psana -o psana.l3t-accept-only=0 ...
Or you can add the option to your psana configuration file (if you are using one):
[psana]
l3t-accept-only=0
It seems that for as much as 5% of the time, CsPad DataV2 is not in the Event
The only distinction between CsPad DataV1 and DataV2 is the sparsification of particular sections as given in the configuration object. That is DataV2 may be sparser. The actual hardware is kicking out DataV1 but the DAQ event builder is making a DataV2 when it can. Sometimes the DAQ sends the original DataV1 instead of the DataV2. This can be due to limited resources, in particular competition with resources required for compressing cspad in the xtc files. If you do not find a DataV2 in the Event, look for a DataV2
How do I set psana verbosity from the config file?
Most all psana options can be set from both the config file as well as the command line. Unfortunately verbosity cannot be set from a config file. That is
psana -v -v ...
has no config file equivalent. This is because verbosity is a function of the Message service that psana is a client of, rather than server for. Unfortunately this makes it difficult to turn on debugging messages from within a python script that is run as
python myscript.py
However one can configure the message logging service through the MSGLOGCONFIG environment variable. In particular
MSGLOGCONFIG=trace python myscript.py
or
MSGLOGCONFIG=debug python myscript.py
turns on trace or debug level MsgLog messages. The above examples were tested with the bash shell. For full details on configuring the MsgLogger through the MSGLOGCONFIG environment variables, see https://pswww.slac.stanford.edu/swdoc/releases/ana-current/doxy-all/html/group__MsgLogger.html
Strange Results after doing Math with data in Python
One thing to bear in mind with the data in the Python interface, the detector data is almost always returns as a numpy array of an integral type. For example, after getting a waveform of Acqiris data, if you were to print it out during an interactive Python session, you might see
waveform
array([234,53,5,...,324], dtype=np.int16)
Note the dtype, this data is two byte signed integers. In particular if a value of the waveform is over 32000 and you add 10000 to it, those values will wrap around and become negative. It may be a good idea, before doing any math with the data, to convert it to floats:
waveform = waveform.astype(np.float)
Hdf5
Topics specific to hdf5
Why is there both CsPad DataV2 and CsPad DataV1 in the translation?
The only distinction between CsPad DataV1 and DataV2 is the sparsification of particular sections as given in the configuration object. That is DataV2 may be sparser. The actual hardware is kicking out DataV1 but the DAQ event builder is making a DataV2 when it can. Sometimes the DAQ sends the original DataV1 instead of the DataV2. This can be due to limited resources, in particular competition with resources required for compressing cspad in the xtc files.
How do I write hdf5 files from C++ or Python
Python:
From Python we recommend h5py. For interactive Python, an example is found at Using h5py to Save Data.
For Python you can also use pytables. This is installed in the analysis release. Do
import tables
In your Python code.
C++
If developing a Psana module to process xtc, consider splitting your module into a C++ module which puts ndarrays in the event store, and a Python module which retrieves them and writes the hdf5 file using h5py.
You can also work with the C interface to hdf5. hdf5 is installed as a package in the analysis release. From your C++ code, do
#include "hdf5/hdf5.h"
A tip for learning hdf5 is to run example programs from an 'app' subdirectory of your package. For example, if you create an analysis release and a package for yourself, create an app subdirectory to that package and put an example file there:
~/myrelease/mypackage/app/hdf5_example.c
Now run 'scons' from the ~/myrelease directory, and then run hdf5_example.
Psana Modules - Using the Translator:
The Psana ddl based Translator can be used to write ndarrays, strings and a few simple types that C++ modules register. These will be organized in the same groups that we use to translate xtc to hdf5. Datasets with event times will be written as well. To use this, create a psana config file that turns off the translation of all xtc types but allows translation of ndarrays and strings. An example cfg file is here: psana_translate_noxtc.cfg You would just change the modules and files parameters for psana and the output_file parameter to Translator.H5Output. Load modules before the translator that put ndarrays into the event store. The Translator will pick them up and write them to the hdf5 file
TimeTool
Here we cover topics specific to the offline TimeTool module. The TimeTool results can be obtained in one of two ways depending on the experimental setup. The first is directly during data acquisition. For data recorded prior to Oct 13, 2014, the timetool results were always recorded as EPICS PV's. After Oct 13, 2014, they are still recorded as EPICS PV's, but also recorded in their own data type: TimeTool::DataV1. The latter is the preferred way to access the data, EPICS PV's are provided for backward compatibility. The second is during offline analysis using the psana module TimeTool.Analyze. Similarly, this module puts a TimeTool::DataV1 object in the event store. Previously, it put a collection of floats, or ndarrays in the event store (for backward compatibility, it still puts the floats in the event store). Documentation on the psana TimeTool modules can be found in the psana - Module Catalog.
The case studies below reference code in the TimeToolExamples package from the svn users repository at SLAC. The simplest way to work through these case studies is to add this package to a test release and build/run the code - potentially modifiying it to run on the experimental data that you are have access to. If you are not at SLAC, downloads of the code are provides below.
Assuming you are at SLAC, start by making a test release:
newrel ana-current myrel
cd myrel
addpkg -u TimeToolExamples V00-00-05
scons
If you have any trouble with the addpkg -u command, you may need to do
kinit
to get a kerberos ticket to access the users svn repository. This tag (V00-00-05) has been tested with ana-0.13.4 and should work with later releases. This is the release when the TimeTool.Analyze package started to use the TimeTool::DataV1 object.
The package includes scripts in the TimeToolExamples/app subdirectory. It is intended that users will modify these scripts for their purposes.
*IMPORTANT* after modifying a script in the app sub-directory of a package, you *MUST* run scons. This installs a copy of the script (with a modification to the #! line) in the myrel/arch directory. The file in myrel/arch is what is actually run.
SXR case study: EVR BYKICK signals no beam
This is the most straightforward way to run the TimeTool and, I believe, the expected way it is run in SXR. The laser is always on, but the beam is not present when the evr bykick code is present. The TimeTool.Analyze module will build up a reference during the BYKICK shots, and compute results for all other shots. An example script which executes this scenario can be found in
TimeToolExamples/app/tt_sxr_bykick
After installing the package in a test release as described above and running scons, do
tt_sxr_bykick -h
to get help from the script. The script was developed/tested against this data:
tt_sxr_bykick -e sxri0214 -r 158 -n 100
The -n option is a testing option that limits the number of events to the first 100. The script generated a log plot of the image and plots the time tool pixel position result over the plot.
One can read the code for the script here:
SXR case study: reference/signal in different runs
Below we go over a script for generated offline TimeTool data for an sxr experiment. For this experiment, run 144 was done with the beam blocked, and run 150 with the beam on. The laser is always on in both runs.
This requires some configuration of the TimeTool. We run the TimeTool.Analyze module on run 144 - telling it that the beam is always off. Analyze builds up a reference. We further configure Analyze to save the reference. We also save a averaged background image for our own interactive plotting later.
We then run TimeTool.Analyze on run 150. We save the resulting timetool values to an hdf5 file using the psana xtc to hdf5 translator, see The XTC-to-HDF5 Translator for details.
Finally, to check the work, we process run 150 in index mode, see psana - Python Script Analysis Manual for details on indexing mode (random access) to psana events. We load the time tool values from the h5 file and plot them against the opal, after subtracting our background image.
The TimeToolExamples package discusses above includes two files for this case study. The first is the script that designates the sxr experiment data to run on. It is the file TimeToolExamples/app/tt_sxrd5814. You can immediately take a look at the code here: tt_sxrd5814. The second is a library of functions called by the driver script: TimeToolExamples/src/ttlib.py that you can download here: ttlib.py. Instead of the addpkg command above, one can do
newpkg mypkg
mkdir mypkg/src
mkdir mypkg/app
and download the files into
mypkg/app/tt_sxrd5814
mypkg/src/ttlib.py
and run
scons
to build the code. The run the script, from the release directory do
tt_sxrd5814
Note, users of other experiments will not be able to access the data from this experiment. You will want to modify TimeToolExamples/app/tt_sxrd5814 to read your own data. Note the warning above about running scons after modifying a script in the app subdirectory.
After running the script as is, it should produce the files
ttref_sxrd5814_r0144.txt # reference that TimeTool.Analayze produced ttref_sxrd5814_r0144.npy # our own background reference for plotting tt_sxrd5814_r0150.h5 # the h5 file with the timetool results for r150
This script builds a background from the first 300 events in run 144,
and processes the first 500 events in run 150.
A recursive listing of the h5 file should show, among other groups:
h5ls -r tt_sxrd5814_r0150.h5 /Configure:0000/Run:0000/CalibCycle:0000/TimeTool::DataV1/noSrc__TTANA/data Dataset {500/Inf} /Configure:0000/Run:0000/CalibCycle:0000/TimeTool::DataV1/noSrc__TTANA/time Dataset {500/Inf}
The data dataset is the TimeTool::DataV1 objects. If you get a verbose listing of this dataset, you'll see something like:
psanacs058:~/rel/TimeTool3 $ h5ls -v tt_sxrd5814_r0150.h5/Configure:0000/Run:0000/CalibCycle:0000/TimeTool::DataV1/noSrc__TTANA/data data Dataset {500/Inf} Location: 1:8396 Links: 1 Chunks: {2048} 114688 bytes Storage: 28000 logical bytes, 114688 allocated bytes, 24.41% utilization Type: struct { "event_type" +0 enum native unsigned int { Dark = 0 Reference = 1 Signal = 2 } "amplitude" +8 native double "position_pixel" +16 native double "position_time" +24 native double "position_fwhm" +32 native double "ref_amplitude" +40 native double "nxt_amplitude" +48 native double } 56 bytes
This shows you the six fields with the TimeTool Data, and also the enum values for the first field that identifies the event type.
The time dataset stores the event id's for the data - the seconds, nanoseconds and fiducials.
After running the script once, the second time the script is run, it will produce
interactive plots.