You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

  • matplotlib pyplot / pylab
    ... an open-source plotting tool

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 library
    In [1]: import matlab
    Pretend this is matlab
    In [2]: 
    

    who and whos
    In [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 module
    In [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 editing
    In [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

  • No labels