Versions Compared

Key

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

...

Interactive analysis with IPython

The LCLS offline analysis group does have plans for a real interactive pyana, but currently this is not available.
2011-11-04 iPsana Interactive Analysis Framework.pdf

The version available in our offline release system is
IPython 0.9.1 – An enhanced Interactive Python.
so this is the one I've been using in these examples.
Not a whole lot more than a python shell.

...

Panel
titleLoading your arrays into (I)Python and plotting interactively:
Code Block
[ofte@psana0106 xpptutorial]$ ipython
Python 2.4.3 (#1, Nov  3 2010, 12:52:40)
Type "copyright", "credits" or "license" for more information.

IPython 0.9.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from numpy import *

In [2]: from matplotlib.pyplot import *

In [3]: ipm3 = load('point_scan_delay.npy')

In [4]: ipm3.shape
Out[4]: (200, 3)

In [5]: ion()

In [6]: delay = ipm3[:,0]

In [7]: ipmraw = ipm3[:,1]

In [8]: ipmnorm = ipm3[:,2]

n [9]: plot(delay,ipmnorm,'ro')
Out[9]: [<matplotlib.lines.Line2D object at 0x59c4c10>]

In [10]: draw()

In [11]:

Non-interactive batch analysis

Pyana jobs are designed to do batch analysis, but matplotlib plotting does not go well with this. If you want your job to produce graphics, make sure to use a matplotlib backend that writes the graphics directly to file, e.g. png files.

Multiprocessing

Pyana can make use of multiple core processing. On the command line, add the option '-p N' where N is the number of cores to use.

Extra care needs to be taken when plotting. Also, output files need to be made with the pyana mkfile command. The output will be merged at the end of the job, but may not be in order. So if you need events to be written to a file in chronological order, you're better off using single core processing.

Extracting the data with pyana, some examples

Outline of a pyana module

Like the other frameworks, pyana is an executable that loops through the XTC file and calls all
requested user modules at certain transitions. All the analysts need to do is to fill in the
relevant functions in their user analysis module:

Toggle Cloak
idkappe
code (pyana outline)

Extracting the data with pyana, some examples

Outline of a pyana module

Like the other frameworks, pyana is an executable that loops through the XTC file and calls all
requested user modules at certain transitions. All the analysts need to do is to fill in the
relevant functions in their user analysis module:

Toggle Cloak
idkappe
code (pyana outline)

Cloak
idkappe
Panel

For the following two examples, check

Cloak
idkappe
Panel

For the following two examples, check out the latest version of the pyana_examples package:

Code Block
none
none
addpkg pyana_examples HEAD
scons

...

Cloak
iddelayscan
  • Fetching the ControlPV information:
    ControlPV is available from the env object, and since it only changes at the beginning
    of each calibration cycle, the begincalibcycle function is the appropriate place to get it:
    none
    The ControlConfig object may contain several pvControl and pvMonitor objects. In this case
    there's only one, but make sure the name matches anyway: none
  • Fetching the IPIMB and PhaseCavity information:
    All the other information that we need, is available through the evt object, and
    event member function is the place to get it:
    none
    Use "XppSb3Ipm-1|Ipimb-0" (a.k.a. IPM3) sum of all channels for normalization and filtering
    none
    Use "XppSb3Pim-1|Ipimb-0" (a.k.a. PIM3) channel 1 as signal
    none
    Get the phase cavity:
    none
    Compute delay time and fill histograms
    none

Image peak finding

Here are a collection of useful algorithms for image analysis: http://docs.scipy.org/doc/scipy/reference/ndimage.html

...

Panel

Try some plotting of CSPad data using xtcexplorer. Launch the explorer and load xpp48712 run 66 (a dark run):

Code Block
none
none
xtcexplorer /reg/d/psdm/XPP/xpp48712/xtc/e153-r0066-s00-c00.xtc
  • *Look through a couple of events, then "Quit Pyana" and edit the configuration file. Add an output file name, and switch to "NoDisplay" and run 100 events to collect an average of dark images.
  • With darks collected, load another file from the same experiment: run 141. Edit the pyana configuration file to use the file you just generated to subtract darks. Run the explorer in "SlideShow" mode again.
  • Change the color scale of the plot by left and right clicking on the colorbar
  • Pyana" and edit the configuration file. Add an output file name, and switch to "NoDisplay" and run 100 events to collect an average of dark images.
  • With darks collected, load another file from the same experiment: run 141. Edit the pyana configuration file to use the file you just generated to subtract darks. Run the explorer in "SlideShow" mode again.
  • Change the color scale of the plot by left and right clicking on the colorbar.

Non-interactive batch analysis

Pyana jobs are designed to do batch analysis, but matplotlib plotting does not go well with this. If you want your job to produce graphics, make sure to use a matplotlib backend that writes the graphics directly to file, e.g. png files.

Multiprocessing

Pyana can make use of multiple core processing. On the command line, add the option '-p N' where N is the number of cores to use.

Extra care needs to be taken when plotting. Also, output files need to be made with the pyana mkfile command. The output will be merged at the end of the job, but may not be in order. So if you need events to be written to a file in chronological order, you're better off using single core processing.