Interactive data analysis with iPython
Many users are familiar with matlab, which is not supported by the LCLS offline group. This is a description of how you can use interactive python to analyze your data in a very similar way.
Many thanks to the XPP crew, Henrik Lemke in particular, for providing guidance, code examples (in matlab) and feedback in writing the python scripts presented here.
The components
- ipython
... an interactive python shell
External links:
- matplotlib pyplot / pylab
... an open-source plotting tool
- numpy
... numeric python
External links:
The Matlab-like tools / library provided by PCDS
- matlab.py
... a module implementing in python some of the tools written by Henrik/XPP for matlab
Starting iPython[ofte@psana0XXX myrelease]$ 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.
Loading the libraryIn [1]: import matlab Pretend this is matlab In [2]:
who and whosIn [2]: who matlab # who gives you a brief list of your workspace contents In [3]: whos Variable Type Data/Info # whos gives you a longer list of your workspace contents ------------------------------ matlab module <module 'matlab' from 'matlab.py'> In [4]:
more about a moduleIn [4]: matlab.<TAB> # write matlab. and hit the TAB button to see available functions in matlab.py matlab.__builtins__ matlab.__hash__ matlab.__class__ matlab.__init__ matlab.__delattr__ matlab.__name__ matlab.__dict__ matlab.__new__ matlab.__doc__ matlab.np matlab.__file__ matlab.plt matlab.filtvec matlab.py matlab.findmovingmotor matlab.py~ matlab.__getattribute__ matlab.pyc matlab.get_filter matlab.rdXPPdata matlab.get_limits matlab.__reduce__ matlab.get_limits_automatic matlab.__reduce_ex__ matlab.get_limits_channelhist matlab.__repr__ matlab.get_limits_correlation matlab.runexpNO2fina matlab.get_limits_corrfrac matlab.ScanInput matlab.getSTDMEANfrac_from_startpoint matlab.ScanOutput matlab.H5getobjnames matlab.__setattr__ matlab.h5py matlab.__str__
after editingIn [5]: reload matlab -------> reload(matlab) # if you edited matlab.py, reload it before you continue Pretend this is matlab Out[15]: <module 'matlab' from 'matlab.py'>
Examples
1) Select limits from graphical input and plot filtered IPIMB
Overview
Content Tools