PyXSanalysis
pyXSanalysis is a series of Python scripts that use extend the pyXS software package. This code is intended to automate various aspects of data-treatment for SAXS and WAXS area images.
Contents
Installing (Summary)
- You will need Python 2.6 installed, including the packages:
- numpy (Numerical Python)
- matplotlib (plotting package)
- PIL (Python Image Library)
- (Optional) GSL (GNU Scientific Library) and PyGSL is necessary for certain advanced features.
- Simply copy the entire directory of Python scripts somewhere on your machine, and run them.
- Note that the first time you run the scripts, you may get an error like:
ImportError: /pyXSanalysis/pyXS/_RQconv.so: wrong ELF class: ELFCLASS32
- To fix this, you will need to use a version of RQconv appropriate to your platform (Windows, Mac, Linux, etc.). Go into the sub-folder "pyXSanalysis/pyXS/RQconv_versions/" and see if there is a directory appropriate for your system. If so, copy all the contents of that directory into "pyXSanalysis/pyXS/". If none of the available RQconv versions work for you, then you will need to compile a new one:
- Install SWIG (Simplified Wrapper and Interface Generator)
- Go into the pyXSanalysis/pyXS/ sub-directory.
- Delete the file "_RQconv.so"
- Rebuild a new RQconv by using:
python setup.py build_ext --inplace
Windows Installation Instructions
- Copy the Python scripts somewhere appropriate on your computer (e.g. C:\pyXSmain\). The directory should contain "analysis.py" and the sub-directory "pyXSanalysis".
- Install Python 2.6:
- Go to http://www.python.org/download and download the latest version of Python 2.6 (e.g. click Python 2.6.4 Windows installer).
- Install python by running the downloaded file (e.g. python-2.6.4.msi)
- Install necessary Python packages:
- numpy (Numerical Python)
- Go to Numpy download page and download a recent version (e.g. 1.3.0)
- Run the executable (e.g. numpy-1.3.0-win32-superpack-python2.6.exe) and follow the instructions to install.
- PIL (Python Image Library)
- Go to PIL homepage and download a recent release (e.g. Python Imaging Library 1.1.7 for Python 2.6)
- Run the executable (e.g. PIL-1.1.7.win32-py2.6.exe) and follow the instructions to install.
- matplotlib (a Python plotting library)
- Go to download page and download a recent version (e.g. 0.99.0)
- Run the executable (e.g. matplotlib-0.99.1.win32-py2.6.exe) and follow the instructions.
- numpy (Numerical Python)
- Switch to a version of RQconv appropriate to your platform (Windows, Mac, Linux, etc.):
- Go into the sub-folder "pyXSanalysis\pyXS\RQconv_versions\"
- Find a directory appropriate for your system. The version "x86.Windows7.virtualbox" should work for Windows 7.
- Copy the entire contents of the directory into "pyXSanalysis\pyXS\". Thus, you are copying the files "_RQconv.pyd", "RQconv.o", and so on, into the pyXS folder.
- If none of the available RQconv versions work for your system, you may get an error like:
ImportError: /pyXSanalysis/pyXS/_RQconv.so: wrong ELF class: ELFCLASS32
- In that case, you will need to compile a new version of RQconv:
- Install MinGW:
- From the download page, download the "Automated MinGW Installer" (e.g. MinGW-5.1.6.exe).
- Run the executable. When selecting components, include "MinGW base tools", "g++ compiler" and "MinGW Make".
- Add appropriate environment variables:
- Open the "System Properties" from the Windows Control Panel. On the "Advanced" tab, select "Environment Variables..."
- Edit the system variable called "Path" by adding entries at the end (separated by semi-colons):
- C:\python26\;C:\MinGW\bin\
- Install SWIG (Simplified Wrapper and Interface Generator) for Python access to C-code:
- Go to the download page and download a recent version (e.g. swigwin-1.3.40).
- Unzip the package and extract the folder within.
- Move the folder (e.g. swigwin-1.3.40) to a sensible location (e.g. C:\swig\).
- Add appropriate environment variables:
- Open the "System Properties" from the Windows Control Panel. On the "Advanced" tab, select "Environment Variables..."
- Edit the system variable called "Path" by adding entries at the end (separated by semi-colons):
- C:\python26\;C:\MinGW\bin\;C:\swig\
- Also create two new system variables like:
- PYTHON_INCLUDE: D:\python21\include
- PYTHON_LIB: D:\python21\libs\python21.lib
- Build RQConv using SWIG
- Open a Windows shell (e.g. Start > Run > "cmd")
- Navigate to the proper directory:
- cd C:\pyXSmain\pyXSanalysis\pyXS\
- Build the module using the provided "setup.py" script:
- c:\python26\python setup.py build_ext --inplace --compiler=mingw32
- Copy the newly-created files (_RQconv.pyd RQconv.py RQconv_wrap.c) into the pyXS directory.
- Run the Python file:
- python ./analysis.py
How to run on Windows
Once everything is installed, you can right-click on the "analysis.py" file, and select "Edit with IDLE...". This will open the file. You can then select "Run" (F5) to run the code, and edit the code in "analysis.py" in order to do different kinds of analyses. You can browse through the file "pyXSanalysis\processing.py" to see what kinds of analysis routines are available (and what options they take). You can look in "examples\various.py" to see some examples of code you could put into "analysis.py".
Troubleshooting the RQconv compiling
- If you get an error message like:
- C:\pyXSmain\pyXSanalysis\pyXS>python setup.py build_ext --inplace
- running build_ext
- building '_RQconv' extension
- swigging RQconv.i to RQconv_wrap.c
- C:\swig\swig.exe -python -o RQconv_wrap.c RQconv.i
- RQconv.i(9): Error: Unable to find 'numpy.i'
- error: command 'swig.exe' failed with exit status 1
- Then you need to find the "numpy.i" interface file and let swig find it. You can browse the numpy code and download numpy.i. Then place it in the build directory (C:\pyXSmain\pyXSanalysis\pyXS\).
- If you get an error message like:
- C:\pyXSmain\pyXSanalysis\pyXS>python setup.py build_ext --inplace
- running build_ext
- building '_RQconv' extension
- swigging RQconv.i to RQconv_wrap.c
- C:\swig\swig.exe -python -o RQconv_wrap.c RQconv.i
- error: Unable to find vcvarsall.bat
- Then you probably need to install MinGW correctly and specify it as the compiler you wish to use (--compiler=mingw32 flag).
Mac OS X Installation Instructions
- Copy the Python scripts somewhere appropriate on your computer (e.g. ~/Desktop/pyXSmain/). The directory should contain "analysis.py" and the sub-directory "pyXSanalysis".
- Python should already be installed. (If not, go here.)
- Install necessary Python packages:
- PIL (Python Image Library)
- Go to PIL homepage and download a recent release (e.g. Python Imaging Library 1.1.7 Source Kit)
- Extract the tar file (double-click on file, or in terminal use: tar xzvf Imaging-1.1.7.tar.gz
- Go into the folder that has just been created (cd Imaging-1.1.7)
- Build:
python setup.py install
- PIL (Python Image Library)
Troubleshooting
Python Image Library (PIL)
- If you get the error:
- lipo: can't open input file: /var/tmp//ccG8BgoP.out (No such file or directory)
- error: command 'gcc-4.2' failed with exit status 1
- Then you need to manually re-run the gcc command that failed, but remove the unnecessary "-arch PPC" flag:
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _imaging.c -o build/temp.macosx-10.6-universal-2.6/_imaging.o
- And keep building, removing "-arch ppc" as needed:
- python setup.py build
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c decode.c -o build/temp.macosx-10.6-universal-2.6/decode.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c encode.c -o build/temp.macosx-10.6-universal-2.6/encode.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c map.c -o build/temp.macosx-10.6-universal-2.6/map.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c display.c -o build/temp.macosx-10.6-universal-2.6/display.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c outline.c -o build/temp.macosx-10.6-universal-2.6/outline.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c path.c -o build/temp.macosx-10.6-universal-2.6/path.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Access.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Access.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Antialias.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Antialias.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Bands.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Bands.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/BitDecode.c -o build/temp.macosx-10.6-universal-2.6/libImaging/BitDecode.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/BitDecode.c -o build/temp.macosx-10.6-universal-2.6/libImaging/BitDecode.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Blend.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Blend.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Chops.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Chops.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Convert.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Convert.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/ConvertYCbCr.c -o build/temp.macosx-10.6-universal-2.6/libImaging/ConvertYCbCr.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Copy.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Copy.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Crc32.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Crc32.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Crop.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Crop.o
- gcc -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c libImaging/Dib.c -o build/temp.macosx-10.6-universal-2.6/libImaging/Dib.o
- Etc.