Skip to content

Instantly share code, notes, and snippets.

@phaustin
Last active March 22, 2016 04:24
Show Gist options
  • Select an option

  • Save phaustin/ec4ef02f403d78f25e53 to your computer and use it in GitHub Desktop.

Select an option

Save phaustin/ec4ef02f403d78f25e53 to your computer and use it in GitHub Desktop.
Readme_scipy.org

netcdf and hdf

building netcdf4python

export HDF5_DIR=/users/user-soft/usr251_Centos export NETCDF4_DIR=/users/user-soft/usr251_Centos/gfortran export LD_RUN_PATH=’/users/user-soft/usr251_Centos/lib:/users/user-soft/usr251_Centos/gfortran’

hdf5 1.8.9


./configure –prefix=/users/user-soft/usr251_Centos –enable-hl –enable-shared –enable-cxx

netcdf 4.3.1.1 – intel


http://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-netcdf-with-the-intel-compilers

export CC=/users/user-soft/bin/gcc export CXX=/users/user-soft/bin/g++ export LD_RUN_PATH=/users/user-soft/usr251_Centos/lib export CPPFLAGS=-I/users/user-soft/usr251_Centos/include export LDFLAGS=’-L/users/user-soft/usr251_Centos/lib ’ ./configure –prefix=/users/user-soft/netcdf_ifort90

export CC=gcc export CXX=g++ export LD_RUN_PATH=/usr/lib export CPPFLAGS=-I/usr/include export LDFLAGS=’-L/usr/lib’ ./configure –prefix=/opt/local/netcdf_ifort

for fortran

export F77=ifort export FC=ifort export F90=ifort export CPPFLAGS=’-I/users/user-soft/usr251_Centos/include -I/users/user-soft/netcdf_ifort90/include’ export LDFLAGS=’-L/users/user-soft/usr251_Centos/lib -L/users/user-soft/netcdf_ifort90/lib -lnetcdf’ export FFLAGS=’-O3 -xHost -ip -no-prec-div -static-intel -I/users/user-soft/netcdf_ifort90/include’ export LD_RUN_PATH=’/users/user-soft/netcdf_ifort90/lib:/users/user-soft/usr251_Centos/lib’ ./configure –prefix=/users/user-soft/netcdf_ifort90

newroc

export F77=ifort export FC=ifort export F90=ifort export CPPFLAGS=’-I/usr/include -I/opt/local/netcdf_ifort/include’ export LDFLAGS=’-L/usr/lib -lhdf5_hl -L/opt/local/netcdf_ifort/lib -lnetcdf -L/opt/intel/lib/intel64 -lifport -lifcore -limf -lsvml -lintlc -Wl,-rpath -Wl,/opt/intel/lib/intel64’ export FFLAGS=’-O3 -xHost -ip -no-prec-div -static-intel -I/opt/local/netcdf_ifort/include’ export LD_RUN_PATH=’/opt/local/netcdf_ifort/lib:/usr/lib:/opt/intel/lib/intel64’ ./configure –prefix=/opt/local/netcdf_ifort

make check fails for j=10

netcdf 4.3.0 – pgi


export CC=/users/user-soft/bin/gcc export CXX=/users/user-soft/bin/g++ export FC=/users/user-soft/bin/gfortran export F90=/users/user-soft/bin/gfortran export LD_RUN_PATH=/users/user-soft/usr251_Centos/lib export CPPFLAGS=-I/users/user-soft/usr251_Centos/include export LDFLAGS=-L/users/user-soft/usr251_Centos/lib ./configure –prefix=/users/user-soft/usr251_Centos/gfortran

pgf90 -c -fpic -shared -I/users/user-soft/usr251_Centos/include nc4_simple_xy_wr.f90 pgf90 -o test -Wl,-rpath -Wl,/users/user-soft/usr251_Centos/lib -L/users/user-soft/usr251_Centos/lib -lnetcdff -L/users/user-soft/usr251_Centos/lib -lnetcdf nc4_simple_xy_wr.o

netcdf fortran


look at config.log to make sure everything is running

export LD_RUN_PATH=/users/user-soft/lib64:/users/user-soft/usr251_Centos/gfortran/lib:/users/user-soft/usr251_Centos/lib ./configure –prefix=/users/user-soft/usr251_Centos/gfortran

current on kite – netcdf and hdf


/home/datatmp/phil/cdat-5.2-src phil@swift% ./configure –prefix=/home/phil/usr64/cdat –with-python=/home/phil/usr64/bin/python –with-hdf5=/home/phil/usr64_nc4 –with-netcdf=/home/phil/usr64_nc4_gfortran

~/install phil@swift% cd hdf5-1.8.5 ~/install/hdf5-1.8.5 phil@swift% export FC=gfortran ~/install/hdf5-1.8.5 phil@swift% export FFLAGS=-fPIC ~/install/hdf5-1.8.5 phil@swift% export CFLAGS=-fPIC o./configure –prefix=/home/phil/usr64_hdf1.8.5_gfortran –enable-hl –enable-shared –enable-fortran –enable-cxx

~/install/netcdf-4.1.1 phil@swift% export FC=gfortran ~/install/netcdf-4.1.1 phil@swift% export FLAGS=-fPIC ~/install/netcdf-4.1.1 phil@swift% export CFLAGS=-fPIC ./configure –prefix=/home/phil/usr64_nc4_gfortran –with-hdf5=/home/phil/usr64_hdf1.8.5_gfortran –enable-shared

cd ~/install/netcdf4-python export NETCDF3_DIR=/home/phil/usr64/netcdf_3.6.3_gfortran export HDF5_DIR=/home/phil/usr64_hdf1.8.5_gfortran export NETCDF4_DIR=/home/phil/usr64_nc4_gfortran python setup.py install python setup-nc3.py install

current for roc (2009/may/8)


building atlas and lapack http://thread.gmane.org/gmane.comp.python.scientific.devel/8274/focus=8275 <file:///~/public_html/readmes/Readme_scipy.nm#* build – current>

scipy/numpy <file:///~/public_html/readmes/Readme_scipy.nm#* numpy scipy compile – good 2009/7/5 —>

<file:///~/NOTES/200911/091111#* admin – install gcc current>

umfpack:

http://www.cise.ufl.edu/research/sparse/amd/current/AMD.tar.gz http://www.cise.ufl.edu/research/sparse/umfpack/current/UMFPACK.tar.gz http://www.cise.ufl.edu/research/sparse/UFconfig/current/UFconfig.tar.gz ~/install/numpy/ mv UFconfig UMFPACK mv AMD UMFPACK

nfs/kite/home/phil/install/UMFPACK/Include phil@tern% cp * ~/usr64/include nfs/kite/home/phil/install/AMD phil@tern% cp -a Include/*.h ~/usr64/include. nfs/kite/home/phil/install phil@tern% cp UFconfig/UFconfig.h ~/usr64/include

plus .a files copy to ~/usr64/lib

~/install/UFconfig phil@tern% hg diff -r 0 -r 1 UFconfig.mk diff -r f5b8cdb7802e -r 8301480cbd9c UFconfig.mk — a/UFconfig.mk Sat Jun 13 20:26:40 2009 -0700 +++ b/UFconfig.mk Sat Jun 13 20:27:09 2009 -0700 @@ -33,7 +33,7 @@

-CC = cc +CC = gcc

@@ -48,8 +48,8 @@ MV = mv -f

-F77 = f77 -F77FLAGS = -O +F77 = gfortran +F77FLAGS = -O -fPIC F77LIB =

@@ -89,8 +89,8 @@

-BLAS = -lblas -lgfortran -lgfortranbegin -lg2c -LAPACK = -llapack +BLAS = -L/home/phil/usr64/lib -lblas -lgfortran +LAPACK = -L/home/phil/usr64/lib -llapack

@@ -106,10 +106,10 @@

-XERBLA = +XERBLA = /home/phil/usr64/lib/liblapack.a

-# XERBLA = ../../UFconfig/xerbla/libxerbla.a +#XERBLA = ../../UFconfig/xerbla/libxerbla.a

#------------------------------------------------------------------------------

@@ -220,7 +220,7 @@

-CFLAGS = -O3 -fexceptions +CFLAGS = -O3 -fexceptions -fPIC

~/install/UFconfig phil@tern%

numpy scipy compile – good 2009/7/5 —


export LD_LIBRARY_PATH=/home/phil/usr_py26/lib

double check numpy-trunk/numpy/distutils/site.cfg is current

for scipy and numpy python setup.py config_fc –fcompiler=gfortran –f77exec=gfortran –f90exec=gfortran build

get this erroneous message

customize GnuFCompiler Found executable /usr/bin/g77 gnu: no Fortran 90 compiler found gnu: no Fortran 90 compiler found customize GnuFCompiler gnu: no Fortran 90 compiler found gnu: no Fortran 90 compiler found customize GnuFCompiler using config

followed by this correct message:

Found executable /usr/bin/gfortran customize Gnu95FCompiler using config C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC o

and this

gcc: numpy/linalg/lapack_litemodule.c /usr/bin/gfortran -Wall -Wall -shared build/temp.linux-x86_64-2.5/numpy/linalg/lapack_litemodule.o build/temp.linux-x86_64-2.5/numpy/linalg/python_xerbla.o -L/home/phil/usr64/lib -Lbuild/temp.linux-x86_64-2.5 -llapack -lptf77blas -lptcblas -latlas -lgfortran -o build/lib.linux-x86_64-2.5/numpy/linalg/lapack_lite.so

then

~/install/setuptools-0.6c11 phil@tern% ~/usr_py26/bin/python setup.py install

~/install/setuptools-0.6c11 phil@tern% ~/usr_py26/bin/easy_install f2py

~/install/setuptools-0.6c11 phil@tern% ~/usr_py26/bin/easy_install nose

import numpy numpy.test(‘fast’)

need:

f2py –fcompiler=gfortran -c Driver.f90 -m _thermodyn http://maths.ucd.ie/~rca/cgi/toa_balance.html

matplotlib roc:

export F77=gfortran export GEOS_DIR=/users/user-soft/usr251_Centos python setup.py install

matplotlib tern:

/space/phil/install_2009_02_12/numpy-trunk phil@roc% svn update python setup.py config_fc –fcompiler=gfortran –f77exec=gfortran –f90exec=gfortran build double check /space/phil/install_2009_02_12/numpy-trunk/numpy-trunk/numpy/distutils/site.cfg

mv mv /home/phil/usr64/lib/python2.5/site-packages/numpy

for cdat: ~/install/cdat-5.1.0 phil@roc% export F77=gfortran ~/install/cdat-5.1.0 phil@roc% ./configure –prefix=/home/phil/cdat –with-python=/users/user-soft/usr251_Centos/bin/python

then add /home/phil/cdat/lib/python2.5/site-packages to PYTHONPATH and /home/phil/cdat/bin to PATH

copying numpy/distutils/site.cfg -> home/phil/usr64/lib/python2.5/site-packages/numpy/distutils

import numpy numpy.test(‘fast’)

rm -rf ~/install/scipy-trunk/build

export UMFPACK=”None”

~/install/scipy-trunk phil@tern% python setup.py config_fc –fcompiler=gfortran install

scipy.test(‘fast’)

matplotlib – write setup.cfg

rm -rf ~/install/matplotlib-trunk/matplotlib/build/ rm -rf /home/phil/usr64/lib/python2.5/site-packages/matplotlib

python setup.py install

~/install/matplotlib-trunk/toolkits/basemap phil@tern% rm -rf build

export F77=gfortran export GEOS_DIR=/home/phil/usr64

~/install/matplotlib-trunk/toolkits/basemap/geos-2.2.3 phil@tern% ./configure –prefix=$GEOS_DIR

rm -rf /home/phil/usr64/lib/python2.5/site-packages/mpl_toolkits ~/install/matplotlib-trunk/toolkits/basemap phil@tern% rm -rf build

python setup.py install

hg clone http://hg.cython.org/cython

or

~/install/cython phil@tern% hg pull hg update

~/install/cython phil@tern% rm -rf /home/phil/usr64/lib/python2.5/site-packages/Cython ~/install/cython phil@tern% rm -rf /home/phil/usr64/bin/cython

rm -rf build python setup.py install

bzr branch lp:ipython bzr update python setup.py install

python -c “import numpy; print numpy.show_config()”

scipy help files


http://news.gmane.org/gmane.text.docutils.user http://thread.gmane.org/gmane.comp.python.scientific.devel/2969/focus=2995 http://article.gmane.org/gmane.comp.python.scientific.devel/3900/match=moinmoin http://search.gmane.org/?query=moinmoin&author=andrew+straw&group=gmane.comp.python.scientific.*&sort=date&DEFAULTOP=and&xP=extrapolate&xFILTERS=Gcomp.lib.boost.*—A http://dir.gmane.org/gmane.comp.web.wiki.moin.general http://news.gmane.org/gmane.comp.python.pytables.user http://www.37mm.no/mpy/idl-numpdy.html /home/phil/usr243/lib/python2.4/site-packages/numpy/core/include/numpy/__multiarray_api.h /home/phil/usr243/lib/python2.4/site-packages/numpy/core/include/numpy/arrayobject.h /home/phil/papers/scipybook.pdf /home/phil/include/pythonlibs/num_util/num_util.h http://www.scipy.org/NumPyCapi

http://numeric.scipy.org/

tutorial: http://www.rexx.com/~dkuhlman/scipy_course_01.html /users/CLUSTER/cluster-usr/i386/mpich1/lib http://numeric.scipy.org/numpydoc/numpy-22.html http://scipy.org/Numpy_Example_List http://www.scipy.org/doc/numpy_api_docs/ file:///home/phil/papers/scipybook.pdf http://search.gmane.org/ gmane.comp.python.* ////home/phil/philprojects/Readme_python.nm http://news.gmane.org/gmane.comp.lib.boost.build http://news.gmane.org/gmane.comp.lib.boost.devel http://news.gmane.org/gmane.comp.lib.boost.user http://www.scipy.org/NumPy_for_Matlab_Users http://news.gmane.org/gmane.comp.python.numeric.general http://news.gmane.org/gmane.comp.python.scientific.devel http://news.gmane.org/gmane.comp.python.scientific.user http://dir.gmane.org/gmane.comp.python.ipython.user http://news.gmane.org/gmane.comp.python.ipython.user http://news.gmane.org/gmane.comp.python.matplotlib.general http://news.gmane.org/gmane.comp.python.matplotlib.devel http://news.gmane.org/gmane.comp.python.devel http://news.gmane.comp.version-control.subversion

gmane.comp.tex.latex.beamer.general

http://search.gmane.org/?query=__import__&group=gmane.comp.python.*&sort=date&DEFAULTOP=and&xP=scipy.vectorize.&xFILTERS=Gcomp.python.*—A

http://search.gmane.org/?query=moinmoin&author=andrew+straw&group=gmane.comp.python.scientific.*&sort=date&DEFAULTOP=and&—A

curl -O -C - http://matplotlib.sourceforge.net/users_guide_0.87.1.pdf http://www.mathworks.com/access/helpdesk/help/techdoc/ref/plot.html http://www.mathworks.com/access/helpdesk/help/techdoc/ref/subplot.html http://www.mathworks.com/access/helpdesk/help/techdoc/ref/bar.html

python – scipy install notes step by step


prev: <none> next: <none>

~/Desktop/build phil@thrush% cd zlib-1.2.3 ~/Desktop/build/zlib-1.2.3 phil@thrush% ./configure –prefix=/home/phil/lib/centos && make install

~/Desktop/build/hdf5-1.8.0-beta1 phil@thrush% ./configure –with-zlib=/home/phil/lib/centos –prefix=/home/phil/lib/centos && make install

sh% export F90=/usr/bin/gfortran ~/Desktop/build phil@thrush% export FC=/usr/bin/g77 <file://///home/phil/NOTES/200712/071205#* install – netcdf4 results>

pythables 2.0.2:

python27 setup.py build_ext –inplace –hdf5=/home/phil/usr_owl –lflags=”-Xlinker -rpath -Xlinker /home/phil/usr_owl/lib”

http://code.google.com/p/netcdf4-python/ ~/Desktop/build/netCDF4-0.7.1 phil@thrush% export HDF5_DIR=/home/phil/lib/centos ~/Desktop/build/netCDF4-0.7.1 phil@thrush% export NETCDF4_DIR=/home/phil/lib/centos python setup.py install ~/Desktop/build/netCDF4-0.7.1/test phil@thrush% cd test ~/Desktop/build/netCDF4-0.7.1/test phil@thrush% python run_all.py

<file://///home/phil/NOTES/200712/071205#* install – pytables 2.0.2>

for netcdf in sandbox – after build need to

cp sandbox/netcdf/netcdf.py ~/usr243_Fc3/lib/python2.4/site-packages/sandbox/netcdf/ cp ~/usr243_Fc3/lib/python2.4/site-packages/scipy/sandbox/__init__.py ~/usr243_Fc3/lib/python2.4/site-packages/scipy/sandbox/netcdf/

the edit ~/usr243_Fc3/lib/python2.4/site-packages/sandbox/netcdf/netcdf.py

From: Rob Hetland <hetland <at> tamu.edu> Subject: sandbox.netcdf does not install correctly. Newsgroups: gmane.comp.python.scientific.user Date: 2006-07-11 16:23:35 GMT (1 year, 20 weeks, 5 days, 23 hours and 21 minutes ago)

The netcdf class in the scipy sandbox does not install correctly. I have installed this utility by hand, moving the required files over to the site-packages directory, and the package does work (after the import statements are fixed), it’s just the installation doesn’t move the right files over. I am very bad at distutils, so I will simply describe what needs to be changed:

The import statements including Scientific_netcdf need to be changed to:

from _netcdf import * from _netcdf import _C_API

netcdf.py needs to be transfered to the correct directory. It would most likely be best to put things in a netcdf directory, with an __init__.py (absent now, as far as I can tell). Other than these small installation issues, it seems to work great!

-Rob

build has to be done on gull (site.cfg needs files in /raid, could export it)

note that Lib directory no longer exists – sandbox is under scipy

need to cp /raid/datatmp/phil/install/numpy-trunk/numpy/distutils/site.cfg /home/phil/usr243/lib/python2.4/site-packages/numpy/distutils/site.cfg

svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk matplotlib-trunk /raid/datatmp/phil/install/numpy-trunk/numpy/distutils/site.cfg

python setup.py config_fc –fcompiler=gnu build_src build_clib build_ext build numpy.test(10,verbosity=10)

http://pong.tamu.edu/tiki/tiki-view_blog_post.php?blogId=6&postId=97

> I have also the old g77 compiler installed (g77-3.4.6). Is there a way to force numpy/scipy to use it?

Sure.

python setup.py config_fc –fcompiler=gnu build_src build_clib build_ext build

> I tried to f2py the above code but since I am using enthought > edition of scipy it demands visual studio.

Use –compiler=mingw32 on the appropriate commands. If you are building from a setup.py, you would do

$ python setup.py build_src build_clib –compiler=mingw32 build_ext –compiler=mingw32

I forget what you would do when using the f2py2e script, though.

They ought to be. BTW, you might want to try

python setup.py build_src build_clib build_ext –inplace

and add src/lib to your PYTHONPATH. I think most of us at Enthought develop in this way for better or worse.

svn co http://svn.scipy.org/svn/numpy/trunk/ ./numpy-trunk svn co https://svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib-trunk svn co http://svn.scipy.org/svn/scipy/trunk ./scipy-trunk svn co http://ipython.scipy.org/svn/ipython/ipython/trunk ipython-trunk

apply thses patches, following directions in ///~/philprojects/home/matthew/winpython/Readme_winpython.nm

From: Nicolas Pernetty <nicopernetty <at> yahoo.fr> Subject: Re: IPython in XEmacs now working on Windows Newsgroups: gmane.comp.python.ipython.user Date: 2007-02-01 22:46:53 GMT (3 weeks, 2 days, 23 hours and 17 minutes ago)

From: “R. Bernstein” <rocky@panix.com> Sender: ipython-user-bounces@scipy.org Reply-To: rocky@panix.com To: ipython-user@scipy.net Subject: Re: [IPython-user] Colorizing lines in debuggers and post-mortem Date: Sat, 17 Feb 2007 23:38:50 -0500

cd ipython-trunk

/raid/datatmp/phil/install/ipython-trunk phil@gull% patch -p 0 < ~/python.patch patching file win32_manual_post_install.py patching file IPython/ColorANSI.py patching file IPython/genutils.py Hunk #1 succeeded at 1247 (offset 20 lines). /raid/datatmp/phil/install/ipython-trunk phil@gull% patch -p 0 < ~/Debugger-color.py patching file IPython/PyColorize.py patching file IPython/ultraTB.py patching file IPython/Debugger.py patching file IPython/Extensions/ipy_pydb.py /raid/datatmp/phil/install/ipython-trunk phil@gull%

  1. wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz

wget http://www.python.org/ftp/python/2.4.3/Python-2.4.3.tgz

or wget http://ipython.scipy.org/dist/ipython-0.7.1.tar.gz

./configure –prefix=/home/phil/usr243

svn update scipy-trunk svn update numpy-trunkmak svn update matplotlib-trunk svn update ipython-trunk

cd numpy

make sure /home/phil/install/numpy-trunk/numpy/distutils/site.cfg is as below

get it from previous version ~/install/numpy-trunk/numpy/distutils phil@owl% cp /home/phil/usr242/lib/python2.4/site-packages/numpy/distutils/site.cfg .

check to be sure /home/phil/install/numpy-trunk/numpy/distutils/site.cfg has been copied to /home/phil/usr243/lib/python2.4/site-packages/numpy/distutils/site.cfg

cd /home/phil/install/numpy-trunk

rm build rm -rf ~/usr243_Fc3/lib/python2.4/site-packages/numpy /home/phil/user243_Fc3/bin/python setup.py install

easy_install nose

import numpy numpy.test(10,verbosity=10)

cd scipy-trunk

setup.py install

cp sandbox/netcdf/netcdf.py ~/usr243_Fc3/lib/python2.4/site-packages/sandbox/netcdf/ cp ~/usr243_Fc3/lib/python2.4/site-packages/scipy/sandbox/__init__.py ~/usr243_Fc3/lib/python2.4/site-packages/scipy/sandbox/netcdf/

use as: import sandbox.netcdf.netcdf as nc

build ipython

setup.py install

build Numerical setup.py install

svn co https://svn.sourceforge.net/svnroot/matplotlib/trunk/toolkits

download and build pygtk http://ftp.gnome.org/pub/GNOME/sources/pygtk/2.4/

(need 2.4.1 for fc3) ~/install/pygtk-2.4.1 phil@gull% ./configure –prefix=/home/phil/usr242 make make install (libglade not found)

then do matplotlib so it enables the gtk backend

do basemap and copy data into

cp -af /home/phil/usr24/share/basemap /home/phil/usr242/share/basemap

Then get mailbox_reader

http://gradha.sdf-eu.org/program/mailbox_reader.en.html

http://pong.tamu.edu/tiki/tiki-view_blog_post.php?blogId=6&postId=97

export dgBLAS=/home/phil/install/ATLAS/lib/Linux_P4SSE2 export LAPACK=/home/phil/install/ATLAS/lib/Linux_P4SSE2 export ATLAS=/home/phil/install/ATLAS/lib/Linux_P4SSE2 export FFTW3=/usr/local/lib

Commands to check out:

svn co http://svn.scipy.org/svn/numpy/trunk numpy svn co http://svn.scipy.org/svn/scipy/trunk scipy

If you need further information, don’t hesitate to ask.

Yes, in fact it was the first build on a new computer. I just removed my build/, and site-packages/scipy and Numeric/ directories, rebuilt and reinstalled Numeric 24.1 and newcore/newscipy and still observe the segfault. I also tried installing Scipy-0.3.2, which did not have a problem with Numeric-24.1.

http://cens.ioc.ee/~pearu/scipy/INSTALL.html http://www.scipy.org/documentation/buildatlas4scipy.txt http://www.scipy.org/documentation/buildscipy.txt

blas/lapack/atlas


http://old.scipy.org/documentation/buildatlas4scipy.txt

mkdir -p ~/install/blas export BLAS_SRC=/home/phil/install/blas cd $BLAS_SRC wget http://www.netlib.org/blas/blas.tgz tar xzf blas.tgz g77 -fno-second-underscore -O2 -c *.f ar r libfblas.a *.o ranlib libfblas.a rm -rf *.o

wget http://www.netlib.org/lapack/lapack.tgz

export LAPACK_SRC=LAPACK mkdir -p $LAPACK_SRC cd $LAPACK_SRC/.. wget http://www.netlib.org/lapack/lapack.tgz tar xzf lapack.tgz cd $LAPACK_SRC

cp INSTALL/make.inc.LINUX make.inc # on LINUX

make lapacklib make clean

get atlas 3.6.0 from sourceforge

export BUILD_DIR=/home/phil/install export BLAS_SRC=$BUILD_DIR/blas export BLAS=$BLAS_SRC/libfblas.a export LAPACK=$BUILD_DIR/LAPACK export LAPACK_SRC=$LAPACK/SRC export ATLAS_SRC=$BUILD_DIR/ATLAS export ARCH=Linux_P4SSE2

Look at INSTALL.txt

make xconfig ./xconfig -F f “-fomit-frame-pointer -O -fno-second-underscore” -b $BLAS

Enter number at top left of screen [0]: 45 Have you scoped the errata file? [y]: <enter> use express setup? [y]: <enter> Enter Architecture name (ARCH) [Linux_P4SSE2]: <enter> Enter Maximum cache size (KB) [512]: <enter> Enter File creation delay in seconds [0]: <enter> Use supplied default values for install? [y]: <enter>

export ARCH=Linux_P4SSE2

make install arch=$ARCH make sanity_test arch=$ARCH

export ARCH=Linux_P4SSE2 ~/install/ATLAS phil@gull% make sanity_test arch=$ARCH You can find the following ATLAS libraries in ‘$ATLAS_SRC/lib/$ARCH’: libf77blas.a libcblas.a liblapack.a libatlas.a

libptf77blas.a libptcblas.a

complete liblapack.a following directions:

cd $ATLAS_SRC/lib/$ARCH cp liblapack.a liblapack_orig.a mkdir tmp; cd tmp ar x ../liblapack.a cp $LAPACK/lapack_LINUX.a ../liblapack.a ar r ../liblapack.a *.o cd ..; rm -rf tmp

libraries in

/home/phil/install/ATLAS/lib/Linux_P4SSE2

fftw installed on gull in /usr/local/lib/libfftw3*

svn co http://svn.scipy.org/svn/scipy_core/trunk core cd core rm -rf build python setup.py install

svn co http://svn.scipy.org/svn/scipy/trunk scipy cd ../scipy rm -rf build python setup.py install

Removing old scipy installation tree before executing the above commands is recommended.

cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/numpy login cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/numpy co -P Numerical

cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/numpy login cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/numpy co -P numarray python setup.py config install –gencode

Pearu

In addition to site-packages/matplotlib, we’ll also install

site-packages/pylab.py site-packages/pytz # iff it doesn’t already exist site-packages/dateutil # iff it doesn’t already exist site-packages/subprocess # iff it doesn’t already exist

From: Tom Loredo <loredo@astro.cornell.edu> Sender: scipy-user-bounces@scipy.net To: scipy-user@scipy.net Subject: Re: [SciPy-user] how to get matplotlib working with new scipy? Date: Fri, 2 Dec 2005 16:44:01 -0500 (EST)

cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/matplotlib co -P toolkits

Hi Sven,

I’m just starting with scipy_core, so I can’t address all your issues, but Travis just helped me regarding mpl compatibility, so I’ll pass on what he told me in case he hasn’t answered yet.

The issue of mpl compatibility was recently addressed on the scipy and mpl developer lists. A patch was checked in that enables you to use mpl with just scipy (no Numeric or numarray needed). You can’t just download the patches and patch mpl 0.85; the files that are patched have changed since the release. So you need to use the CVS version of mpl. Instructions for downloading it are at the CVS link on the mpl SourceForge page. Basically, just execute these two CVS commands:

This will create a “matplotlib” directory in your current directory with the current CVS check-in. Go in there and install mpl as usual. When you’re done, you’ll need to edit your matplotlibrc file, setting numerix to “scipy”. Then the few examples I just tried all work.

Cheers, Tom

From: Arnd Baecker <arnd.baecker@web.de> Sender: scipy-dev-bounces@scipy.net To: SciPy Developers List <scipy-dev@scipy.net> Subject: Re: [SciPy-dev] newcore on 64 bit systems Date: Wed, 9 Nov 2005 14:13:56 +0100 (CET)

Hi Nils,

On Wed, 9 Nov 2005, Nils Wagner wrote:

> I have also a problem with python setup.py install in newcore > > gcc options: ‘-pthread -fno-strict-aliasing -DNDEBUG -O2 > -fmessage-length=0 -Wall -g -fPIC’ > compile options: ‘-DNO_ATLAS_INFO=1 -Iscipy/base/include > -Ibuild/src/scipy/base -Iscipy/base/src -I/usr/include/python2.4 -c’ > /usr/bin/g77 -shared > build/temp.linux-x86_64-2.4/scipy/corelib/lapack_lite/lapack_litemodule.o > -L/usr/local/builds/src/blas -Lbuild/temp.linux-x86_64-2.4 -lflapack_src > -lfblas -lg2c -o build/lib.linux-x86_64-2.4/scipy/lib/lapack_lite.so > usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5../../../../x86_64-suse-linux/bin/ld: > /usr/local/builds/src/blas/libfblas.a(dgemm.o): relocation R_X86_64_32 > against `a local symbol’ can not be used when making a shared object; > recompile with -fPIC > /usr/local/builds/src/blas/libfblas.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5../../../../x86_64-suse-linux/bin/ld: > /usr/local/builds/src/blas/libfblas.a(dgemm.o): relocation R_X86_64_32 > against `a local symbol’ can not be used when making a shared object; > recompile with -fPIC > /usr/local/builds/src/blas/libfblas.a: could not read symbols: Bad value > collect2: ld returned 1 exit status > error: Command “/usr/bin/g77 -shared > build/temp.linux-x86_64-2.4/scipy/corelib/lapack_lite/lapack_litemodule.o > -L/usr/local/builds/src/blas -Lbuild/temp.linux-x86_64-2.4 -lflapack_src > -lfblas -lg2c -o build/lib.linux-x86_64-2.4/scipy/lib/lapack_lite.so” > failed with exit status 1 > removed scipy/base/__svn_version__.py > removed scipy/base/__svn_version__.pyc > removed scipy/f2py/__svn_version__.py > removed scipy/f2py/__svn_version__.pyc > > How can I fix these problems ? > > I strictly followed the instructions given at > http://www.scipy.org/documentation/buildatlas4scipy.txt > > Are there special instructions how to build newcore/newscipy on 64 bit > machines ?

This is a known problem on 64 Bit machines. http://www.scipy.org/mailinglists/mailman?fn=scipy-user/2005-February/004066.html http://www.scipy.net/pipermail/scipy-user/2005-September/005265.html

Below I post my complete notes on the installation of **old** scipy on 64 Bit. The only difference is that you want to use newscipy/newcore. Everything else should be the same (apart from fftw3, it seems that only fftw2 is supported in newscipy at the moment. Also no guarantee on performance for that one).

Note that the whole text is written in ReSt, so it should be no problem to use the text or fragments for the scipy wiki …

HTH, Arnd

Get the sources ===============

Create directories::

mkdir -p INSTALL_PYTHON/Sources cd INSTALL_PYTHON/Sources

`gcc http://gcc.gnu.org/`_::

wget ftp://ftp.gwdg.de/pub/misc/gcc/releases/gcc-3.4.4/gcc-3.4.4.tar.bz2

python and docu::

wget ftp://ftp.python.org/pub/python/2.4.2/Python-2.4.2.tar.bz2 wget http://www.python.org/ftp/python/doc/2.4.2/html-2.4.2.tar.bz2

Ipython via svn::

svn co http://ipython.scipy.org/svn/ipython/ipython/trunk ipython-trunk

zip -9r ipython ipython rm -rf ipython

Numeric::

(press <enter> for CVS password) cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/numpy login cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/numpy co -P Numerical zip -9r Numerical Numerical rm -rf Numerical

f2p2e::

(CVS password: guest) cvs -d :pserver:anonymous@cens.ioc.ee:/home/cvs login cvs -z6 -d :pserver:anonymous@cens.ioc.ee:/home/cvs checkout f2py2e zip -9r f2py2e f2py2e rm -rf f2py2e

`fftw http://www.fftw.org/`_::

wget http://www.fftw.org/fftw-3.0.1.tar.gz

`ATLAS http://math-atlas.sourceforge.net/_`::

wget http://cesnet.dl.sourceforge.net/sourceforge/math-atlas/atlas3.6.0.tar.bz2

**OLD** scipy svn::

svn co http://svn.scipy.org/svn/scipy/trunk scipy

cd scipy svn co http://svn.scipy.org/svn/scipy_core/trunk/ scipy_core

cd .. zip -9r scipy scipy rm -rf scipy

Directory “Sources“ =====================

After this we have::

2032724 atlas3.7.11.tar.bz2 520527 f2py2e.zip 1946361 fftw-3.0.1.tar.gz 27565872 gcc-3.4.4.tar.bz2 1395537 html-2.4.2.tar.bz2 953884 ipython.zip 796402 Numerical.zip 7853169 Python-2.4.2.tar.bz2 16783889 scipy.zip

Environment variables ======================

::

export PHOME=/scr/python/ export INFODIR=${PHOME}/info:$INFODIR export INFOPATH=${PHOME}/info:$INFOPATH export MANPATH=${PHOME}/man:$MANPATH export LD_LIBRARY_PATH=${PHOME}/lib64:${PHOME}/lib:$LD_LIBRARY_PATH export LD_RUN_PATH=${PHOME}/lib64:${PHOME}/lib:$LD_RUN_PATH

export PYTHONDOCS=${PHOME}/docs/Python-Docs-2.4.2/ export PATH=${PHOME}/bin:${PATH} export PAGER=”less -R”

export CFLAGS=-fPIC

For the installation::

cd .. mkdir CompileDir cd CompileDir

(this should be on the same level as “Sources“)

gcc ===

::

tar xjf ../Sources/gcc-3.4.4.tar.bz2 mkdir gcc-build cd gcc-build

../gcc-3.4.4/configure –prefix=${PHOME} –enable-shared –enable-threads=posix –enable-__cxa_atexit –enable-clocale=gnu –enable-languages=c,c++,f77,objc

make make install

cd ${PHOME}/bin/ ln -s gcc ${PHOME}/bin/cc cd -

Python ======

::

tar xjf ../Sources/Python-2.4.2.tar.bz2 cd Python-2.4.2 ./configure –prefix=${PHOME}

make make install

make test

255 tests OK. 35 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_bsddb3 test_cd test_cl test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_curses test_dl test_gl test_imageop test_imgfile test_linuxaudiodev test_macfs test_macostools test_nis test_normalization test_ossaudiodev test_pep277 test_plistlib test_rgbimg test_scriptpackages test_socket_ssl test_socketserver test_sunaudiodev test_timeout test_urllib2net test_urllibnet test_winreg test_winsound Those skips are all expected on linux2.

cd ..

IPython =======

::

unzip ../Sources/ipython.zip cd ipython python setup.py install cd .. rehash

xemacs -nw /scr/python/lib/python2.4/site-packages/IPython/UserConfig/ipythonrc

#colors Linux colors LightBG

confirm_exit 0

ATLAS and BLAS/LAPACK =====================

See: http://www.scipy.org/documentation/buildatlas4scipy.txt

BLAS ----

::

export BLAS_SRC=${HOME}/INSTALL_PYTHON/CompileDir/BLAS export LAPACK_SRC=${HOME}/INSTALL_PYTHON/CompileDir/LAPACK

mkdir -p $BLAS_SRC cd $BLAS_SRC wget http://www.netlib.org/blas/blas.tgz tar xzf blas.tgz

g77 -fno-second-underscore -O2 -fPIC -c *.f

ar r libfblas.a *.o ranlib libfblas.a rm -rf *.o

LAPACK


::

mkdir -p $LAPACK_SRC cd $LAPACK_SRC/.. wget http://www.netlib.org/lapack/lapack.tgz tar xzf lapack.tgz cd $LAPACK_SRC

cp INSTALL/make.inc.LINUX make.inc # on LINUX

Edit “make.inc“::

OPTS = -funroll-all-loops -O3 -m64 -fno-second-underscore -fPIC NOOPT = -m64 -fno-second-underscore -fPIC

and do::

make lapacklib

cd ..

ATLAS


Just follow::

export BLAS=$BLAS_SRC/libfblas.a

tar xjf ../Sources/atlas3.7.11.tar.bz2 cd ATLAS

make xconfig ./xconfig -F f “-fomit-frame-pointer -O -fno-second-underscore -fPIC” -F c ” -fomit-frame-pointer -O -mfpmath=387 -m64 -fPIC” -F m “-fomit-frame-pointer -O -mfpmath=387 -m64 -fPIC” -b $BLAS

Settings:

  • 64 Bit
  • Posix threads
  • don’t stop
  • use express setup? [y]:
  • Enter f77 compiler [g77]: Enter F77 Flags [-fomit-frame-pointer -O -m64]:
  • Tune the Level 1 BLAS? [y]:

Gives for the compile commands:: F77 = /scr/python3//bin/g77 -fomit-frame-pointer -O -fno-second-underscore -fPIC CC = /scr/python3//bin/gcc -fomit-frame-pointer -O -mfpmath=387 -m64 -fPIC MCC = /scr/python3//bin/gcc -fomit-frame-pointer -O -mfpmath=387 -m64 -fPIC

Have a couple of cups of coffee while doing::

make install arch=Linux_HAMMER64SSE3_2

make sanity_test arch=Linux_HAMMER64SSE3_2 make ptsanity_test arch=Linux_HAMMER64SSE3_2

Make optimized LAPACK library::

cd lib//Linux_HAMMER64SSE3_2/ mkdir tmp; cd tmp ar x ../liblapack.a cp ../liblapack.a ../liblapack.a_SAVE cp ../../../../LAPACK/lapack_LINUX.a ../liblapack.a ar r ../liblapack.a *.o cd ..; rm -rf tmp

ls -lh liblapack.a -rw-r–r– 1 abaecker users 11M 2005-10-04 17:32 liblapack.a

cp *.a $PHOME/lib64 cd ../../ cp include/{cblas.h,clapack.h} $PHOME/include cd ..

fftw ====

::

tar xzf ../Sources/fftw-3.0.1.tar.gz cd fftw-3.0.1/ ./configure CFLAGS=-fPIC –prefix=$PHOME make make install

Attempt with optimization::

./configure CFLAGS=”-fPIC -O3 -fomit-frame-pointer -fno-schedule-insns -fstrict-aliasing -mpreferred-stack-boundary=4” –prefix=$PHOME

boost


<file://///home/phil/NOTES/200311/031107#* install – boost v2 step by step – start here medusa/kite/gull>

install – matplotlib on fc3 libraries


Dec 10 07:51:39 Installed: glib2-devel.i386 2.4.8-1.fc3 Dec 10 08:10:56 Installed: freetype-devel.i386 2.1.9-1.2.1.fc3.rf Dec 10 08:11:00 Installed: fontconfig-devel.i386 2.2.3-5 Dec 10 08:11:17 Installed: xorg-x11-devel.i386 6.8.2-1.FC3.13 Dec 10 08:11:17 Installed: glib-devel.i386 1:1.2.10-15 Dec 10 08:11:20 Installed: gtk+-devel.i386 1:1.2.10-33 Dec 10 08:16:03 Installed: libjpeg-devel.i386 6b-33 Dec 10 08:16:05 Installed: libtiff-devel.i386 3.6.1-10.fc3 Dec 10 08:16:06 Installed: libungif-devel.i386 4.1.3-1 Dec 10 08:16:06 Installed: imlib-devel.i386 1:1.9.13-21 Dec 10 08:16:06 Installed: audiofile-devel.i386 1:0.2.6-1 Dec 10 08:16:10 Installed: alsa-lib-devel.i386 1.0.6-8.FC3 Dec 10 08:16:10 Installed: esound-devel.i386 1:0.2.35-2 Dec 10 08:16:11 Installed: libxml-devel.i386 1:1.8.17-12 Dec 10 08:16:12 Installed: ORBit-devel.i386 1:0.5.17-14 Dec 10 08:16:14 Installed: gnome-libs-devel.i386 1:1.4.1.2.90-44 Dec 10 08:16:14 Installed: libglade-devel.i386 1:0.17-15 Dec 10 08:19:12 Installed: pygtk2-devel.i386 2.4.1-fc3.1 Dec 10 08:20:25 Installed: pango-devel.i386 1.6.0-7 Dec 10 08:20:25 Installed: atk-devel.i386 1.8.0-2 Dec 10 08:20:32 Installed: gtk2-devel.i386 2.4.14-3.fc3 Dec 10 08:29:57 Installed: tcl-devel.i386 8.4.7-2 Dec 10 08:29:59 Installed: tk-devel.i386 8.4.7-2 Dec 10 08:36:24 Installed: libpng-devel.i386 2:1.2.8-1.fc3

python – hotshot profiling


From: arnd.baecker@web.de Sender: scipy-user-bounces@scipy.net To: SciPy Users List <scipy-user@scipy.net> Subject: Re: [SciPy-user] Benchmark data Date: Sat, 10 Dec 2005 15:13:42 +0100 (CET)

On Fri, 9 Dec 2005, Travis Oliphant wrote:

> I know people may be tired of the benchmark data,

In my opinion just the contrary - the more benchmark results we can get for scipy, the better!

What about setting up a `scipy.bench()` suite (similar to `scipy.test()` )? They could be collected as `bench_xxx.py` (and their level could determine how long the are expected to run).

For FFT, scipy.test already includes a speed comparison, but I would like to see more of this (Esssentially for all subpackages linalg, sparse, integrate, interpolate stats, random .... and in general for ufunc operations, scalar operations etc.). This would allow to compare the efficiency of different LAPACK variants, compiler settings, different compilers etc. etc.

I think it would be great if users could contribute simple benchmark examples of their area of interest.

> but I’m just trying to > understand what kinds of techniques produce fast code.

I very much appreciate that you take this issue so serious!!

[…]

> So, I’m not sure how to reproduce what Gerard sees (except numarray’s > faster arange) > which is a little perplexing. I suppose that’s why people criticize > benchmarks so much.

In the end it only counts, how fast a given code is executed. But there is no (easy?) way to find the optimal compile flags - the space spanned by all possible options is just too big. And varying the problem size can lead to different optimal values… The task is not made simpler by different compilers, different CPUs/Cache sizes, different distributions, different kernels, whatever else …

So I would not be surprised at all if gcc 4.x or Intels icc produce different results.

Just one remark on bench.py: it uses time.time(). So it does not determine the CPU time of a process. This could be determined with jiffies from scipy.test.testing import jiffies Another option might be timeit.py, see In [4]: import timeit In [5]: timeit? (worth reading!)

Some more remarks on profiling, which might be useful to other as well: Python code can be profiled using the `hotshot` module. Together with kcachegrind http://kcachegrind.sourceforge.net/ and Joerg Beyer’s script `hotshot2cachegrind.py` you can use a GUI to inspect the profiling results:

############ import hotshot

def run():

prof = hotshot.Profile(“pythongrind.prof”, lineevents=1) prof.runcall(run) prof.close() ############

  • this will generate the profiling results in “pythongrind.prof”
  • then use hotshot2cachegrind -o cachegrind.out.42 pythongrind.prof to convert
  • Start kcachegrind cachegrind.out.42 which will give a nice graphical interface to the profiling data

Remark: kcachegrind can also be used to display profilings of gcc code (However, I don’t think it is possible to descend from the python results to the C level of the called functions …)

Note that this is particularly helpful to find and analyze the main bottlenecks in a given code. So in the above case, where the speed of single operations is compared, I don’t think it will help much. (Also note, that it takes some time to understand the output; a couple of things still look mysterious to me ;-)…

Thanks for all your effort!

Best, Arnd

_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user

python – benchmark.py


#!/usr/bin/env python

import sys import time import itertools import math

import Numeric import numarray import scipy.base

pi = math.pi

def klein(NX, nu, nv, a): “”“Returns the figure-8 form of the Klein bottle u in [0, 2pi), v in [0, 2pi), and a > 2 http://mathworld.wolfram.com/KleinBottle.html “”” assert(nu > 2) assert(nv > 2) assert(a > 2) cos = NX.cos sin = NX.sin ticks = [time.time()] # label i = NX.arange(nu*nv) # 1 ticks.append(time.time()) u = i % nu # 2 ticks.append(time.time()) u %= nu-1 # 3 ticks.append(time.time()) u = 2*pi*u/(nu-1) # 4 ticks.append(time.time()) v = i / nu # 5 ticks.append(time.time()) v %= nv-1 # 6 ticks.append(time.time()) v = 2*pi*v/(nu-1) # 7 ticks.append(time.time()) xyzs = NX.zeros((nu*nv, 3), NX.Float) # 8 ticks.append(time.time()) xyzs[:,0] = (a+cos(u/2)*sin(v)-sin(u/2)*sin(2*v))*cos(u) # 9 ticks.append(time.time()) xyzs[:,1] = (a+cos(u/2)*sin(v)-sin(u/2)*sin(2*v))*sin(u) # 10 ticks.append(time.time()) xyzs[:,2] = sin(u/2)*sin(v)+cos(u/2)*sin(2*v) # 11 ticks.append(time.time()) return ticks

def print_ticks(tick_lists): Nmodules = len(tick_lists) Nticks = len(tick_lists[0][1]) names = [ a[0] for a in tick_lists ] ticks = [ a[1] for a in tick_lists ] tickfmt = ‘%15.4g’ * Nmodules print ‘label ’ + (‘%15s’*Nmodules) % tuple(names) for i in range(1, Nticks): t = tuple(tl[i]-tl[i-1] for tl in ticks) print ‘%5d %s’ % (i, tickfmt % t) print ‘TOTAL %s’ % (tickfmt % tuple(tl[-1]-tl[0] for tl in ticks))

def usage(): print ‘Usage: python numpy size’ print ‘where numpy must be Numeric, numarray, or scipy’ print ‘and size an integer in [3, 13)’ sys.exit(1)

if __name__ == ‘__main__’: if len(sys.argv) != 2: usage()

print ‘Numeric-%s’ % Numeric.__version__ print ‘numarray-%s’ % numarray.__version__ print ‘scipy-core-%s’ % scipy.core_version.version

try: size = int(sys.argv[1]) except: usage() if size < 3 or size >= 13: usage()

print ‘benchmark size = %s (vectors of length %d)’ % (size, 2**(2*size)) all_ticks = [] for name, NX in [(‘Numeric’, Numeric), (‘numarray’, numarray), (‘scipy.base’, scipy.base)]: ticks = klein(NX, 2**size, 2**size, pi) all_ticks.append((name, ticks)) print_ticks(all_ticks)

From: Travis Oliphant <oliphant.travis@ieee.org> Sender: scipy-user-bounces@scipy.net To: SciPy Users List <scipy-user@scipy.net> Subject: [SciPy-user] New name for Scipy Core is NumPy Date: Thu, 05 Jan 2006 03:39:05 -0700

There has been a fast-paced discussion on the scipy-dev list which resulted in the renaming of the scipy_core package to numpy in preparation for the 0.9. 2 (nearing stable 1.0 release).

You now need to get numpy out of svn:

svn co http://svn.scipy.org/svn/numpy/trunk numpy

and build it before building scipy (numpy replaces scipy_core)

Also, you must explicitly call scipy.pkgload() if you want to load the scipy namespace with the numpy names (and the scipy sub-package names). Otherwise, scipy acts more like a library (you have to explicitly import scipy.linalg)

This new packaging structure makes things much nicer for .eggs and should mean a more stable platform in the long run. The only big porting effort is to use replace scipy.base with numpy and/or

import scipy scipy.pkgload()

An actual release of numpy and scipy will follow.

Best regards,

-Travis

Commands to check out:

svn co http://svn.scipy.org/svn/numpy/trunk numpy svn co http://svn.scipy.org/svn/scipy/trunk scipy

then move site.cfg to numpy/disutils

> scipy.show_config()

__________________________ ~/install/numpy phil@gull% cat numpy/distutils/site.cfg #

#

#

[DEFAULT]

[atlas]

#library_dirs = /usr/lib/3dnow # Debian Sid library_dirs = /home/phil/install/ATLAS/lib/Linux_P4SSE2

[lapack] library_dirs = /home/phil/install/ATLAS/lib/Linux_P4SSE2

[lapack_src] src_dirs = /home/phil/install/LAPACK/SRC

[blas] library_dirs = /home/phil/install/ATLAS/lib/Linux_P4SSE2

[blas_src] src_dirs = /home/phil/install/blas

[fftw] library_dirs = /usr/local/lib fftw_libs = fftw3 fftw_opt_libs = fftw_threaded, rfftw_threaded

[x11]

#[lapack]

From: Robert Kern <robert.kern@gmail.com> Sender: scipy-user-bounces@scipy.org Reply-To: SciPy Users List <scipy-user@scipy.org> To: SciPy Users List <scipy-user@scipy.org> Subject: Re: [SciPy-user] SciPy finds wrong lapack Date: Tue, 02 Jan 2007 11:18:18 -0600

J Oishi wrote: > Thanks for the tip. I tried setting the search_static_first=true, but > the problem remains. > >> What is your site.cfg and where (and what) are the relevant >> libraries on your >> system? > my site.cfg (for both scipy and numpy) reads > > [DEFAULT] > search_static_first=true > [atlas] > atlas_libs = lapack,cblas, atlas, f77blas > > My atlas libs are in usr/local/lib/atlas, but the /usr/lib > liblapack.so.3 versions are the ones being linked into calc_lwork.so. > I think this might be related to the fact that > liblapack.so.3 => /usr/lib/liblapack.so.3 (0x0045a000) > libblas.so.3 => /usr/lib/libblas.so.3 (0x00111000) > are from my (possibly tainted) RedHat libraries, rather than from my > good ATLAS versions > /usr/local/lib/atlas/liblapack.a > /usr/local/lib/atlas/libcblas.a

Ah. Then you need to include that information in your site.cfg:

[atlas] atlas_libs = lapack, f77blas, cblas, atlas library_dirs = /usr/local/lib/atlas

Also, note the correction to the order of the libraries.

_________________

import numpy numpy.teset(10) numpy.show_config()

using databases gdbm


from whichdb import whichdb print whichdb(’home/phil.spambayes.db’)

http://tinyurl.com/h285p

random normal


If you can, please use the .rand() and .randn() methods on a RandomState object which you can initialize with whatever seed you like.

from numpy.random import RandomState as rn

In [1]: import numpy as np rs In [2]: rs = np.random.RandomState([12345678, 90123456, 78901234])

interpolate along an axis


import numpy as np def __midpoints_1d(a): “”“Return `a` linearly interpolated at the mid-points.”“” return (a[:-1] + a[1:])/2.

def midpoints(a, axis=None): “”“Return `a` linearly interpolated at the mid-points.

Parameters


a : array-like Input array. axis : int or None Axis along which the interpolation takes place. None stands for all axes.

Returns


out : ndarray Input array interpolated at the midpoints along the given axis.

Examples


>>> a = [1,2,3,4] >>> midpoints(a) array([1.5, 2.5, 3.5]) “”” x = np.asarray(a) if axis is not None: return np.apply_along_axis(__midpoints_1d, axis, x) else: for i in range(x.ndim): x = midpoints(x, i) return x

http://www.mail-archive.com/numpy-discussion@scipy.org/msg17699.html

numpy – scalar types array scalars


np.atleast_1d np.asarray np.ascontiguous

np.empty_like

On Fri, Jan 29, 2010 at 2:58 PM, David Huard <david.hu…@gmail.com> wrote: > For the record, here is what I came up with. > > import numpy as np > > def expand_ellipsis(index, ndim): > “”“Replace the ellipsis, real or implied, of an index expression by slices. > > Parameters > ---------- > index : tuple > Indexing expression. > ndim : int > Number of dimensions of the array the index applies to. > > Return > ------ > out : tuple > An indexing expression of length `ndim` where the Elipsis are replaced > by slices. > “”” > n = len(index) > index = index + ndim * (slice(None),) > > newindex = [] > for i in index: > try: > if i == Ellipsis: > newindex.extend((ndim - n + 1)*(slice(None),)) > else: > newindex.append(i) > except: > newindex.append(i) > > return newindex[:ndim] > > def indexedshape(shape, index): > “”“Return the shape of an array sliced by index. > > Parameters > ---------- > shape : tuple > Shape of the original array. > index : tuple > Indexing sequence. > > Return > ------ > out : tuple > If array A has shape `shape`, then out = A[index].shape. > > Example > ------- > >>> indexedshape((5,4,3,2), (Ellipsis, 0)) > (5,4,3) > >>> indexedshape((5,4,3,2), (slice(None, None, 2), 2, [1,2], > [True, False])) > “”” > index = expand_ellipsis(index, len(shape)) > out = [] > for s, i in zip(shape,index): > if type(i) == slice: > start, stop, stride = i.indices(s) > out.append(int(np.ceil((stop-start)*1./stride))) > elif np.isscalar(i): > pass > elif getattr(i, ‘dtype’, None) == np.bool: > out.append(i.sum()) > else: > out.append(len(i)) > > return tuple(out) > > > def test_indexedshape(): > from numpy.testing import assert_equal as eq > s = (6,5,4,3) > a = np.empty(s) > i = np.index_exp[::4, 3:, 0, np.array([True, False, True])] > eq(a[i].shape, indexedshape(s, i)) > > i = np.index_exp[1::4, 3:, np.array([0,1,2]), ::-1] > eq(a[i].shape, indexedshape(s, i)) > > i = (0,) > eq(a[i].shape, indexedshape(s, i)) > > i = (3, Ellipsis, 0) > eq(a[i].shape, indexedshape(s, i))

BTW: This will be very useful to understand slicing and indexing which is (for me) hidden in the c code.

A few more test cases

good:

>>> i = np.index_exp[np.array([0,1,2])[:,None], np.array([0,1]),:,:] >>> a[i].shape, indexedshape(s, i) ((3, 2, 4, 3), (3, 2, 4, 3))

these are the tricky ones but the ones that show the interaction between broadcasting and slices in more than 2 dimensions

>>> i = np.index_exp[np.array([0,1,2])[:,None], :, np.array([0,1])] >>> a[i].shape, indexedshape(s, i) ((3, 2, 5, 3), (3, 5, 2, 3)) >>> i = np.index_exp[np.array([0,1,2])[:,None], …, np.array([0,1])] >>> a[i].shape, indexedshape(s, i) ((3, 2, 5, 4), (3, 5, 4, 2))

Thanks,

Josef

> > On Fri, Jan 29, 2010 at 1:27 PM, <josef.p…@gmail.com> wrote: >> On Fri, Jan 29, 2010 at 1:03 PM, Keith Goodman <kwgood…@gmail.com> wrote: >>> On Fri, Jan 29, 2010 at 9:53 AM, <josef.p…@gmail.com> wrote: >>>> I forgot about ellipsis, since I never use them, >>>> replace ellipsis by [slice(None)]*ndim or something like this >>>> >>>> I don’t know how to access an ellipsis directly, is it even possible >>>> to construct an index list that contains an ellipsis? >>>> There is an object for it but I never looked at it. >>> >>> I haven’t been following the discussion and I don’t understand your >>> question and in a moment I will accidentally hit send… >>> >>>>> class eli(object): >>> …: >>> …: def __init__(self): >>> …: pass >>> …: >>> …: def __getitem__(self, index): >>> …: print index >>> …: >>> >>>>> x[…] >>> Ellipsis >>>>> x[…,1] >>> (Ellipsis, 1) >>> >>> Ellipsis is a python class. Built in, no need to import. >> >> thanks, this makes it possible to construct index lists with Ellipsis, >> but it showed that my broadcast idea doesn’t work this way >> >> Travis explained last year how slices and broadcasting are used for >> indexing, and it’s quite a bit more complicated than this. >> >> Sorry for jumping in too fast. >> >> Josef >> >>>>> indi= (slice(2,5),Ellipsis, np.arange(3)[:,None]) >>>>> ind2 = [] >>>>> for i in indi: >> if not i is Ellipsis: ind2.append(i) >> else: ind2.extend([slice(None)]*2) >> >> >>>>> ind2 >> [slice(2, 5, None), slice(None, None, None), slice(None, None, None), >> array([[0], >> [1], >> [2]])] >>>>> np.broadcast(*ind2).shape >> (3, 1)

http://projects.scipy.org/numpy/wiki/ZeroRankArray

From: Travis Oliphant <oliphant@ee.byu.edu> Sender: numpy-discussion-bounces@lists.sourceforge.net Reply-To: Discussion of Numerical Python <numpy-discussion@lists.sourceforge.net> To: Discussion of Numerical Python <numpy-discussion@lists.sourceforge.net> Subject: Re: [Numpy-discussion] Fastest way of distinguish a numpy scalar of a python scalar? Date: Tue, 03 Oct 2006 11:47:05 -0600

Sebastian Haase wrote:

>Hi, >a noticed the underscore in “numpy.string_” … >I thought the underscores were removed in favour of handling the >”from numpy import ” separately via the __all__ variable. >Is this done only for *some members of numpy ? > > Yeah. The underscores are still on the conflicting type names.

-Travis

From: Travis Oliphant <oliphant@ee.byu.edu> Sender: numpy-discussion-bounces@lists.sourceforge.net Reply-To: Discussion of Numerical Python <numpy-discussion@lists.sourceforge.net> To: Discussion of Numerical Python <numpy-discussion@lists.sourceforge.net> Subject: Re: [Numpy-discussion] Fastest way of distinguish a numpy scalar of a python scalar? Date: Tue, 03 Oct 2006 11:47:55 -0600

Tim Hochberg wrote:

>Francesc Altet wrote: > > >>Hi, >> >>I thought that numpy.isscalar was a good way of distinguising a numpy scalar >>from a python scalar, but it seems not: >> >> >> >> >>>>>numpy.isscalar(numpy.string_(‘3’)) >>>>> >>>>> >>>>> >>True >> >> >> >>>>>numpy.isscalar(‘3’) >>>>> >>>>> >>>>> >>True >> >>Is there an easy (and fast, if possible) way to check whether an object is a >>numpy scalar or a python one? >> >> >> >> >It looks like isinstance(x, numpy.generic) works, but I didn’t test it >extensively. > > > That should definitely work. All the array scalars are in a hierarchy inheriting from numpy.generic. There are also sub-levels (numpy.integer, numpy.inexact, etc…)

import numpy print numpy.typeDict.keys() print numpy.sctypeDict.keys() allTypes=numpy.typeDict.values() for aType in allTypes: try: print str(aType.dtype) instance=aType(0) print “here is instance: “,instance,instance.itemsize,instance.dtype.name except: print ‘%s failed’ % str(aType)

for aType in numpy.ScalarType: try: anItem=aType(0) print anItem.dtype.name,anItem.dtype.char except: print “++++++++++ failed with: “,aType

From: Travis Oliphant <oliphant.travis <at> ieee.org> Subject: Re: attributes of scalar types - e.g. numpy.int32.itemsize Newsgroups: gmane.comp.python.numeric.general Date: 2006-08-18 23:51:35 GMT (6 weeks, 2 days, 23 hours and 21 minutes ago)

Sebastian Haase wrote: > On Friday 18 August 2006 15:25, Travis Oliphant wrote: > >> Sebastian Haase wrote: >> >>> On Friday 18 August 2006 11:38, Travis Oliphant wrote: >>> >>>> Sebastian Haase wrote: >>>> >>>>> Hi, >>>>> array dtype descriptors have an attribute itemsize that gives the >>>>> total number of bytes required for an item of that dtype. >>>>> >>>>> Scalar types, like numy.int32, also have that attribute, >>>>> but it returns “something else” - don’t know what: >>>>> >>>>> >>>>> Furthermore there are lot’s of more attributes to a scalar dtype, >>>>> e.g. >>>>> >>>> The scalar types are actual Python types (classes) whereas the dtype >>>> objects are instances. >>>> >>>> The attributes you are seeing of the typeobject are very useful when you >>>> have an instance of that type. >>>> >>>> With numpy.int32.itemsize you are doing the equivalent of >>>> numpy.dtype.itemsize >>>> >>> but why then do I not get the result 4 ? >>> >> Because it’s not a “class” attribute, it’s an instance attribute. >> >> What does numpy.dtype.itemsize give you? >> >> > I’m really sorry for being so dumb - but HOW can I get then the number of > bytes needed by a given scalar type ? > > Ah, the real question. Sorry for not catching it earlier. I’ve been in “make sure this isn’t a bug mode” for a long time.

If you have a scalar type you could create one and then check the itemsize:

int32(0).itemsize

Or you could look at the name and parse out how big it is.

There is also a stored dictionary-like object that returns the number of bytes for any data-type recognized:

numpy.nbytes[int32]

-Travis

From: Travis Oliphant <oliphant.travis <at> ieee.org> Subject: Re: help! type ‘float64scalar’ is not type ‘float’ Newsgroups: gmane.comp.python.numeric.general Date: 2006-08-03 05:43:48 GMT (8 weeks, 4 days, 17 hours and 35 minutes ago)

Sebastian Haase wrote: > Thanks, > I just found > numpy.isscalar() and numpy.issctype() ? > These sound like they would do what I need - what is the difference > between the two ? > Oh, yeah.

numpy.issctype works with type objects numpy.isscalar works with instances

Neither of them distinguish between scalars and “numbers.”

If you get errors with isscalar it would be nice to know what they are.

-Travis

From: Travis Oliphant <oliphant <at> ee.byu.edu> Subject: Re: help! type ‘float64scalar’ is not type ‘float’ Newsgroups: gmane.comp.python.numeric.general Date: 2006-08-03 20:37:33 GMT (8 weeks, 4 days, 2 hours and 43 minutes ago)

Sebastian Haase wrote: >On Wednesday 02 August 2006 22:43, Travis Oliphant wrote: >>Sebastian Haase wrote: >>>Thanks, >>>I just found >>>numpy.isscalar() and numpy.issctype() ? >>>These sound like they would do what I need - what is the difference >>>between the two ? >> >>Oh, yeah. >> >>numpy.issctype works with type objects >>numpy.isscalar works with instances >> >>Neither of them distinguish between scalars and “numbers.” >> >>If you get errors with isscalar it would be nice to know what they are. > >I’m still trying to reproduce the exception, but here is a first comparison >that - honestly - does not make much sense to me: >(type vs. instance seems to get mostly the same results and why is there a >difference with a string (‘12’) )

These routines are a little buggy. I’ve cleaned them up in SVN to reflect what they should do. When the dtype object came into existence a lot of what the scalar types where being used for was no longer needed. Some of these functions weren’t updated to deal with the dtype objects correctly either.

This is what you get now: >>> import numpy as N >>> N.isscalar(12)

True

>>> N.issctype(12)

False

>>> N.isscalar(‘12’)

True

>>> N.issctype(‘12’)

False

>>> N.isscalar(N.array([1]))

False

>>> N.issctype(N.array([1]))

False

>>> N.isscalar(N.array([1]).dtype)

False

>>> N.issctype(N.array([1]).dtype)

True

>>> N.isscalar(N.array([1])[0].dtype)

False

>>> N.issctype(N.array([1])[0].dtype)

True

>>> N.isscalar(N.array([1])[0])

True

>>> N.issctype(N.array([1])[0])

False

-Travis

>>>>N.isscalar(12) > >True > >>>>N.issctype(12) > >True > >>>>N.isscalar(‘12’) > >True > >>>>N.issctype(‘12’) > >False > >>>>N.isscalar(N.array([1])) > >False > >>>>N.issctype(N.array([1])) > >True > >>>>N.isscalar(N.array([1]).dtype) > >False > >>>>N.issctype(N.array([1]).dtype) > >False > > # apparently new ‘scalars’ have a dtype attribute ! > >>>>N.isscalar(N.array([1])[0].dtype) > >False > >>>>N.issctype(N.array([1])[0].dtype) > >False > >>>>N.isscalar(N.array([1])[0]) > >True > >>>>N.issctype(N.array([1])[0]) > >True > >-Sebastian

From: Travis Oliphant <oliphant.travis <at> ieee.org> Subject: Re: More about data types in NumPy Newsgroups: gmane.comp.python.numeric.general Date: 2006-09-27 16:35:51 GMT (5 days, 6 hours and 46 minutes ago)

Francesc Altet wrote: > Hello, > > Sorry for being insistent, but I recognize that I’m having a bad time > with NumPy data type rational. Is there an explanation for this?: > > >>>> numpy.dtype(‘i4’).type >>>> > <type ‘numpy.int32’> > >>>> numpy.dtype(‘int32’).type >>>> > <type ‘numpy.int32’> > >>>> numpy.dtype(‘i4’).type == numpy.dtype(‘int32’).type >>>> > True > > So far so good, but is the next the intended behaviour? > > >>>> numpy.typeDict[‘i4’] >>>> > <type ‘numpy.int32’> > >>>> numpy.typeDict[‘int32’] >>>> > <type ‘numpy.int32’> > >>>> numpy.typeDict[‘i4’] == numpy.typeDict[‘int32’] >>>> No, this isn’t correct behavior. This time you’ve caught an actual problem :-)

The typeDict (actually the sctypeDict — scalar-type-dictionary returns a scalar type given a string not a data-type object) is only used if no other conversion can be found for the object. It used to be much more useful before the data-type objects were formalized last year.

-Travis

From: Sebastian Haase <haase <at> msg.ucsf.edu> Subject: numpy scalar types Newsgroups: gmane.comp.python.numeric.general Date: 2006-07-25 05:09:37 GMT (1 week, 1 day, 23 hours and 42 minutes ago)

Hi, I just ran a simple test which I think would be of general interest. It’s about types and what there names are in the numpy module (and how many different names there are for a given type !!) Cheers, Sebastian Haase (maybe there is a good place in the wiki for this !?) >>> N.csingle <type ‘complex64scalar’> >>> N.cdouble <type ‘complex128scalar’> >>> N.cfloat <type ‘complex128scalar’>

and all together !! >>> for tt in N.ScalarType: … l=[k for k,v in N.__dict__.iteritems() if v == tt] … print len(l), tt, l … 0 <type ‘int’> [] 0 <type ‘float’> [] 0 <type ‘complex’> [] 0 <type ‘long’> [] 0 <type ‘bool’> [] 0 <type ‘str’> [] 0 <type ‘unicode’> [] 0 <type ‘buffer’> [] 2 <type ‘int64scalar’> [‘longlong’, ‘int64’] 2 <type ‘int16scalar’> [‘int16’, ‘short’] 2 <type ‘int32scalar’> [‘int32’, ‘int_’] 2 <type ‘uint32scalar’> [‘uint’, ‘uint32’] 2 <type ‘unicodescalar’> [‘unicode_’, ‘unicode0’] 2 <type ‘complex64scalar’> [‘complex64’, ‘csingle’] 3 <type ‘int32scalar’> [‘intp’, ‘intc’, ‘int0’] 4 <type ‘complex128scalar’> [‘cfloat’, ‘complex_’, ‘cdouble’, ‘complex128’] 3 <type ‘stringscalar’> [‘string’, ‘str_’, ‘string0’] 3 <type ‘float96scalar’> [‘float96’, ‘longfloat’, ‘longdouble’] 2 <type ‘uint16scalar’> [‘ushort’, ‘uint16’] 2 <type ‘objectscalar’> [‘object0’, ‘object_’] 3 <type ‘float64scalar’> [‘double’, ‘float64’, ‘float_’] 2 <type ‘int8scalar’> [‘byte’, ‘int8’] 2 <type ‘uint8scalar’> [‘uint8’, ‘ubyte’] 2 <type ‘boolscalar’> [‘bool8’, ‘bool_’] 2 <type ‘float32scalar’> [‘float32’, ‘single’] 3 <type ‘complex192scalar’> [‘complex192’, ‘clongdouble’, ‘clongfloat’] 3 <type ‘uint32scalar’> [‘uintc’, ‘uint0’, ‘uintp’] 2 <type ‘uint64scalar’> [‘uint64’, ‘ulonglong’] 2 <type ‘voidscalar’> [‘void’, ‘void0’]

import numpy print numpy.typeDict.keys() print numpy.sctypeDict.keys() allTypes=numpy.typeDict.values() for aType in allTypes: try: print str(aType.dtype) except: print ‘%s failed’ % str(aType)

new library for num_util


/home/phil/philprojects/pythonlibs/num_util works with owl using makesimple

scipy fft routines


From: “Glen W. Mabey” <Glen.Mabey@swri.org> Sender: matplotlib-users-bounces@lists.sourceforge.net To: matplotlib Mailing list <matplotlib-users@lists.sourceforge.net> Subject: Re: [Matplotlib-users] [Numpy-discussion] which fft I should use Date: Mon, 1 Jan 2007 09:32:02 -0600

On Wed, Dec 27, 2006 at 12:58:24PM -0500, Robert Kern wrote: > Gennan Chen wrote: > > Hi! all, > > > > There are so many fft routines in Scipy/Numpy. Does anyone know > > which one should be used officially? > > For maximum portability and speed, use numpy.dual.fft() and its friends. That > will use the optimized functions in scipy.fftpack if it is available and > numpy.fft otherwise.

This was seen on numpy-discussion. Is this the behavior implemented in matplotlib/numerix/fft/__init__.py ?

Doesn’t look like it to me …

Glen

install – current site.cfg


#

#

#

[DEFAULT]

[atlas]

#library_dirs = /usr/lib/3dnow # Debian Sid library_dirs = /raid/datatmp/phil/install/ATLAS/lib/Linux_P4SSE2

[lapack] library_dirs = /raid/datatmp/phil/install/ATLAS/lib/Linux_P4SSE2

[lapack_src] src_dirs = /raid/datatmp/phil/install/LAPACK/SRC

[blas] library_dirs = /raid/datatmp/phil/install/ATLAS/lib/Linux_P4SSE2

[blas_src] src_dirs = /raid/datatmp/phil/install/blas

[fftw] library_dirs = /home/phil/lib/fftw3_thrush/lib fftw_libs = fftw3 #fftw_opt_libs = fftw_threaded, rfftw_threaded

[netcdf] library_dirs = /nfs/kite/common/netcdf-3.6.1/lib include_dirs = /nfs/kite/common/netcdf-3.6.1/include

[x11]

#[lapack]

netcdf examples


from netCDF4 import Dataset ncfilename=’BOMEX_128x128x64_50m_3s.nc’ theFile=Dataset(ncfilename,’r’,’NETCDF3_CLASSIC’) theFile.variables.keys()

numpy idioms


mask = (a<0) a[mask] = numpy.random.normal(0, 1, size=mask.sum())

> > The method is not described in the numpy book, and the docstring says > it is a method of mtrand.RandomState, which is an object. I deduce from > this that the module initialises one single object of this type on > import, which is used by every call to generate a random number, for any > distribution? Is this a right deduction?

The “functions” in numpy.random are just aliases to the methods on the global instance. They are there only for convenience when you don’t need real control over the stream and for backwards compatibility with Numeric’s RandomArray which only had global state.

The preferred way is to make your own instance of RandomState and call methods off of it. You should only use numpy.random.seed() if you need to work around other code which uses the global instance (which, unfortunately, is much of scipy.stats).

hdf4 install


export F77=gfortran export FC=gfortran export CFLAGS=’-fPIC’ export CCFLAGS=’-fPIC’

install bison and flex

shared (hdf4 won’t build shared fortran libs): ./configure –prefix=/home/phil/usr64/libhdf4_25_gfortran –enable-shared –disable-fortran

./configure –includedir=/home/phil/usr_owl/include/hdf –prefix=/home/phil/usr_owl –enable-shared –disable-fortran

static ./configure –prefix=/home/phil/usr64/libhdf4_25_gfortran_static

pytables install


tern:

export LD_RUN_PATH=/home/phil/usr64_nc4/lib python setup.py install –hdf5=/home/phil/usr64_nc4

python –matplotlib plotting template


import numpy as npy from pylab import figure, close, show fig = figure() ax = fig.add_subplot(111) x = npy.arange(0,10.) ax.plot(x) show()

python – complete example of package with tests


/////home/phil/philprojects/pythonlibs/multivariate_normal

generating random numbers


from numpy.random import RandomState as rn #initialize the generator theRandomGen=rn([0102030303]) #get 1000 uniformly distributed random variables between #0 and 1 theVars=theRandomGen.uniform(0,1,1000) theVars=theRandomGen.uniform(0.2,1,(100,10))

import numpy as np rs=np.random.RandomState([12345678, 90123456, 78901234])

RandomState(seed=None): initializes the PRNG with the given seed. See the seed() method for details.

seed can be an integer, an array (or other sequence) of integers of any length, or None. If seed is None, then RandomState will try to read data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise.

rs.uniform(size=[2,3,4])

np.argsort(out, axis=None) Out[39]: array([11, 0, 15, 5, 10, 3, 23, 7, 2, 17, 12, 20, 4, 1, 19, 6, 16, 8, 9, 21, 14, 22, 13, 18])

last axis:

In [41]:np.argsort(out, axis=2) Out[41]: array([[[0, 3, 2, 1], [1, 3, 0, 2], [3, 2, 0, 1]],

[[3, 0, 2, 1], [1, 3, 0, 2], [3, 0, 1, 2]]])

In [42]:np.argsort(out, axis=-1) Out[42]: array([[[0, 3, 2, 1], [1, 3, 0, 2], [3, 2, 0, 1]],

[[3, 0, 2, 1], [1, 3, 0, 2], [3, 0, 1, 2]]])

matplotlib – batch printing


from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure from matplotlib.patches import Rectangle fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.plot([.5,.7],[1.5, 2.5]) ax.add_artist(Rectangle((.5, 1.5), .2, 1, fill=False)) ax.set_aspect(“equal”) canvas.print_figure(‘test.eps’)

From: John Hunter <jdhunter@nitace.bsd.uchicago.edu> Sender: matplotlib-users-admin@lists.sourceforge.net To: Christian Seberino <seberino@spawar.navy.mil> Cc: matplotlib-users@lists.sourceforge.net Subject: Re: [Matplotlib-users] How/why creating Figure object changes defaults of plot? Date: Wed, 04 Jan 2006 19:42:39 -0600

>>>>> “Christian” == Christian Seberino <seberino@spawar.navy.mil> writes:

Christian> I’ve notice that if I (1) create a plot vs. e.g. Christian> plot([1,2,3])

Christian> (2) explicitly add a plot to a Figure object

Christian> e.g. fig = Figure() p = fig.add_subplot(111) Christian> plot([1,2,3])

Christian> it looks DIFFERENT?!?

Not sure what your problem is: please post complete examples. But it looks like you are improperly mixing pylab and the OO API. If you want to use a minimal set of pylab and use OO matplotlib for every thing else, I recommend

import matplotlib.numerix as nx from pylab import figure, show, close

The first command lets pylab handle figure management, the most complex part, and the second gives you access to the numpy namespace

Here is the equivalent of the canonical pylab :

plot([1,2,3[)

using a more pythonic style:

from pylab import figure, show, close fig = figure() ax = fig.add_subplot(111) ax.plot([1,2,3]) show()

Note in your example:

fig = Figure() p = fig.add_subplot(111) plot([1,2,3])

You used fig.add_subplot to create an Axes, which you named “p”, but then did not use it. You would have wanted something like

p.plot([1,2,3])

JDH

python – matplotlib line cycler


From: Fernando Perez <fperez.net@…> Subject: Re: setting the default line style order Newsgroups: gmane.comp.python.matplotlib.general Date: 2007-02-23 09:29:16 GMT (17 weeks, 5 days, 15 hours and 57 minutes ago)

On 2/23/07, Fernando Perez <fperez.net@…> wrote: > On 2/23/07, Jouni K. Sepp�nen <jks@…> wrote: > > Brian Blais <bblais@…> writes: > > > > > Is there a way to specify the default order of line colors and > > > styles, for plot commands given in sequence > > > > I don’t think there is built-in support for this. See e.g. > > http://thread.gmane.org/gmane.comp.python.matplotlib.general/5708 > > for some previous discussion and suggestions. > > It’s probably worth mentioning that the cyclers John mentions are > trivial to write using itertools:

Sorry, tab put me in the ‘send’ button in gmail too early… I meant:

import itertools

colorcycler = itertools.cycle([‘blue’,’green’,’red’,’magenta’,’cyan’]).next linecycler = itertools.cycle([ ‘-‘,’–’, ‘-.’ , ‘:’ ]).next n = itertools.count().next

y = array([1,2,3])

for i in range(10): plot(y+n(),color=colorcycler(),linestyle=linecycler())

On 6/27/07, Ryan Krauss <ryanlists@gmail.com> wrote: > I think what you are asking is how to make mpl plot different line > types in colors and styles that are easily distinguishable when > plotted in grayscale. I had tinkered with this a bit in the past and > the final suggestion was to write some helper functions so that I > could do the following: > > from mycyclers import colorcycler, linecycler > > for data in mydata: > ax.plot(data, linestyle=linecycler(), color=colorcycler()) > > so that by writing a linecycler function I could control the line > types plotted each time and the same with the color. Color would be > specified as a grayscale such as ‘#808080’ for a medium gray or > ‘#000000’ for black. > > I didn’t actually do it this way or I would post the code (I was in a > hurry and did something hackish). I think that linecycler and > colorcycler would be helper classes thta increment there own internal > count when called and return a linestyle or color. > > I think what you want in the end is a simple way to do this: > > t=arange(0,1,0.01) > y=sin(2*pi*t) > x=cos(2*pi*t) > plot(t,x,color=’#000000’,linestyle=’-‘) > plot(t,y,color=’#808080’,linestyle=’:’) > > where color and line style would increment pseudo-automatically > through lists you have defined and that you like. > > A slightly better approach might be: > t=arange(0,1,0.01) > y=sin(2*pi*t) > x=cos(2*pi*t) > data=[x,y] > mycolors=[‘#000000’,’#808080’] > mytypes=[‘-‘,’:’] > > def grayscaleplot(data,t): > for n,item in enumerate(data): > plot(t,item, color=mycolors[n], linestyle=mytypes[n]) > > FWIW,

current installation


`ATLAS http://math-atlas.sourceforge.net/_`:: http://www.netlib.org/lapack/

build – current


From: Phil Austin <phaustin <at> gmail.com> Subject: Re: Building numpy/scipy on RHEL5 OR CentOS5 Newsgroups: gmane.comp.python.scientific.devel Date: 2008-06-23 16:50:37 GMT (16 weeks, 5 days, 1 hour and 31 minutes ago)

Michael Hearne wrote: > I’ve been wrestling with installing scipy (in any form - binary, source, > egg, rpm) on some RHEL5 machines that I am compelled to work with, and > have failed miserably. I noticed a thread a few months back about > building scipy on CentOS 5, and noticed that at least one of the > respondents indicated he’d had success. As I understand it, CentOS > strives for binary compatibility with RHEL, so I’m hopeful that CentOS > solutions will work for me. >

I do this pretty regularly with numpy/scipy/matplotlib from svn for Centos 5.1 on x86_64. I build ATLAS and lapack from scratch but use the fftw3 rpms

~ phil <at> owl% rpm -qa | grep fftw3 fftw3-3.1.1-1.el5.rf fftw3-devel-3.1.1-1.el5.rf

The major problem I encountered compared to earlier builds with Mandrake was the fact that ‘fPIC’ needs to be explicitly passed to every fortran, C and C++ compiler call. There is a bug in the lapack makefile, for example, that drops ‘fPIC’ from 4 lapack compile statements (out of hundreds) and these have to recompiled by hand (See step 3 below).

The following is a cut and paste from a fairly disorganized set of notes.

  1. build python

export CPPFLAGS=’-fPIC’ export CFLAGS=’-fPIC’ export FFLAGS=’-fPIC’

./configure –prefix=/users/user-soft/usr251_Centos

make install

  1. build ATLAS

#turn off throttling sudo /usr/bin/cpufreq-selector -g performance

mkdir my_build cd my_build /home/datatmp/phil/install/ATLAS/mybuild phil <at> owl% \ ../configure –prefix=/home/phil/usr251_Centos \ –cflags=’-fPIC’ -Fa alg -fPIC

make make install

  1. build LAPACK

for lapack: cp INSTALL/make.inc.LINUX ~/install/lapack-3.1.1/make.inc and edit:

FORTRAN = gfortran OPTS = -funroll-all-loops -O3 -fPIC DRVOPTS = $(OPTS) NOOPT = -fPIC LOADER = gfortran LOADOPTS = -fPIC

BLASLIB = /home/phil/usr64/lib/libf77blas.a /home/phil/usr64/lib/libatlas.a LAPACKLIB = lapack$(PLAT).a TMGLIB = tmglib$(PLAT).a EIGSRCLIB = eigsrc$(PLAT).a LINSRCLIB = linsrc$(PLAT).a

this should no longer be needed:

!!and then rebuild these individual routines with fPIC – recompile!

~/install/transport/lapack-3.1.1/SRC gfortran -fPIC -c slaruv.f -o slaruv.o gfortran -fPIC -c dlaruv.f -o dlaruv.o

~/install/transport/lapack-3.1.1/INSTALL

gfortran -fPIC -c slamch.f -o slamch.o gfortran -fPIC -c dlamch.f -o dlamch.o gfortran -fPIC -o testieee tstiee.o

make liblapack make libblas then make all – to build vanilla blas and testing make lapack_install – to get statistics

Now merge ATLAS and lapack:

cd /home/datatmp/phil/install/ATLAS/mybuild/lib

cp liblapack.a liblapack_orig.a mkdir tmp; cd tmp ar x ../liblapack.a cp ~/install/transport/lapack-3.1.1/lapack_LINUX.a ../liblapack.a ar r ../liblapack.a *.o cd ..; rm -rf tmp cp liblapack.a home/phil/usr251_Centos/lib

the edit numpy site.cfg and add the library locations:

[atlas]

#library_dirs = /usr/lib/3dnow # Debian Sid library_dirs = /home/phil/usr251_Centos/lib

[lapack] library_dirs = /home/phil/usr251_Centos/lib

[lapack_src] src_dirs = /home/phil/install/transport/lapack-3.1.1/SRC

[blas] library_dirs = /home/phil/usr251_Centos/lib

[blas_src] src_dirs = /home/datatmp/phil/install/ATLAS/src/blas

[fftw3] library_dirs = usr/lib64 fftw_libs = fftw3 #fftw_opt_libs = fftw_threaded, rfftw_threaded

  1. build numpy

rm build and do

python setup.py clean

python setup.py build –fcompiler=gfortran python setup.py install

make sure

~/install/numpy-trunk/numpy/distutils/site.cfg has been copied to

/home/phil/usr251_Centos/lib/python2.5/site-packages\ /numpy/distutils/site.cfg

easy_install nose

>>> numpy.test(‘full’)

  1. build scipy

#don’t use octaves umfpack ~/install/scipy-trunk phil@tern% export UMFPACK=”None” python setup.py build –fcompiler=gfortran python setup.py install

  1. build geos

export F77=gfortran export GEOS_DIR=/home/phil/usr64

~/install/matplotlib-trunk/toolkits/basemap/geos-2.2.3 phil@tern% ./configure –prefix=$GEOS_DIR

Phil Austin wrote: > 3) build LAPACK > > for lapack: cp INSTALL/make.inc.LINUX ~/install/lapack-3.1.1/make.inc > and edit: > > FORTRAN = gfortran > OPTS = -funroll-all-loops -O3 -fPIC > DRVOPTS = $(OPTS) &gt; NOOPT = &gt; LOADER = gfortran &gt; LOADOPTS = &gt; &gt; BLASLIB = /home/phil/usr251_Centos/lib/libcblas.a &gt; LAPACKLIB = lapack$(PLAT).a > TMGLIB = tmglib$(PLAT).a > EIGSRCLIB = eigsrc$(PLAT).a > LINSRCLIB = linsrc$(PLAT).a > > !!and then rebuild these individual routines with fPIC – recompile! >

You should put -fPIC to NOOPT and LOADOPTS instead: this will be more reliable, as this way, -fPIC will be used for every source file

cheers,

David

csv2rec – reading column data for csv files


import matplotlib.mlab as mlab trythis=mlab.csv2rec(‘ARM2X_SCM15F_RH.dat’,delimiter=’ ‘,names=[‘col1’,’col2’,’col3’]) theTimes=trythis[‘col1’] thePresLevs=trythis[‘col2’] theVals=trythis[‘col3’] #160 time steps theTimes=theTimes.reshape((160,-1)) thePresLevs=thePresLevs.reshape((160,-1)) theVals=theVals.reshape((160,-1)) #take only 35 pressure levels theTimes=theTimes[:,:35] thePresLevs=thePresLevs[:,:35] theVals=theVals[:,:35]

csv2rec – reading lists of lists


assign3=mlab.csv2rec(‘assign3.csv’,delimiter=’;’,checkrows=30)

psnorm=ps[‘mark’]/totScore listOfLists.append(psnorm.tolist())

matplotlib random sample


rs=np.random.RandomState([12345678, 90123456, 78901234]) rs.uniform(size=[2,3,4])

matplotlib adjusting figure size

http://www.scipy.org/Cookbook/Matplotlib/AdjustingImageSize

#!/usr/bin/env python “”” This is a small demo file that helps teach how to adjust figure sizes for matplotlib

”””

import matplotlib print “using MPL version:”, matplotlib.__version__ matplotlib.use(“WXAgg”) # do this before pylab so you don’tget the default back end.

import pylab import matplotlib.numerix as N

x = N.arange(0, 2*N.pi, 0.1) y = N.sin(x)

pylab.plot(x,y) F = pylab.gcf()

DPI = F.get_dpi() print “DPI:”, DPI DefaultSize = F.get_size_inches() print “Default size in Inches”, DefaultSize print “Which should result in a %i x %i Image”%(DPI*DefaultSize[0], DPI*DefaultSize[1])

F.savefig(“test1.png”)

F.set_size_inches( (DefaultSize[0]*2, DefaultSize[1]*2) ) Size = F.get_size_inches() print “Size in Inches”, Size F.savefig(“test2.png”)

F.set_size_inches( DefaultSize )# resetthe size Size = F.get_size_inches() print “Size in Inches”, Size F.savefig(“test3.png”, dpi = (200)) # change the dpi

On Dec 8, 2008, at 1:09 AM, Roy H. Han wrote:

> I figured it out. > Specifically, I need to use pylab.Axes(figure, [left, bottom, width, > height]) where each value in the frame is between 0 and 1 > [.2,.1,.7,.8] > means > 20 percent margin on left > 10 percent margin on bottom > 10 percent margin on right (1 - .2 - .7) > 10 percent margin on top (1 - .1 - .8)

Yep, you got it. Now, you can also use the simpler `pyplot.subplots_adjust` as a function, or as a method for your figure. That way, you’re not tied to defining the positions at the creation of your subplot.

reading binary files using memmap:


import numpy as np theTime = np.memmap(‘t.bin’, dtype=np.float32, offset=0,shape=(180,), order=’C’) theHeight=np.memmap(‘z.bin’, dtype=np.float32, offset=0,shape=(180,), order=’C’) for i in theHeight[:128]: print “%8.3f” % i

animation example for matplotlib


from pylab import * from scipy import *

fig=figure(1) theAx=gca() theAx.set_title(‘here is a title’) theAx.set_ylabel(‘here is a y label’) theAx.set_xlabel(‘here is a x label’) img = standard_normal((40,40)) image = imshow(img,interpolation=’nearest’,animated=True,label=”blah”) show()

for k in range(1,10000): print k img = standard_normal((40,40)) image.set_data(img) fig.canvas.draw()

interpolation


scipy.interpolate.UnivariateSpline

>>> import numpy >>> import scipy >>> import scipy.interpolate >>> >>> x = numpy.arange(10,dtype=’float32’) * 0.3 >>> y = numpy.cos(x) >>> >>> sp = scipy.interpolate.UnivariateSpline(x,y) >>> sp(0.5) # should be a good approximation of cos(0.5)=0.8775 array([ 0.88198072])

record array examples


<file:////Users/phil/repos/readmes/Readme_scipy.nm#* working with structured arrays and recarrays>

sorting a record array


data = np.genfromtxt(filename, dtype=None, usecols=(0,1,2), names=’year,month,day’) data.sort(order=[‘year’, ‘month’, ‘day’])

see my new sorting code at

~/repos/ubcplot/newfigs.py for how to use a sort function

using f2py


f2py -c -m fib3 fib3.f ///~/repos/CliMT-0.6.5/src/thermodyn/Driver.f90

for annotated code

wrapping us standard atmosphere with f2py


use the f2py wrappers at

///~/repos/CliMT-0.6.5/src/thermodyn/Driver.f90

flatau code which contains mcclatchey ////users/phil/repos/pythonlibs/thermo/thermos.f

subsetted this: ////users/phil/repos/pythonlibs/thermo/mcclatchey.f

f2py –fcompiler=gfortran -c -m mcclatchey mcclatchey.f

call with: z,p,t,rvden,o3den,den = mcclatchey.mccla(‘midwinter’,np)

f2py documentation:

http://www.scipy.org/F2py

http://cens.ioc.ee/projects/f2py2e/

documentation format using sphinx


<file:///~/public_html/readmes/Readme_python.nm#* using sphinx>

sorting and rsyncing pages


this uses key to sort on thickness ///~/repos/ubcplot/newfigs.py

this produces the pickle file used by the sort ///~/repos/atsc405_zming/plot_profile.py

plotting with mayavi


////users/jdawe/MOVIES/BOMEX/CLOUD_FIELD/make_cloud_field.py

////home/jdawe/MOVIES/BOMEX/CLUSTER_OUTPUT_CDF/output_cdf.py

os.system( “”“mencoder “mf://png/fig_*.png” -mf fps=15 -o avi/cloud_field.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=2000”“” )

/users/jdawe/MOVIES phil@roc% cat /users/jdawe/MOVIES/BOMEX/mayavi.bash #!/bin/bash Xvfb :1 -screen 0 1280x1024x24 &

/users/jdawe/MOVIES phil@roc% rpm -qf /usr/bin/Xvfb xorg-x11-server-Xvfb-1.1.1-48.41.el5_2.1

/home/jdawe/MOVIES/BOMEX/CLUSTER_OUTPUT_CDF/output_cdf.py

set file_out=x2.avi set fps=24 set obr=1200 set opt=”mbd=2:keyint=132:cmp=2:subcmp=2:dia=2:mv0:last_pred=3” set codec=”msmpeg4v2”

http://lists.mplayerhq.hu/pipermail/mencoder-users/2005-December/002410.html:

mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=1200:vpass=1:mbd=2:keyint=132:cmp=2:subcmp=2:dia=2:mv0:last_pred=3:turbo -nosound -mf fps=24:type=png -o /dev/null mf://*.png mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=1200:vpass=2:mbd=2:keyint=132:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 -nosound -mf fps=24:type=png -o x2.avi mf://*.png

checking for atlas and lapack


from numpy.core import _dotblas

python >>import numpy >>numpy.test() #this should run with no errors (skipped tests and known-fails are ok) >>a = numpy.random.randn(6000, 6000) >>numpy.dot(a, a) # look at your cpu monitor and verify all cpu >>cores are at 100% if you built with threads

>>> np.show_config() atlas_threads_info: libraries = [‘lapack’, ‘ptf77blas’, ‘ptcblas’, ‘atlas’] library_dirs = [‘/users/user-soft/usr251_Centos/lib’] language = f77 include_dirs = [‘/users/user-soft/usr251_Centos/include’]

blas_opt_info: libraries = [‘ptf77blas’, ‘ptcblas’, ‘atlas’] library_dirs = [‘/users/user-soft/usr251_Centos/lib’] define_macros = [(‘ATLAS_INFO’, ‘”\”3.8.0\”“’)] language = c include_dirs = [‘/users/user-soft/usr251_Centos/include’]

atlas_blas_threads_info: libraries = [‘ptf77blas’, ‘ptcblas’, ‘atlas’] library_dirs = [‘/users/user-soft/usr251_Centos/lib’] language = c include_dirs = [‘/users/user-soft/usr251_Centos/include’]

lapack_opt_info: libraries = [‘lapack’, ‘ptf77blas’, ‘ptcblas’, ‘atlas’] library_dirs = [‘/users/user-soft/usr251_Centos/lib’] define_macros = [(‘ATLAS_INFO’, ‘”\”3.8.0\”“’)] language = f77 include_dirs = [‘/users/user-soft/usr251_Centos/include’]

lapack_mkl_info: NOT AVAILABLE

blas_mkl_info: NOT AVAILABLE

mkl_info: NOT AVAILABLE

qt designer and sql alchemy


http://www.stat.washington.edu/~hoytak/blog/bestlibraries.html

odeint cookbook example


http://www.scipy.org/Cookbook/Theoretical_Ecology/Hastings_and_Powell

matplotlib – object oriented plotting


#07/11/2009 04:41 AM

import matplotlib.use(‘Agg’) import matplotlib.pyplot as plt fig = plt.figure() fig.canvas # use thie canvas (it is FIgureCanvasAgg) rather than #creating your own

Or you can use the API and manually create your own figure and canvas (this is recommended since you have maximum control over object management)::

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111)

matplotlib – plotting to a string


#07/08/2009 12:35 PM

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure import cStringIO

def plot(…): fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111)

… … canvas.draw() imgdata = cStringIO.StringIO() canvas.print_png(imgdata) return imgdata.get_value()

testing for iterable (matplotlib.cbook)


/users/user-soft/usr251_Centos/lib/python2.5/site-packages/matplotlib/cbook.py

def iterable(obj): ‘return true if obj is iterable’ try: len(obj) except: return False return True

fitting distributions


For CDF you can use cumsum function (standard approach), but for smaller number of data points I prefer to use all the points, which is a neat trick:

from scipy import *

def my_cdf(x): bins = sort(x) cdf = linspace(0,1,len(bins)) return [bins, cdf]

On Mon, Jul 20, 2009 at 15:11, Omer Khalid<Omer.Khalid@cern.ch> wrote: > > Hi Ivo, > > > > Thanks for your reply. But I am getting a little confused here now. It seems > > there are multiple ways to get the CDF for a distribution. You mean linspace > > function returns a CDF for a normal distribution.

No, not at all. linspace() returns uniformly increasing numbers between the given endpoints. Ivo showed you how to find the empirical CDF of the dataset. It is not related to any particular family of probability distributions.

> > As far as I understood from other sources is that scipy.stats.norm.cdf > > (mean, std) will return the CDF for the normal distribution or for > > non-normal distribution given one replace norm with the distributions > > name.

Yes.

> > And what about scipy.stats.<dist>.fit function?

It will find the maximum likelihood parameters for fitting the given distribution to your dataset. These parameters can be then used the the <dist> object to return the fitted CDF, PDF, etc. The .fit() method is not very flexible, though.

numpy views


> > I have a simple question: How can I detect whether two arrays share the same > > data?

np.may_share_memory

splitting a line


Stéfan van der Walt wrote: > You cannot use view on an array scalar, so you’ll have to convert to > an array first: > > x = x.reshape((1,)) > x.view(‘S1’)

Bingo!

Thanks, Stéfan.

I don’t know why one can’t uwe view on a scalar – there is still a dat pointer isn’t there?, and it can be reshaped. Butno matter, now I have a one liner that splits a string up into fixed fields, and returns a float array of the numbers in those fields:

np.array((line,)).view(dtype=’S%i’%field_len).astype(np.float)

#!/usr/bin/env python

import numpy as np

def line2array1(line, field_len): nums = [] i = 0 while i < len(line): nums.append(float(line[i:i+field_len])) i += field_len return np.array(nums)

def line2array2(line, field_len): return np.array(map(float, [line[i*field_len:(i+1)*field_len] for i in range(len(line)/field_len)]))

def line2array3(line, field_len): return np.array(tuple(line), dtype = ‘S1’).view(dtype=’S%i’%field_len).astype(np.float)

def line2array4(line, field_len): return np.array((line,)).view(dtype=’S%i’%field_len).astype(np.float)

lines = [” 1.000000E+00 0.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00”, “-1.000000E+00-1.000000E+00-1.000000E+00-1.000000E+00 1.250000E+00 1.250000E+00”, ]

for line in lines: print line2array1(line, field_len=13)

for line in lines: print line2array2(line, field_len=13)

for line in lines: print line2array3(line, field_len=13)

for line in lines: print line2array4(line, field_len=13)

multivariate gaussian plus sphinx example


http://projects.scipy.org/scikits/browser/trunk/learn/scikits/learn/machine/em/densities.py

embedding ipython


save this to test.py and do

python test.py

from IPython.Shell import IPShellEmbed from IPython.ipstruct import Struct myconfig = Struct() myconfig.confirm_exit=0 ipshell=IPShellEmbed(rc_override=myconfig) ipshell()

making movies


Xue – here is a new two-pass command to mencoder that makes avi files that work with windows media player to turn a directory of png files into bomex.avi – go ahead and use this one from now on and forget about gifcicle

#pass 1 mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=1200:vpass=1:mbd=2:keyint=132:cmp=2:subcmp=2:dia=2:mv0:last_pred=3:turbo -nosound -mf fps=24:type=png -o /dev/null mf://*.png

#pass 2 mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=1200:vpass=2:mbd=2:keyint=132:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 -nosound -mf fps=24:type=png -o bomex.avi mf://*.png

#this works with windows but not mac mencoder -mc 0 -noskip -skiplimit 0 -ovc lavc -lavcopts vcodec=msmpeg4v2:vhq “mf://*.png” -mf type=png:fps=18 -o output.avi

#this won’t work with windows media player #http://matplotlib.sourceforge.net/examples/animation/movie_demo.html mencoder mf://*.png -mf type=png:w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o outputmplt.avi

#this won’t work with windows media player mencoder -mc 0 -noskip -skiplimit 0 -ovc lavc -lavcopts \ vcodec=mpeg4:vhq:trell:mbd=2:vmax_b_frames=1:v4mv:vb_strategy=0:vlelim=0:vcelim=0:cmp=6:subcmp=6:precmp=6:predia=3:dia=3:vme=4:vqscale=1 \ “mf://*.png” -mf type=png:fps=18 -o output.avi

#works http://pymolwiki.org/index.php/Making_Movies #mencoder -mc 0 -noskip -skiplimit 0 -ovc lavc -lavcopts vcodec=msmpeg4v2:vhq “mf://*.png” -mf type=png:fps=6 -o output.avi

but

h264enc -2p -p qt

fails

h264enc

http://ubuntuforums.org/showthread.php?p=9868359#post9868359 http://showmedo.com/videotutorials/video?name=1820010&fromSeriesID=182

http://article.gmane.org/gmane.comp.python.matplotlib.general/19384/match=mencoder From: Phil Austin <paustin@…> Subject: Re: making quicktime animations from linux – summary Newsgroups: gmane.comp.python.matplotlib.general Date: 2009-09-04 21:56:26 GMT (1 year, 21 weeks, 23 hours and 20 minutes ago)

Thanks for all the suggestions, for future reference here’s a summary of my results producing various kinds of quicktime compatible videos from matplotlib. I used Ubuntu Jaunty and had the medibuntu codecs installed. The target audience is undergraduates, so straightforward is good.

Executive summary: either MOV or mjpeg work with quicktime 7.6.2 as-is. Ogg-vorbis is the compression winner, so requiring that students install vlc is another option for large animations.

  1. MOV

ffmpeg -r 60 -i plot%05d.png -vcodec libx264 -b 2000k out.mov

http://clouds.eos.ubc.ca/~phil/video/samples/out.mov size: 0.9 Mbytes note: works with my (patient) colleague’s stock QT 7.6.2

  1. FLV

ffmpeg -r 60 -i shum%05d.png -vcodec libx264 -b 2000k out.flv

http://clouds.eos.ubc.ca/~phil/video/samples/out.flv size: 0.9 Mbytes note: Safari tried to open this as a text file

  1. WMV2:

ffmpeg -r 60 -i shum%05d.png -vcodec wmv2 -b 2000k out.avi http://clouds.eos.ubc.ca/~phil/video/samples/out.avi size: 1.1 Mbytes note: no luck getting quicktime to recognize this, even after we installed the codecs from

http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx

  1. jpeg:

mencoder -nosound -ovc lavc \ -lavcopts vbitrate=5000:vcodec=mjpeg \ -mf type=png:fps=15 -o moviejpeg.avi mf://\*.png -v http://clouds.eos.ubc.ca/~phil/video/samples/moviejpeg.avi size: 5.7 Mbytes note: works, although not svelt

  1. ogv

ffmpeg2theora –nosound –optimize –width 800 –height 600 –inputfps=15 –aspect 4:3 shum%05d.png -o movie.ogv

http://clouds.eos.ubc.ca/~phil/video/samples/movie.ogv size: 0.33 Mbytes (!) note: we followed the install instructions at http://www.theora.org/downloads/ but Safari didn’t recognize the ogv suffix, and didn’t offer to associate it with a player


Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what’s new with Crystal Reports now. http://p.sf.net/sfu/bobj-july

working with structured arrays and recarrays


numpy.rec.fromrecords

fromarrays http://www.scipy.org/Numpy_Example_List#head-fb08ac5f2a5d8da114940b8d0d9d1155443f2336

In [48]:theLayer.integrated.shape Out[48]:(20, 4)

In [49]:out=np.rec.fromarrays(theLayer.integrated.T,names=(‘time’,’theta’,’height’,’deltheta’))

In [50]:out.dtype Out[50]:dtype([(‘time’, ‘<f8’), (‘theta’, ‘<f8’), (‘height’, ‘<f8’), (‘deltheta’, ‘<f8’)])

In [51]:type(out) Out[51]:<class ‘numpy.core.records.recarray’>

In [52]:test=np.asarray(out)

In [53]:type(test) Out[53]:<type ‘numpy.ndarray’>

In [54]:test=np.asanyarray(out)

In [55]:type test ------->type(test) Out[55]:<class ‘numpy.core.records.recarray’>

now got he other way:

converting from record arrays to numpy arrays:

In [134]:test=np.frombuffer(out.data) In [136]:test.shape=(20,4)

perez code to manipulate recarrays

July 30, 2009 Subject: [xpyx] [Numpy-discussion] Reductions and binary ops on recarrays… ///~/lib/python/recarrutil.py

matplotlib – custom formatter


Jae-Joon Lee wrote: > > Use pylab’s yticks command. > > > > http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.yticks > > > > Or Axes.set_yticklabels together with Axes.set_yticks. > > > > http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_yticklabels > > > > -JJ

Or a make a very simple custom Formatter:

import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import ScalarFormatter

class PositiveFormatter(ScalarFormatter): def pprint_val(self, x): return ScalarFormatter.pprint_val(self, np.abs(x))

x = np.arange(0,20,0.1) y = 100 * np.sin(x) plt.plot(x, y) ax = plt.gca() ax.yaxis.set_major_formatter(PositiveFormatter()) plt.show()

This is a much safer way to handle it than trying to modify tick labels directly.

matplotlib – putting image on graph


A snippet of code does not help in general. Please take your time to create a simple, standalone code that reproduces your problem and post that code in this mailing list so that we can easily test.

Here is the code, based on yours, that works for me.

im = Image.open(“icon.jpg”)

ax = gca() limx = ax.get_xlim() limy = ax.get_ylim() ax.set_autoscale_on(False)

[x0, y0], [x1, y1] = ax.bbox.get_points()

datawidth = limx[1] - limx[0] dataheight = limy[1] - limy[0] pixelwidth = x1 - x0 pixelheight = y1 - y0 adaptedwidth = im.size[0] * (datawidth/pixelwidth) adaptedheight = im.size[1] * (dataheight/pixelheight)

ax.imshow(im, origin=”lower”, extent=(0.5, 0.5+adaptedwidth, 0.5, 0.5+adaptedheight))

plt.draw()

matplotlib – animate a tk widget


from collections import deque import math import Tkinter as tk import numpy as np

import matplotlib as mpl mpl.use(‘TkAgg’) from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg #from matplotlib.figure import Figure

#x = np.arange(0,2*np.pi,0.01) def mk_data(ct=[0]): ct[0] = 1 return 5 math.sqrt(ct[0])*np.sin(ct[0]/10.0)

class TSPlot(FigureCanvasTkAgg): “”“Provides a simple time-series plot of the most recent and previous 100 observations, where `datafunc` returns a single new observation. “”” def __init__(self, datafunc, master=None, title=”, **kwargs): xlength = 101 self._title = title self._datafunc = datafunc self._background = None self._line = None self._ylim = (0,1) self._xlim = (-100,0) self._ydata = deque() #Python 3 range object not sliceable self._xdata = [x+1-xlength for x in range(xlength)] self.fig = mpl.figure.Figure(figsize=(5,2.5), dpi=100) self._ax = self.fig.add_subplot(111) FigureCanvasTkAgg.__init__(self, self.fig, master=master) #grid to master self.get_tk_widget().grid(row=0,column=0, columnspan=2) self.update_line_cnt = 0 def setup(self):

new_ydata = self.update_data() self.adjust_ylim(new_ydata) self.set_background() def adjust_ylim(self, datum): “”“Return bool. Resets `_ylim` (if needed to accommodate `_ydata`). “”” ylow, yhigh = self._ylim adjust = False if not (ylow < datum < yhigh): maxy = max(self._ydata) miny = min(self._ydata) yhigh = maxy + 0.5 * (maxy-miny) ylow = miny - 0.5 * (maxy-miny) if yhigh == ylow: yhigh += 1 ylow -= 1 adjust = True self._ylim = ylow, yhigh return adjust def update(self, *args): “”“Return None. Update the line plot.”“”

newdata = self.update_data() ydata = self._ydata xdata = self._xdata if len(ydata) < len(xdata): xdata = xdata[-len(ydata):]

self.restore_region(self._background) self.line.set_data([xdata,ydata])

self._ax.draw_artist(self.line)

self.blit(self._ax.bbox) def update_data(self): “”“Return number, the new value from `_datafunc`. “”” new_ydata = self._datafunc() self._ydata.append(new_ydata) if self.adjust_ylim(new_ydata): self.set_background() return new_ydata def set_background(self): “”“Return None. Resets the background of the canvas. “”” ax = self._ax ax.clear() ydata = self._ydata xdata = self._xdata[-len(ydata):] self.line, = ax.plot(xdata, ydata, animated=True) ax.set_title(self._title, fontsize=’small’) ax.set_xlim(self._xlim) ax.set_ylim(self._ylim) self.show() #save the background (everything but the animated line)

self._background = self.copy_from_bbox(ax.bbox) def run(self): for i in range(500): self.update()

root = tk.Tk() myapp = TSPlot(mk_data, master=root) #myapp.grid(row=0, column=0, columnspan=2) btn = tk.Button(master=root, command=myapp.setup, text=”SetUp”) btn.grid(row=1, column=0) btn = tk.Button(master=root, command=myapp.run, text=”Run”) btn.grid(row=1, column=1)

root.mainloop()

numpy reshape and squeeze – axis tricks


test=np.zeros([5,4,3,1,1]) out=test.reshape(-1)

In [9]:out.shape Out[9]:(60,)

In [17]:new=out.squeeze()

In [18]:new.shape Out[18]:(5, 4, 3)

In [23]:test=out.reshape(-1,1)

In [24]:test.shape Out[24]:(60, 1)

appending to a recarray


specifying indices


n Sat, Aug 8, 2009 at 8:54 PM, Neil Martinsen-Burrell<nmb@wartburg.edu> wrote: > > > > The ellipsis is a built-in python constant called Ellipsis. The colon > > is a slice object, again a python built-in, called with None as an > > argument. So, z[…,2,:] == z[Ellipsis,2,slice(None)]. > >

There is also numpy.s_:

inds = np.s_[…,2,:] z[inds]

(Though there are some problems with negative indices: see for example http://www.mail-archive.com/numpy-discussion@scipy.org/msg18245.html)

On 8 Aug 2009, at 10:02 PM, T J wrote:

matplotlib – setting tick formatting for N values with MaxNLocator


http://matplotlib.sourceforge.net/api/ticker_api.html#matplotlib.ticker.MaxNLocator

nose testing – scripts from fperez


#!/usr/bin/env python from __future__ import with_statement “”“Minimal test script to check for modules needed in scipy tutorials.

Execute this code at the command line by typing:

python adv_tut_checklist.py

If it does NOT say ‘OK’ at the end, copy the entire output of the run and send it to the course instructor for help.

Note: it NEEDS nose to run at all, so if you don’t have nose, it will fail completely to even start. “””

import glob import os import platform import shutil import sys import tempfile

from StringIO import StringIO from textwrap import dedent

import nose import nose.tools as nt

##############################################################################

#-----------------------------------------------------------------------------

def sys_info(): “”“Summarize some info about the system”“”

print ‘==================’ print ‘System information’ print ‘==================’ print ‘os.name :’,os.name try: print ‘os.uname :’,os.uname() except:

pass print ‘platform :’,sys.platform print ‘platform+ :’,platform.platform() print ‘prefix :’,sys.prefix print ‘exec_prefix :’,sys.exec_prefix print ‘executable :’,sys.executable print ‘version_info :’,sys.version_info print ‘version :’,sys.version print ‘==================’

def c(cmd): “”“Run system command, raise SystemExit if it returns an error.”“” print “$”,cmd stat = os.system(cmd) #stat = 0 # Uncomment this and comment previous to run in debug mode if stat: raise SystemExit(“Command %s failed with code: %s” % (cmd, stat))

def validate_mpl(m): “”“Called if matplotlib imports. Sets backend for further examples.”“” m.use(‘Agg’)

m.rcParams[‘figure.subplot.top’] = 0.85

def validate_cython(cython): “”“Called if Cython imports, does further version checks.”“” from Cython.Compiler.Version import version

min_version = (0, 11, 2) cython_version = tuple([int(x) for x in version.split(‘.’)]) msg = “Cython version %s found, at least %s required” % (cython_version, min_version) nt.assert_true(cython_version >= min_version, msg)

def validate_sympy(sympy): if sys.version.find(‘EPD_Py25 4.3.0’) != -1: pass min_version = ‘0.6.4’ version = sympy.__version__ msg = “Sympy version %s, at least %s required” % (version, min_version)

if version < min_version: raise ValueError(msg)

#-----------------------------------------------------------------------------

def check_import(mnames, validator=None): “”“Check that the given module name can be imported.

If more than one name is given, all but the last are allowed to raise exceptions which are ignored. Basically, this means that any of the names is considered to satisfy the group, and we only report an error if they all fail to import.

A validator is a function that will be called with the imported module object if the import succeeds. It can either do extra tests on the module (such as version checks) or simply configure it. “””

if isinstance(mnames, basestring): exec “import %s as m” % mnames else: group, last = mnames[:-1], mnames[-1] for mname in group: try: exec “import %s as m” % mname except: pass else: break # We exit on first success else:

exec “import %s as m” % last

if validator is not None: validator(m)

for vname in [‘__version__’, ‘version’, ‘Version’]: try: vinfo = eval(“m.%s” % vname) break except AttributeError: pass else: vinfo = ’no info’ print ‘MOD: %s, version: %s’ % (m.__name__,vinfo)

def test_imports(): modules = [‘setuptools’, ‘IPython’, ‘numpy’,’scipy’,’scipy.io’, ‘matplotlib’,’pylab’, ‘enthought.mayavi.api’,

‘scipy.weave’, ‘sympy’, ‘Cython’, ‘Cython.Distutils.build_ext’, ‘enthought.traits.api’, ‘enthought.traits.ui.api’, (‘enthought.traits.ui.wx’,’enthought.traits.ui.qt4’), ]

validators = dict(matplotlib = validate_mpl, sympy = validate_sympy)

for mname in modules: yield (check_import, mname, validators.get(mname))

def test_weave(): “Simple code compilation and execution via scipy’s weave” from scipy import weave

weave.inline(‘int x=1;x++;’)

n,m = 1,2 code=”“” int m=%s; return_val=m+n; “”” % m val = weave.inline(code,[‘n’]) nt.assert_equal(val,m+n)

def test_cython(): “”“Test basic Cython sanity”“”

validate_cython(None)

setup_code = dedent(“”” from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext import numpy as np

setup( name=’Test of proper Cython installation’, cmdclass={‘build_ext’: build_ext}, ext_modules=[ Extension(“cython_check”, [“cython_check.pyx”], include_dirs=[np.get_include()])]) “”“)

cython_code = dedent(“”” cimport cython cimport numpy as np import numpy as np

@cython.wraparound(True) # only present in Cython 0.11.2+ def func(): cdef np.ndarray[np.int_t] arr = np.arange(2000, 2100, dtype=np.int) return “Hello at SciPy %d” % arr[9] “”“)

csetup_fname = ‘cython_setup.py’ cython_fname = ‘cython_check.pyx’ with open(csetup_fname,’w’) as f: f.write(setup_code) with open(cython_fname,’w’) as f: f.write(cython_code)

c(‘python cython_setup.py build_ext –inplace’) import cython_check result = cython_check.func() nt.assert_equal(“Hello at SciPy 2009”, result)

def test_loadtxt(): import numpy as np import numpy.testing as npt

array = np.array

c = StringIO(“0 1\n2 3”) a1 = np.loadtxt(c) a2 = np.array([[ 0., 1.], [ 2., 3.]]) yield npt.assert_array_equal,a1,a2

d = StringIO(“M 21 72\nF 35 58”) a1 = np.loadtxt(d, dtype={‘names’: (‘gender’, ‘age’, ‘weight’), ‘formats’: (‘S1’, ‘i4’, ‘f4’)})

a2 = np.array([(‘M’, 21, 72.0), (‘F’, 35, 58.0)], dtype=[(‘gender’, ‘|S1’), (‘age’, ‘<i4’), (‘weight’, ‘<f4’)]) yield npt.assert_array_equal,a1,a2

c = StringIO(“1,0,2\n3,0,4”) x,y = np.loadtxt(c, delimiter=’,’, usecols=(0,2), unpack=True) yield npt.assert_array_equal,x,np.array([ 1., 3.]) yield npt.assert_array_equal,y,np.array([ 2., 4.])

def test_plot(): “Simple plot generation.” from matplotlib import pyplot as plt plt.figure() plt.plot([1,2,3]) plt.xlabel(‘some numbers’) plt.savefig(‘tmp_test_plot.png’)

def test_plot_math(): “Plots with math” from matplotlib import pyplot as plt plt.figure() plt.plot([1,2,3],label=’data’) t=(r’And X is $∑i=0^∞ γ_i + \frac{αi^2}{γ}’ r’+ cos(2 θ^2)$’) plt.title(t) plt.legend() plt.grid() plt.savefig(‘tmp_test_plot_math.png’)

def main(): “”“Main routine, executed when this file is run as a script “””

global TESTDIR cwd = os.getcwd() TESTDIR = tempfile.mkdtemp(prefix=’tmp-testdata-‘,dir=cwd)

print “Running tests:”

try: os.chdir(TESTDIR) nose.runmodule(argv=[__file__,’-vvs’,’-x’], # ,’–pdb’], exit=False) finally: os.chdir(cwd)

print print “Cleanup - removing temp directory:”, TESTDIR

shutil.rmtree(TESTDIR)

print “”” *************************************************************************** TESTS FINISHED ***************************************************************************

If the printout above did not finish in ‘OK’ but instead says ‘FAILED’, copy and send the entire output, including the system information below, for help. We’ll do our best to assist you. You can send your message to the Scipy user mailing list:

http://mail.scipy.org/mailman/listinfo/scipy-user

but feel free to also CC directly: Fernando.Perez@berkeley.edu “”” sys_info()

#----------------------------------------------------------------------------- if __name__ == ‘__main__’: main()

SciPy-User] Sanity checklist for those attending the SciPy’09 tutorials ------------- another example 08/09/2009 02:12 AM subject #!/usr/bin/env python from __future__ import with_statement “”“Minimal test script to check for modules needed in scipy tutorials.

Execute this code at the command line by typing:

python intro_tut_checklist.py

If it does NOT say ‘OK’ at the end, copy the entire output of the run and send it to the course instructor for help.

Note: it NEEDS nose to run at all, so if you don’t have nose, it will fail completely to even start. “””

import glob import os import platform import shutil import sys import tempfile

from StringIO import StringIO from textwrap import dedent

import nose import nose.tools as nt

##############################################################################

#-----------------------------------------------------------------------------

def sys_info(): “”“Summarize some info about the system”“”

print ‘==================’ print ‘System information’ print ‘==================’ print ‘os.name :’,os.name try: print ‘os.uname :’,os.uname() except:

pass print ‘platform :’,sys.platform print ‘platform+ :’,platform.platform() print ‘prefix :’,sys.prefix print ‘exec_prefix :’,sys.exec_prefix print ‘executable :’,sys.executable print ‘version_info :’,sys.version_info print ‘version :’,sys.version print ‘==================’

def c(cmd): “”“Run system command, raise SystemExit if it returns an error.”“” print “$”,cmd stat = os.system(cmd) #stat = 0 # Uncomment this and comment previous to run in debug mode if stat: raise SystemExit(“Command %s failed with code: %s” % (cmd, stat))

def validate_mpl(m): “”“Called if matplotlib imports. Sets backend for further examples.”“” m.use(‘Agg’)

m.rcParams[‘figure.subplot.top’] = 0.85

#-----------------------------------------------------------------------------

def check_import(mnames, validator=None): “”“Check that the given module name can be imported.

If more than one name is given, all but the last are allowed to raise exceptions which are ignored. Basically, this means that any of the names is considered to satisfy the group, and we only report an error if they all fail to import.

A validator is a function that will be called with the imported module object if the import succeeds. It can either do extra tests on the module (such as version checks) or simply configure it. “””

if isinstance(mnames, basestring): exec “import %s as m” % mnames else: group, last = mnames[:-1], mnames[-1] for mname in group: try: exec “import %s as m” % mname except: pass else: break # We exit on first success else:

exec “import %s as m” % last

if validator is not None: validator(m)

for vname in [‘__version__’, ‘version’, ‘Version’]: try: vinfo = eval(“m.%s” % vname) break except AttributeError: pass else: vinfo = ’no info’ print ‘MOD: %s, version: %s’ % (m.__name__,vinfo)

def test_imports(): modules = [‘setuptools’, ‘IPython’, ‘numpy’,’scipy’,’scipy.io’, ‘matplotlib’,’pylab’, ‘enthought.mayavi.api’, ]

validators = dict(matplotlib = validate_mpl)

for mname in modules: yield (check_import, mname, validators.get(mname))

def test_loadtxt(): import numpy as np import numpy.testing as npt

array = np.array

c = StringIO(“0 1\n2 3”) a1 = np.loadtxt(c) a2 = np.array([[ 0., 1.], [ 2., 3.]]) yield npt.assert_array_equal,a1,a2

d = StringIO(“M 21 72\nF 35 58”) a1 = np.loadtxt(d, dtype={‘names’: (‘gender’, ‘age’, ‘weight’), ‘formats’: (‘S1’, ‘i4’, ‘f4’)})

a2 = np.array([(‘M’, 21, 72.0), (‘F’, 35, 58.0)], dtype=[(‘gender’, ‘|S1’), (‘age’, ‘<i4’), (‘weight’, ‘<f4’)]) yield npt.assert_array_equal,a1,a2

c = StringIO(“1,0,2\n3,0,4”) x,y = np.loadtxt(c, delimiter=’,’, usecols=(0,2), unpack=True) yield npt.assert_array_equal,x,np.array([ 1., 3.]) yield npt.assert_array_equal,y,np.array([ 2., 4.])

def test_plot(): “Simple plot generation.” from matplotlib import pyplot as plt plt.figure() plt.plot([1,2,3]) plt.xlabel(‘some numbers’) plt.savefig(‘tmp_test_plot.png’)

def test_plot_math(): “Plots with math” from matplotlib import pyplot as plt plt.figure() plt.plot([1,2,3],label=’data’) t=(r’And X is $∑i=0^∞ γ_i + \frac{αi^2}{γ}’ r’+ cos(2 θ^2)$’) plt.title(t) plt.legend(numpoints=1) #remove double points plt.grid() plt.savefig(‘tmp_test_plot_math.png’)

def main(): “”“Main routine, executed when this file is run as a script “””

global TESTDIR cwd = os.getcwd() TESTDIR = tempfile.mkdtemp(prefix=’tmp-testdata-‘,dir=cwd)

print “Running tests:”

try: os.chdir(TESTDIR) ret = nose.runmodule(argv=[__file__,’-vvs’], exit=False) finally: os.chdir(cwd) print “Cleanup - removing temp directory:”, TESTDIR

shutil.rmtree(TESTDIR) print “”” *************************************************************************** TESTS FINISHED ***************************************************************************

If the printout above did not finish in ‘OK’ but instead says ‘FAILED’, copy and send the entire output, including the system information below, for help. We’ll do our best to assist you. You can send your message to the Scipy user mailing list:

http://mail.scipy.org/mailman/listinfo/scipy-user

but feel free to also CC directly: Fernando.Perez@berkeley.edu “”” sys_info()

#----------------------------------------------------------------------------- if __name__ == ‘__main__’: main()

controlling digits in array print


numpy.set_printoptions

hdf install – current


source: ~phil/install/hdf5-1.8.4.tar.bz2

~/install/hdf5-1.8.4 phil@swift% export CC=gcc ~/install/hdf5-1.8.4 phil@swift% export FC=gfortran

tern: ./configure –prefix=/home/phil/usr64_nc4 –enable-hl –enable-shared –enable-fortran –enable-cxx

make make check make install

roc: ./configure –prefix=/users/user-soft/usr251_Centos –enable-hl –enable-shared –enable-fortran –enable-cxx

netcdf 4 install – current


source: ~phil/install/netcdf-4.1-beta2.tar.gz

export FC=gfortran export CC=gcc export F77=gfortran export CXX=g++

~/install/netcdf-4.1-rc1 phil@tern% ./configure –with-hdf5=/home/phil/usr64_nc4/ –prefix=/home/phil/usr64_nc4 –enable-shared –enable-netcdf-4

make check install

netcdf-python source ~phil/install/netCDF4-0.9.tar.gz

export HDF5_DIR=/home/phil/usr64_nc4 export NETCDF4_DIR=/home/phil/usr64_nc4 python setup.py install

and if you want netcdf3 install ~phil/install/netcdf-3.6.3.tar.gz as for netcdf4

on tern: export NETCDF3_DIR=/home/phil/usr64/netcdf_3.6.3 ~/usr64/bin/python setup-nc3.py install

on roc:

export NETCDF3_DIR=/users/user-soft/netcdf_363_gfortran

~/repos/satellite/fwdmodel phil@roc% ldd /users/user-soft/usr251_Centos/lib/python2.5/site-packages/netCDF4.so

libnetcdf.so.6 => /users/user-soft/usr251_Centos/lib/libnetcdf.so.6 (0x00002aaaaad5b000) libhdf5.so.6 => /users/user-soft/usr251_Centos/lib/libhdf5.so.6 (0x00002aaaab04f000) libhdf5_hl.so.6 => /users/user-soft/usr251_Centos/lib/libhdf5_hl.so.6 (0x00002aaaab4e7000) libz.so.1 => /usr/lib64/libz.so.1 (0x00002aaaab739000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aaaab94d000) libc.so.6 => /lib64/libc.so.6 (0x00002aaaabb67000) libm.so.6 => /lib64/libm.so.6 (0x00002aaaabeb8000) /lib64/ld-linux-x86-64.so.2 (0x0000555555554000)

vis5d install


export f77=f77

optimize root finder


///~/repos/atsc405_zming/thermlib1.py

matplotlib markers


http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.lines.Line2D.set_marker

If you want the symbol faces to be completely transparent, set mfc=’None’ (with quotes):

plot([1,2,3], ‘o’, mfc=’None’)

If you need them to be colored but with an alpha, then you will have to plot twice, once for the edges as above (adding an alpha kwarg if desired), and the second time for the centers with markeredgewidth=0 to turn off the edges. (For consistency one might expect mec=’None’ should work the same way, but it doesn’t.)

The drawing model is such that alpha is attached to the whole marker, and can’t be set separately for edge and face without making two separate markers, as suggested above. Note also that postscript doesn’t support alpha at all.

pytables – using pytable as memmap


Re: [Numpy-discussion] np.memmap and memory usage

Francesc Alted Wed, 01 Jul 2009 06:04:32 -0700

A Wednesday 01 July 2009 10:17:51 Emmanuelle Gouillart escrigué: > Hello, > > I’m using numpy.memmap to open big 3-D arrays of Xray tomography > data. After I have created a new array using memmap, I modify the > contrast of every Z-slice (along the first dimension) inside a for loop, > for a better visualization of the data. Although I call memmap.flush > after each modification of a Z-slice, the memory used by Ipython keeps > increasing at every new iteration. At the end of the loop, the memory > used by Ipython is of the order of magnitude of the size of the data file > (1.8Go !). I would have expected that the maximum amount of memory used > would corresponde to only one Z-slice of the 3D array. See the code > snapshots below for more details. > > Is this an expected behaviour?

I think so, yes. As all the file (1.8 GB) has to be processed, the OS will need to load everything in RAM at least once. The memory containing already processed data is not ‘freed’ by the OS even if you try to flush() the slices (this just force memory data to be saved on-disk), but rather when the OS needs it again (but still, they will be swapped out to disk, effectively consuming resources). I’m afraid that the only way to actually ‘free’ the memory is to close() the complete dataset.

> How can I reduce the amount of > memory used by Ipython and still process my data?

There are a number of interfaces that can deal with binary data on-disk so that they can read&write slices of data easily. By using this approach, you only have to load the appropriate slice, operate and write it again. That’s similar to how numpy.memmap works, but it uses far less memory (just the loaded slice).

For example, by using the PyTables interface [1], you could do:

f = tb.openFile(filename+”.h5”, “r+”) data = f.root.data for nrow, sl in enumerate(data): sl[sl<imin] = imin sl[sl>imax] = imax data[nrow] = sl f.close()

which is similar to your memmap-based approach:

data = np.memmap(filename+”.bin”, mode=’r+’, dtype=’f4’, shape=shape) for sl in data: sl[sl<imin] = imin sl[sl>imax] = imax

just that it takes far less memory (47 MB vs 1.9 GB) and besides, it has no other limitation than your available space on disk (compare this with the limit of your virtual memory when using memmap). The speeds are similar too:

Using numpy.memmap Time creating data file: 8.534 Time processing data file: 32.742

Using tables Time creating data file: 2.88 Time processing data file: 32.615

However, you can still speed-up out-of-core computations by using the recently introduced tables.Expr class (PyTables 2.2b1, see [2]), which uses a combination of the Numexpr [3] and PyTables advanced computing capabilities:

f = tb.openFile(filename+”.h5”, “r+”) data = f.root.data expr = tb.Expr(“where(data<imin, imin, data)”) expr.setOutput(data) expr.eval() expr = tb.Expr(“where(data>imax, imax, data)”) expr.setOutput(data) expr.eval() f.close()

and the timings for this venue are:

Using tables.Expr Time creating data file: 2.393 Time processing data file: 18.25

which is around a 75% faster than a pure memmap/PyTables approach.

Further, if your data is compressible, you can probably achieve additional speed-ups by using a fast compressor (like LZO, which is supported by PyTables right out-of-the-box).

I’m attaching the script I’ve used for producing the above timings. You may find it useful for trying this out against your own data.

[1] http://www.pytables.org [2] http://www.pytables.org/download/preliminary/ [3] http://code.google.com/p/numexpr/

HTH,

– Francesc Alted

import sys from time import time import numpy as np import tables as tb

shape=(512, 981, 981) filename = “/scratch2/faltet/data-vol”

def create_data(kind): if kind == “np”: data = np.memmap(filename+”.bin”, mode=’w+’, dtype=’f4’, shape=shape) for nrow in range(len(data)): data[nrow] = nrow else: f = tb.openFile(filename+”.h5”, “w”) data = f.createCArray(f.root, ‘data’, tb.Float32Atom(), shape=shape) for nrow in range(len(data)): data[nrow] = nrow f.close()

def process_data(kind): imin, imax = -2, 2 if kind == “np”: data = np.memmap(filename+”.bin”, mode=’r+’, dtype=’f4’, shape=shape) for sl in data: sl[sl<imin] = imin sl[sl>imax] = imax #print “data (numpy)–>”, data elif kind == “tb”: f = tb.openFile(filename+”.h5”, “r+”) data = f.root.data for nrow, sl in enumerate(data): sl[sl<imin] = imin sl[sl>imax] = imax data[nrow] = sl #print “data (tables) –>”, data[:] f.close() else: f = tb.openFile(filename+”.h5”, “r+”) data = f.root.data expr = tb.Expr(“where(data<imin, imin, data)”) expr.setOutput(data) expr.eval() expr = tb.Expr(“where(data>imax, imax, data)”) expr.setOutput(data) expr.eval() #print “data (tables.Expr)–>”, data[:] f.close()

if __name__ == ‘__main__’: if len(sys.argv) > 1: kind = sys.argv[1] else: kind = “np”

if kind == “np”: print “Using numpy.memmap” elif kind == “tb”: print “Using tables” else: print “Using tables.Expr”

t0 = time() create_data(kind) print “Time creating data file:”, round(time()-t0, 3) t0 = time() process_data(kind) print “Time processing data file:”, round(time()-t0, 3)

_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

future division


from __future__ import division

array creation


theTime=np.empty_like(theTemp)

plotting netcdf file


from netCDF4 import Dataset import matplotlib.pyplot as plt ncfilename=’BOMEX_128x128x64_50m_3s.nc’ keepFigs={} theFile=Dataset(ncfilename,’r’,’NETCDF3_CLASSIC’) theFile.variables.keys() theZ=theFile.variables[‘z’][…] theTKE=theFile.variables[‘TKE’][…] figNum=0 theFig=plt.figure(figNum) keepFigs[(figNum,’BOMEX_50m_TKE’)]=theFig theFig.clf() theAx=theFig.add_subplot(111) theAx.plot(theTKE.T,theZ)

for key,theFig in keepFigs.items(): fignum,figName=key figName=’../png/%s.png’ % figName theFig.canvas.draw() theFig.savefig(figName)

masked arrays – numpy.ma


np.ma.masked is fill value:

When you use display a mask entry, you actually display the `masked` constant: it’s a 0-shaped float masked array with its own `fill_value`, but more importantly, it’s a constant. You can use it to test whether one element is masked. Check this example: >>> x = ma.array([1,2,3],mask=[0,1,0],dtype=int,fill_value=999) >>> x masked_array(data = [1 – 3], mask = [False True False], fill_value = 999) >>> x[1] is masked True >>> x[1] masked_array(data = –, mask = True, fill_value = 1e+20)

Now, you can change the fill_value of the masked element to whatever you want, but it’ll be propagated >>> ma.masked.fill_value = -999. >>> x[1] masked_array(data = –, mask = True, fill_value = -999.0) >>> y = ma.array([3,2,1],mask=[1,0,1]) >>> y[0] masked_array(data = –, mask = True, fill_value = -999.0)

On Oct 6, 2009, at 10:58 PM, Gökhan Sever wrote: > > > > I see your points. I don’t want to give you extra work, don’t > > worry :) It just seem a bit bizarre: > > > > I[27]: c.data[‘Air_Temp’].fill_value > > O[27]: 999999.99990000005 > > > > I[28]: c.data[‘Air_Temp’][4].fill_value > > O[28]: 1e+20 > > > > As you see, it just returns two different fill_values.

I know, but I hope you see the difference : in the first line, you access the `fill_value` of the array. In the second, you access the `fill_value` of the `masked` constant. Each time you access a masked element of an array with __getitem__, you get the masked constant. We could force the constant to inherit the fill_value of the array that calls __getitem__, but it’d be propagated.

> > I know eventually you will be the one handling this :) it might be > > good to add this issue to the tracker.

Go for it, but don’t expect anything before the release of 1.4.0 (in the next few months)

> > >> > > This is the last resort. I will eventually try this if I don’t any >> > > other options left. > > > > I gonna have difficulties fixing something that I don’t see broken… > > Now, there might be something wrong in my installation. I gonna try to > > install 1.3.0 somwehere. say, what Python are you using ? > > > > OK, I use meld to diff my copy of ma/core.py with the latest trunk > > version. There are lots of differences :) So there is a possibility > > that I might have built my local numpy before 09/08. I should renew > > my copy. Do you know the link of svn browser for the numpy? I don’t > > know how you are making separate installations without overriding > > other package? I either use Sage (if I have extra time) or SPD. They > > are both shipped with numpy 1.3.0.

Make yourself a favor and install virtualenv and virtualenvwrapper. That way, several versions of the same package can coexist without interference. Oh, and install pip till you’re at it:

http://pypi.python.org/pypi/virtualenv http://www.doughellmann.com/projects/virtualenvwrapper/ http://pypi.python.org/pypi/pip

On Oct 7, 2009, at 1:12 AM, Gökhan Sever wrote: > > One more from me: > > I[1]: a = np.arange(5) > > I[2]: mask = 999 > > I[6]: a[3] = 999 > > I[7]: am = ma.masked_equal(a, mask) > > > > I[8]: am > > O[8]: > > masked_array(data = [0 1 2 – 4], > > mask = [False False False True False], > > fill_value = 999999) > > > > Where does this fill_value come from? To me it is little confusing > > having a “value” and “fill_value” in masked array method arguments.

Because the two are unrelated. The `fill_value` is the value used to fill the masked elements (that is, the missing entries). When you create a masked array, you get a `fill_value`, whose actual value is defined by default from the dtype of the array: for int, it’s 999999, for float, 1e+20, you get the idea. The value you used for masking is different, it’s just whatver value you consider invalid. Now, if I follow you, you would expect the value in `masked_equal(array, value)` to be the `fill_value` of the output. That’s an idea, would you mind fiilling a ticket/enhancement and assign it to me? So that I don’t forget.

> > Probably you can pin-point the error by testing a 1.3.0 version > > numpy. Not too many arc function with masked array users around I > > guess :)

Will try, but “if it ain’t broken, don’t fix it”…

> > assert(np.arccos(ma.masked), ma.masked) would be the simplest.

(and in fact, it’d be assert(np.arccos(ma.masked) is ma.masked) in this case).

> > Good to know this. The more I spend time with numpy the more I > > understand the importance of testing the code automatically. This > > said, I still find the test-driven-development approach somewhat > > bizarre. Start only by writing test code and keep implementing your > > code until all the tests are satisfied. Very interesting…These > > software engineers…

Bah, it’s not a rule cast in iron… You can start writing your code but do write the tests at the same time. It’s the best way to make sure you’re not breaking something later on. > >

______________________________________

ode integration


from scipy import array, arange from scipy.integrate import odeint import scipy as sp

def lorenz(w, t, prandtl, rayleigh, beta): x, y, z = w return sp.array([prandtl*(y-x), x*(rayleigh-z)-y, x*y-beta*z])

w0=sp.array([0.,1.,0.]) timepoints=sp.arange(0.,100.,0.01) prandtl=10. rayleigh=28. beta=8/3. data3d = odeint(lorenz, w0, timepoints, args=(prandtl,rayleigh,beta))

import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(1) fig.clf() ax = Axes3D(fig) ax.plot(data3d[:,0],data3d[:,1],data3d[:,2]) plt.show()

preserving array scalars and indexing


in /home/phil/usr64/lib/python2.5/site-packages/holdnew/numpy/lib/type_check.py

def nan_to_num(x): is_scalar = False if not isinstance(x, _nx.ndarray): x = asarray(x) if x.shape == ():

is_scalar = True y = x.copy() old_shape = y.shape if y.shape == ():

y.shape = (1,) t = y.dtype.type if issubclass(t, _nx.complexfloating): return nan_to_num(y.real) + 1j * nan_to_num(y.imag) if issubclass(t, _nx.inexact): are_inf = isposinf(y) are_neg_inf = isneginf(y) are_nan = isnan(y) maxf, minf = _getmaxmin(y.dtype.type) y[are_nan] = 0 y[are_inf] = maxf y[are_neg_inf] = minf if is_scalar: y = y[0] else: y.shape = old_shape return y

netcdf – copying netcdf files – best


from netCDF4 import Dataset import glob,os.path import numpy as np oldFiles=glob.glob(“../cgils_2009_12_ubc/*.nc”) print oldFiles

def copyit(oldnc,newnc): pass

for theFile in oldFiles: newFileName=os.path.split(theFile)[-1] oldNC=Dataset(theFile,’r’) newNC=Dataset(newFileName,’w’,format=’NETCDF3_CLASSIC’) theDims=oldNC.dimensions for key,value in theDims.items(): inDim=len(value) newNC.createDimension(key,inDim) for varName,theVar in oldNC.variables.items(): newVar=newNC.createVariable(varName,theVar.dtype,\ theVar.dimensions) newVar[…]=theVar[…] oldNC.close() newNC.close()

ncattrs

__getattr__

installing netcdf 3.6.3 on newroc


#need to use pgf90 for f77 to get f90 linkages #export LDFLAGS=’-lgfortran’

export CC=gcc export CXX=g++ export CFLAGS=’-fPIC -v’ export FFLAGS=’-fPIC -v’ export FCFLAGS=’-fPIC -v’ export CXXFLAGS=’-fPIC -v’

export FC=pgf90 export F77=pgf90 DIR1=/opt/local/netcdf_4_3_1_pgf90 unset LD_LIBRARY_PATH unset LD_RUN_PATH #export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

export FC=ifort export F77=ifort DIR1=/opt/local/netcdf_4_3_1_ifort unset LD_LIBRARY_PATH unset LD_RUN_PATH export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1} gcc -I/opt/local/netcdf_4_3_1_ifort/include -fPIC -v -c -o simple_xy_wr.o simple_xy_wr.c gcc -L/opt/local/netcdf_4_3_1_ifort/lib -o simple_xy_wr simple_xy_wr.o -lnetcdf **works

ifort -I/opt/local/netcdf_4_3_1_ifort/include -fPIC -v -c -o simple_xy_wr.o simple_xy_wr.f90 #export LD_RUN_PATH=/opt/intel/lib/intel64/ ifort -L/opt/local/netcdf_4_3_1_ifort/lib -o simple_xy_wr simple_xy_wr.o -lnetcdff -lnetcdf

to eliminate LD_RUN_PATH use ldconfig phil@newroc:~/install/netcdf-fortran-4.2/examples/F90$ cat etc/ld.so.conf.d/x86_64_ifort.conf /opt/intel/lib/intel64

**works

export FC=ifort export F77=ifort DIR1=/opt/local/netcdf_3_6_3_ifort unset LD_LIBRARY_PATH unset LD_RUN_PATH export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

ifort -I/opt/local/netcdf_3_6_3_ifort/include -fPIC -v -c -o simple_xy_wr.o simple_xy_wr.f90 export LD_RUN_PATH=/opt/local/netcdf_3_6_3_ifort/lib ifort -L/opt/local/netcdf_3_6_3_ifort/lib -o simple_xy_wr simple_xy_wr.o -lnetcdff -lnetcdf

or:

unset LD_RUN_PATH ifort -L/opt/local/netcdf_3_6_3_ifort/lib -Wl,-rpath -Wl,/opt/local/netcdf_3_6_3_ifort/lib -o simple_xy_wr simple_xy_wr.o -lnetcdff -lnetcdf

Libraries have been installed in: /opt/local/netcdf_3_6_3_pgi/lib

If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR’ flag during linking and do at least one of the following:

  • add LIBDIR to the `LD_LIBRARY_PATH’ environment variable during execution
  • add LIBDIR to the `LD_RUN_PATH’ environment variable during linking
  • use the `-Wl,-rpath -Wl,LIBDIR’ linker flag
  • have your system administrator add LIBDIR to `/etc/ld.so.conf’

installing climt – 0.6.6


python setup.py build –fcompiler=gnu95 rm -rf lib/climt/_*.so rm -rf build sys.path.append(‘/home/phil/repos/climt/build/lib’) In [2]: pwd Out[2]: ‘/nfs/kite/home/phil/repos/climt’

import climt._cam3_radiation

In [3]: cd lib/examples /nfs/kite/home/phil/repos/climt/lib/examples

export PYTHONPATH=/home/phil/repos/climt/build/lib export LD_RUN_PATH=/home/phil/usr64/netcdf_3.6.3/lib

python compare_rad_schemes.py cp -r home/datatmp/phil/climt/lib/climt/data /home/phil/repos/climt/build/lib/climt

interpolate


Reference: http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.bisplrep.html

import scipy import math import numpy from scipy import interpolate

x= [1,2,3,4,5,6] y= [10,20,30]

Y = numpy.array([[i]*len(x) for i in y]) X = numpy.array([x for i in y]) Z = numpy.array([[2.3,3.4,5.6,7.8,9.6,11.2], [4.3,5.4,7.6,9.8,11.6,13.2], [6.3,7.4,8.6,10.8,13.6,15.2]])

tck = interpolate.bisplrep(X,Y,Z) print interpolate.bisplev(3.5,15,tck)

7.84921875

EDIT:

Upper solution does not give you perfect fit. check

print interpolate.bisplev(x,y,tck)

[[ 2.2531746 4.2531746 6.39603175] [ 3.54126984 5.54126984 7.11269841] [ 5.5031746 7.5031746 8.78888889] [ 7.71111111 9.71111111 10.9968254 ] [ 9.73730159 11.73730159 13.30873016] [ 11.15396825 13.15396825 15.2968254 ]]

to overcome this interpolate whit polyinomials of 5rd degree in x and 2nd degree in y direction

tck = interpolate.bisplrep(X,Y,Z,kx=5,ky=2) print interpolate.bisplev(x,y,tck)

[[ 2.3 4.3 6.3] [ 3.4 5.4 7.4] [ 5.6 7.6 8.6] [ 7.8 9.8 10.8] [ 9.6 11.6 13.6] [ 11.2 13.2 15.2]]

This yield

print interpolate.bisplev(3.5,15,tck)

7.88671875

Plotting: reference http://matplotlib.sourceforge.net/examples/mplot3d/surface3d%5Fdemo.html

fig = plt.figure() ax = Axes3D(fig) ax.plot_surface(X, Y, Z,rstride=1, cstride=1, cmap=cm.jet) plt.show()

link|flag

edited yesterday

mlab.csv2rec


test=\ “”“200 , 290.764

  1. , 287.561
  2. , 284.39

1600., 281.125 “”” import numpy as np import matplotlib as mplt import cStringIO theFile=cStringIO.StringIO(test) structarray=mplt.mlab.csv2rec(theFile,checkrows=2,delimiter=’,’) rows=structarray.shape cols=structarray[0].shape outarray=np.frombuffer(structarray.data) outarray=outarray.reshape([rows,-1])

loadmat example


scipy.io.loadmat(theFile)

np.loadtxt(theFile)

loadtxt example


np.genfromtxt(theFile)

reading wyoming soundings


/space2/kite_backups/level_0_kite_users/mrautenh/src/atm_profiles_kratz/soundings/readsound.py /home/phil/repos/sounding_dir/readsoundings.py

~ phil@kite% cat /home/phil/teaching/eosc211/eosc211_kite/week10/thesounding.py import readsoundings out=readsoundings.readsound(markerText=’LCH Lake Charles Observations at’, inFileName=’lake_charles.txt”) from scipy.io import savemat thekeys=out.keys() thekeys.sort() keyList=[] titleList=[] datevecList=[] for key in thekeys: oldTup=key.split(’ ‘) newTup=(oldTup[2],oldTup[1],oldTup[0],oldTup[3]) #remove spaces to make valid matlab varname newkey=’%s_%s_%s_%s’ % newTup #switch to dashes for plot titles that don’t subscript plotTitle=’%s-%s-%s-%s’ % newTup theDay=string.atoi(newTup[1]) theTime=string.atoi(newTup[2][:2]) datevecList.append((newTup,(theDay,theTime))) keyList.append((newTup,(key,newkey))) titleList.append((newTup,plotTitle)) datevecList.sort() keyList.sort() titleList.sort() #undecorate keyList=[item for newTup,item in keyList] titleList=[item for newTup,item in titleList] datevecList=[item for newTup,item in datevecList] newDict={} datevecList=[(2006,7,day,hour,0,0) for day,hour in datevecList] print datevecList for old,new in keyList: newDict[new]=out[old][:,:6]

savemat(‘soundings.mat’,newDict)

#here’s the time sorted list to guide makestruct.m #in filling the cell arrray nameFile=file(‘namelist.txt’,’w’) for old,new in keyList: nameFile.write(new + ‘\n’) nameFile.close()

titleFile=file(‘titlelist.txt’,’w’) for title in titleList: print title titleFile.write(title + ‘\n’) titleFile.close()

datevecFile=file(‘datevecList.txt’,’w’) for datevec in datevecList: datevecFile.write(‘%d,%d,%d,%d,%d,%d\n’ % datevec) datevecFile.close()

scipy least squares


reading netcdf

-------o---------

python – netcdf – general file copy


ncattrs

import Scientific.IO.NetCDF as nc

#how to completely copy a netcdf file

ncfile=’daily-1957-12Z.nc’ infile = nc.NetCDFFile(ncfile, ‘r’) outfile=nc.NetCDFFile(‘clone.nc’, ‘w’)

#first transfer the dimensions

for (name,value) in infile.dimensions.items(): outfile.createDimension(name,value)

#next tranfer the global attributes

for (name,value) in infile.__dict__.items(): print “copying global attribute: “,name setattr(outfile,name,value)

#next transfer each variable and its attributes

for (inname,invalue) in infile.variables.items(): print “copying variable: “,name #create the variable outvar = outfile.createVariable(inname,invalue.typecode(),invalue.dimensions) #transfer the attributes for (attname,attvalue) in invalue.__dict__.items(): setattr(outvar,attname,attvalue) #finally, copy the data outvar.assignValue(infile.variables[inname].getValue())

infile.close() outfile.close()

nose testing – minimal example


import numpy as np from numpy.testing import *

class TestContrast(object):

def __init__(self):

def test_contrast1(self): assert_almost_equal(5, 6)

if __name__==”__main__”: run_module_suite()

basemap – determing land sea ocean pixels


Jeff Whitaker <jswhit@fastmail.fm> to Stephane Raynaud <stephane.raynaud@gmail.com> cc Ross.Wilson@ga.gov.au, matplotlib-users@lists.sourceforge.net date Mon, Nov 2, 2009 at 7:52 AM

import numpy as np from numpy import ma from numpy.random import seed import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap, _geoslib from matplotlib.mlab import griddata

ll_lat = -38.39477 # extent of area of interest ll_lon = 144.54767 ur_lat = -37.51642 ur_lon = 145.67144

num_points = 100 # sample points

seed(0) data = np.ones((3, num_points)) data[0,:] *= ll_lon + np.random.random((num_points))*(ur_lon-ll_lon) data[1,:] *= ll_lat + np.random.random((num_points))*(ur_lat-ll_lat) data[2,:] *= np.random.random((num_points))*10000

class Basemap2(Basemap): def is_land(self,xpt,ypt): landpt = False n = 0 for x,y in self.coastpolygons: type = self.coastpolygontypes[n] if type in [1,3]: # land or island in lake b = np.asarray([x,y]).T poly = _geoslib.Polygon(b) landpt = _geoslib.Point((xpt,ypt)).within(poly) if landpt: break n = n + 1 return landpt

fig = plt.figure() m = Basemap2(projection=’cyl’, llcrnrlat=ll_lat, urcrnrlat=ur_lat, llcrnrlon=ll_lon, urcrnrlon=ur_lon, resolution=’f’, suppress_ticks=False, area_thresh=0.5) for npt in range(data.shape[1]): if not m.is_land(data[0,npt],data[1,npt]): data[:,npt] = 1.e30 data = ma.masked_values(data,1.e30) plt.hexbin(data[0,:], data[1,:], data[2,:],zorder=2) m.fillcontinents(color=(0.8,0.8,0.8,0)) m.drawcoastlines(linewidth=0.25, color=’k’) plt.show()

meshgrid and block averaging


pvals=np.linspace(1,100,35) tvals=np.linspace(0,100,2400) time,press=np.meshgrid(tvals,pvals) print time.shape print press.shape #(35, 2400) time=time.reshape(35,100,24) meantime=time.mean(axis=-1) fig = figure(1) fig.clf() theAx=fig.add_subplot(111) thetime=np.linspace(0,100,100) theAx.contourf(thetime,pvals,meantime) plt.show()

current install – matplotlib


~/install/Python-2.6.5 phil@roc% export LD_RUN_PATH=/users/user-soft/usr_py26/lib ./configure –prefix=/users/user-soft/usr_py26 –enable-unicode=ucs4 –enable-shared

svn co https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/trunk matplotlib-trunk

make sure

~/install/numpy-trunk/numpy/distutils/site.cfg

has been copied to

~/install/numpy-trunk/numpy/distutils/site.cfg

cd ~/install/numpy-trunk

export LD_RUN_PATH=/users/user-soft/usr_py26/lib /users/user-soft/usr_py26/bin/python setup.py build –fcompiler=gfortran /users/user-soft/usr_py26/bin/python setup.py install

~/install phil@roc% cd setuptools-0.6c11 ~/install/setuptools-0.6c11 phil@roc% /users/user-soft/usr_py26/bin/python setup.py install

~/install/setuptools-0.6c11 phil@roc% /users/user-soft/usr_py26/bin/easy_install nose

import numpy numpy.test(‘fast’)

~/install/scipy-trunk phil@roc% /users/user-soft/usr_py26/bin/python setup.py install –fcompiler=gfortran ~/install/scipy-trunk phil@roc% /users/user-soft/usr_py26/bin/python setup.py install

~ phil@roc% /users/user-soft/usr_py26/bin/python >>> import scipy >>> scipy.test(‘fast’)

export F77=gfortran export GEOS_DIR=/users/user-soft/usr251_Centos

cd ~/install/matplotlib/matplotlib-trunk/matplotlib /users/user-soft/usr_py26/bin/python setup.py install

/users/user-soft/usr_py26/bin/python setup.py install ~/install/matplotlib/matplotlib-trunk/toolkits/basemap phil@roc% export GEOS_DIR=/users/user-soft/usr251_Centos ~/install/matplotlib/matplotlib-trunk/toolkits/basemap phil@roc% /users/user-soft/usr_py26/bin/python setup.py install

hdf4 is installed in

/users/user-soft/usr251_Centos/lib/hdf4

to build pyhdf export LIBRARY_DIRS=/home/phil/usr64/libhdf4_25_gfortran_static/lib export INCLUDE_DIRS=/home/phil/usr64/libhdf4_25_gfortran_static/include

export INCLUDE_DIRS=/users/user-soft/usr251_Centos/lib/hdf4/include export LIBRARY_DIRS=/users/user-soft/usr251_Centos/lib/hdf4/lib export NOSZIP=1

with dynamic libraries on osx using brew hdf4 and szip

export INCLUDE_DIRS=/usr/local/include export LIBRARY_DIRS=/usr/local/lib export NOSZIP=0

do python setup.py install then edit

gcc -bundle -undefined dynamic_lookup -L/Users/phil/continuum/anaconda/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/pyhdf/hdfext_wrap.o -L/usr/local/lib -L/Users/phil/continuum/anaconda/lib -lmfhdf -lhdf -ljpeg -lz -lsz -o build/lib.macosx-10.5-x86_64-2.7/pyhdf/_hdfext.so

otool -L /Users/phil/install/pyhdf-0.8.3/build/lib.macosx-10.5-x86_64-2.7/pyhdf/_hdfext.so /Users/phil/install/pyhdf-0.8.3/build/lib.macosx-10.5-x86_64-2.7/pyhdf/_hdfext.so: /usr/local/lib/libmfhdf.4.2.8.dylib (compatibility version 4.2.8, current version 4.2.8) /usr/local/lib/libhdf.4.2.8.dylib (compatibility version 4.2.8, current version 4.2.8) libjpeg.8.dylib (compatibility version 13.0.0, current version 13.0.0) libz.1.dylib (compatibility version 1.0.0, current version 1.2.7) /usr/local/lib/libsz.2.0.0.dylib (compatibility version 3.0.0, current version 3.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

rerun python setup.py install – fails to install egg because not running as brew. Move egg to ~phil/pythonlibs/pyhdf

~/install/pyhdf-0.8.3 phil@denmank% mkdir -p ~/pythonlibs ~/install/pyhdf-0.8.3 phil@denmank% mv Users/phil/install/pyhdf-0.8.3/build/bdist.macosx-10.5-x86_64/egg/pyhdf ~/pythonlibs

pyhdf needs static libraries (hdf4 default

~/install/pyhdf-0.8.3 phil@roc% /users/user-soft/usr_py26/bin/python setup.py install /users/user-soft/usr_py26/bin/python hdfstruct.py \ /users/nmorie/matlab/profiles/MYD07_fev_2008/MYD07_L2.A2008049.0650.005.2008049221419.hdf

to build h5py

libhdf5 is at: /users/user-soft/usr251_Centos/lib

export HDF5_DIR=/users/user-soft/usr251_Centos export HDF5_API=18 ~/install/h5py-1.3.0 phil@roc% /users/user-soft/usr_py26/bin/python setup.py install

install doesn’t work, need to hand copy out of the egg directory

/users/user-soft/usr_py26/lib/python2.6/site-packages phil@roc% cp -a /users/user-soft/usr_py26/lib/python2.6/site-packages/h5py-1.3.0-py2.6-linux-x86_64.egg/h5py .

test with:

nosetests /users/user-soft/usr_py26/lib/python2.6/site-packages/h5py-1.3.0-py2.6-linux-x86_64.egg/h5py/tests

– PyNIO

~/install phil@roc% tar xzvf PyNIO-1.3.0b5.linux-x86_64-redhat-py262-gcc412.tar.gz ~/install phil@roc% mv ./lib/python2.6/site-packages/Nio.pth users/user-soft/usr_py26/lib/python2.6/site-packages ~/install phil@roc% mv ./lib/python2.6/site-packages/PyNIO users/user-soft/=usr_py26/lib/python2.6/site-packages

– netCDF4py

~/install/netCDF4-0.9 phil@roc% export NETCDF3_DIR=/users/user-soft/netcdf_363_gfortran ~/install/netCDF4-0.9 phil@roc% export HDF5_DIR=/users/user-soft/usr251_Centos ~/install/netCDF4-0.9 phil@roc% export NETCDF4_DIR=/users/user-soft/usr251_Centos python setup.py install python setup-nc3.py install ~/install/netCDF4-0.9/test3 phil@roc% python run_all.py

atleast_1d and nans


> In [42]: def nan_replace(a, fill=0.0): > ....: a_ = np.atleast_1d(a) > ....: a_[np.isnan(a_)] = fill

grib install


export CFLAGS=-fPIC export FFLAGS=-fPIC export FCFLAGS=-fPIC export FC=gfortran export F77=gfortran

~/Downloads/temp/jasper-1.900.1 phil@tern% ./configure –prefix=/home/phil/usr64

~/Downloads/grib_api-1.9.0 phil@tern% ./configure –prefix=/home/phil/usr64 –with-jasper=/home/phil/usr64

pygrib export GRIBAPI_DIR=/home/phil/usr64 export JASPER_DIR=/home/phil/usr64 ~/usr64/bin/python setup.py install

debugging – run python under gdb


>> >> $ gdb python >> (gdb) set args runtests.py –no-fork >> (gdb) r

netcdf with g95


export FC=g95 export F77=g95

./configure –prefix=/home/phil/usr64/netcdf_3.6.3_g95 –enable-shared

colormaps


I responded to this off list (through a separate request). I did want to point out that the data structure used to create linear segmented colormaps does provide the capability for easily defining constant color bands. There is a simple, but not very general, means of just restricting the number of points in the color map. By making this a small number, one will just have that many distinct colors available (by default it is set to 256, which generally makes it hard to distinguish the distinct levels). This is only useful if you wish the thresholds for the constant levels to be uniformly spaced between 0 and 1 after normalizing the data values to that interval. In this particular case choosing N to be small (7) didn’t align 0 with one of these thresholds and thus wasn’t useful for this purpose.

The more general means of setting arbitrary constant color bands is to take advantage of the fact that the definition of the linear segments allows for discontinuities at each threshold. Two examples are shown below. The first is a continuous colormap and the second illustrates use of constant color bands.

The data structure is simply dictionary that has entries for each of the 3 colors. Each of these is set a tuple of tuples. Each of the interior tuples represents the color value(s) at a normalized data value (i.e., values ranging from 0 to 1). The first value is the normalized data value for which the color intensities apply. Two color intensities are required to allow for discontinuities. So the second value of the tuple is the color intensity just below the data value, and the third the value is the value just above. If the color map is to be continuous at that point, these two values should be the same. The tuples should be monotonic in data values and should start with 0. and end with 1. The color intensities are linearly interpolated between the specified data points. (Actually, color lookup tables are generated instead and simple value lookup is used. As mentioned, the default number of entries in the lookup tables is 256. This can be overridden by specifying how many levels are desired) The following examples illustrate two simple cases.

mycmdata1 = { ‘red’ : ((0., 0., 0.), (0.5, 0.9, 0.9), (1., 1., 1.)), ‘green’: ((0., 0., 0.), (1., 0., 0.)), ‘blue’ : ((0., 0., 0.), (1., 0., 0.)) } mycm1 = LinearSegmentedColormap(‘mycm’, mycmdata1)

This color map is intended to show only red with values between 0 and 0.5 using 90% of the red color range, values running from 0.5 to 1.0 only result in a minor increase of the red intensity from 0.9 to 1.0.

mycmdata2 = { ‘red’ : ((0., 1., 1.), (0.1, 1., 0.), (1., 0., 0.)), ‘green’: ((0., 0., 0.), (0.1, 0., 1.), (0.9, 1., 0.), (1., 0., 0.)), ‘blue’ : ((0., 0., 0.), (0.9, 0., 1.), (1., 1., 1.)) } mycm2 = LinearSegmentedColormap(‘mycm’, mycmdata2)

For this color map, value between 0. and 0.1 will be full red, values between 0.1 and 0.9 will be full green, and values between 0.9 and 1. will be full blue. Note that in this case the difference in the 2nd and 3rd values in the tuples at the changes in color. Color values are interpolated between the normalized data values and since they are the same over the interval, they are constant.

Randy’s case is a bit unusual in that one needs to figure out where 0 in the original data maps to the normalized data, and then construct a colormap that used that “normalized” 0 value as a threshold. So one must construct a colormap for each such image (admittedly a bit clumsy).

Perry

matplotlib – basemap example


from pylab import * from mpl_toolkits.basemap import Basemap lons = linspace(0, 360, 361) lats = 40.*ones(len(lons)) map = Basemap(projection=’ortho’,lon_0=270,lat_0=90.) x,y = map(lons,lats) map.plot(x,y,color=’y’) map.bluemarble(scale=0.5) show()

matplotlib – animation loop


It might be more effort, but what you’re doing now plays havoc with GUI event loops. Now, granted, until EPD upgrades to Matplotlib 1.0.0 this won’t work for you (unless you’re willing to install your own), but this is how IMHO is best to approach this problem:

import matplotlib.pyplot as plt import numpy as np import sys

def dot(): sys.stdout.write(‘.’) sys.stdout.flush()

def busy_loop(): for i in range(1000): r = np.random.rand(100,100) return r

def update_plot(): update_plot.count += 1 r = busy_loop() plt.clf() plt.imshow(r, interpolation=’nearest’, cmap=plt.get_cmap(‘gray’)) plt.draw() dot()

return update_plot.count < 10 update_plot.count = 0

fig = plt.figure()

timer = fig.canvas.new_timer(interval=250) timer.add_callback(update_plot) timer.start() plt.show()

This, to me, isn’t any more complex than your original (the most complex part comes from getting it to stop after a fixed number of iterations). The benefit is that the timed updates integrate into the GUI event loop and don’t fight it. The other benefit is that this works with any of the interactive backends and you don’t end up debugging weird draw problems. Even when I’ve gotten your style of animation to work in the past, I’ve still had problems where resizing the figure, etc. don’t work.

matplotlib – reverse the y axis


ax1.invert_yaxis()

matplotlib – normalizing colors


matplotlib – using hist and barplot


see eosc340 histogram lecture

scipy.io.loadmat and savemat

plotting z and height


ax1.plot(firstsound.temp,firstsound.height)

matlab io


~/install/hdf5-1.8.7 phil@roc% export FC=pgf90 ~/install/hdf5-1.8.7 phil@roc% export FFLAGS=-fPIC ~/install/hdf5-1.8.7 phil@roc% export CFLAGS=-fPIC ~/install/hdf5-1.8.7 phil@roc% ./configure –prefix=/users/user-soft/hdfpgf90 –enable-hl –enable-shared –enable-fortran –enable-cxx

export CPPFLAGS=-I/users/user-soft/hdfpgf90/include export LDFLAGS=-L/users/user-soft/hdfpgf90 ~/install/netcdf-4.1.3 phil@roc% ./configure –prefix=/users/user-soft/netcdfpgf90 –enable-shared

the_data=’/home/phil/public_html/courses/atsc500_old/atsc500/code/data/miami.mat’ mat_file=scipy.io.loadmat(the_data)

./configure –enable-cxx –prefix=/home/phil/usr_owl

gcc

gmp – con’t forget cxx

./configure –prefix=/home/phil/usr_centos –enable-cxx the_data=’/home/phil/public_html/courses/atsc500_old/atsc500/code/data/miami.mat’ mat_file=scipy.io.loadmat(the_data)

./configure –enable-cxx –prefix=/home/phil/usr_owl

gcc

gmp – con’t forget cxx

./configure –prefix=/home/phil/usr_centos –enable-cxx

ppl ./configure –with-gmp-prefix=/home/phil/usr_owl –prefix=/home/phil/usr_owl –with-java=/usr/lib/jvm/java-6-sun-1.6.0.26 ./configure –with-gmp-prefix=/home/phil/usr_centos –prefix=/home/phil/usr_centos

mpfr ./configure –prefix=/home/phil/usr_owl –with-gmp=/home/phil/usr_owl ./configure –prefix=/home/phil/usr_centos –with-gmp=/home/phil/usr_centos

mpc ./configure –with-gmp=/home/phil/usr_owl –with-mpfr=/home/phil/usr_owl –prefix=/home/phil/usr_owl ./configure –with-gmp=/home/phil/usr_centos –with-mpfr=/home/phil/usr_centos –prefix=/home/phil/usr_centos

cloog ppl ./configure –with-gmp-prefix=/home/phil/usr_owl –prefix=/home/phil/usr_owl –with-java=/usr/lib/jvm/java-6-sun-1.6.0.26 ./configure –with-gmp-prefix=/home/phil/usr_centos –prefix=/home/phil/usr_centos

mpfr ./configure –prefix=/home/phil/usr_owl –with-gmp=/home/phil/usr_owl ./configure –prefix=/home/phil/usr_centos –with-gmp=/home/phil/usr_centos

mpc ./configure –with-gmp=/home/phil/usr_owl –with-mpfr=/home/phil/usr_owl –prefix=/home/phil/usr_owl ./configure –with-gmp=/home/phil/usr_centos –with-mpfr=/home/phil/usr_centos –prefix=/home/phil/usr_centos

cloog

./configure –with-gmp=/home/phil/usr_owl –prefix=/home/phil/usr_owl –with-ppl=/home/phil/usr_owl –prefix=/home/phil/usr_owl ./configure –with-gmp=/home/phil/usr_centos –prefix=/home/phil/usr_centos –with-ppl=/home/phil/usr_centos –prefix=/home/phil/usr_centos

export LD_RUN_PATH=/home/phil/usr_owl/lib ./configure –with-gmp=/home/phil/usr_owl –prefix=/home/phil/usr_owl –with-ppl=/home/phil/usr_owl –prefix=/home/phil/usr_owl ./configure –with-gmp=/home/phil/usr_centos –prefix=/home/phil/usr_centos –with-ppl=/home/phil/usr_centos –prefix=/home/phil/usr_centos

export LD_RUN_PATH=/home/phil/usr_owl/lib

export LD_RUN_PATH=/home/phil/usr_centos/lib

only build 64 bit, don’t build java:

../gcc-4.6.1/configure –prefix=/home/phil/usr_centos –with-multilib-list=’m64,!m32’ –with-gmp=/home/phil/usr_centos –with-ppl=/home/phil/usr_centos –with-mpfr=/home/phil/usr_centos –with-cloog=/home/phil/usr_centos –enable-languages=c,c++,fortran

export LD_RUN_PATH=/home/phil/usr_centos/lib only build 64 bit, don’t build java:

fails because it can’t fine gnu/stubs-32.h ../gcc-4.6.1/configure –prefix=/home/phil/usr_centos –with-multilib-list=’m64,!m32’ –with-gmp=/home/phil/usr_centos –with-ppl=/home/phil/usr_centos –with-mpfr=/home/phil/usr_centos –with-cloog=/home/phil/usr_centos –enable-languages=c,c++,fortran

/nfs/kite/home/phil/gcc_install/gccobj phil@owl% apt-file find gnu/stubs-32.h libc6-dev-i386: /usr/include/gnu/stubs-32.h

install libc6-dev-i386

If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR’ flag during linking and do at least one of the following:

  • add LIBDIR to the `LD_LIBRARY_PATH’ environment variable during execution
  • add LIBDIR to the `LD_RUN_PATH’ environment variable during linking
  • use the `-Wl,-rpath -Wl,LIBDIR’ linker flag
  • have your system administrator add LIBDIR to `/etc/ld.so.conf’

See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages.

export LD_RUN_PATH=/home/phil/usr_centos/lib64:/home/phil/usr_centos/lib

./configure –prefix=/home/phil/usr_centos –enable-unicode=ucs4 –enable-shared export LD_RUN_PATH=/home/phil/usr_owl/lib64:/home/phil/usr_owl/lib ./configure –prefix=/home/phil/usr_owl –enable-unicode=ucs4 –enable-shared

./configure –prefix=/home/phil/usr_centos –enable-unicode=ucs4 –enable-shared export LD_RUN_PATH=/home/phil/usr_owl/lib64:/home/phil/usr_owl/lib ./configure –prefix=/home/phil/usr_owl –enable-unicode=ucs4 –enable-shared

numpy on owl


http://www.scipy.org/Installing_SciPy/Linux#head-af64f2425946120488727237b292771651b30c8f

hdf:

linker problems with –enable-fortran

./configure –prefix=/home/phil/usr_owl –enable-hl –enable-shared –enable-cxx

/nfs/kite/home/phil/install/hdf5-1.8.7

./configure –prefix=/home/phil/usr_owl –enable-hl –enable-shared –enable-cxx

/nfs/kite/home/phil/install/hdf5-1.8.7

./configure –prefix=/home/phil/usr_owl –with-hdf5=/home/phil/usr_owl/lib –enable-shared –disable-fortran

export HDF5_DIR=/home/phil/usr_owl

export NETCDF4_DIR=/home/phil/usr_owl

need pytz and old dateutil sudo easy_install python-dateutil==1.5 edit site.cfg

http://www.riverbankcomputing.com/static/Docs/sip4/installation.html#downloading

/nfs/kite/home/phil phil@owl% sudo update-alternatives –config qmake

~/install/PyQt-x11-gpl-4.8.5 phil@owl% qmake -v QMake version 2.01a Using Qt version 4.6.2 in /usr/lib

need to make install as root:

install -m 755 -p “libpythonplugin.so” “/usr/lib/qt4/plugins/designer/libpythonplugin.so” strip –strip-unneeded “/usr/lib/qt4/plugins/designer/libpythonplugin.so” make[1]: Leaving directory `/nfs/kite/home/phil/install/PyQt-x11-gpl-4.8.5/designer’

BUILDING MATPLOTLIB matplotlib: 1.2.x python: 2.7.2 (default, Oct 11 2011, 17:30:56) [GCC 4.6.1] platform: linux2

REQUIRED DEPENDENCIES numpy: 2.0.0.dev-ec56ee1 freetype2: 9.22.3

OPTIONAL BACKEND DEPENDENCIES libpng: 1.2.42 Tkinter: Tkinter: version not identified, Tk: 8.5, Tcl: 8.5 Gtk+: no

  • Building for Gtk+ requires pygtk; you must be able
  • to “import gtk” in your build/install environment

Mac OS X native: no Qt: no Qt4: Qt: 4.6.2, PyQt4: 4.8.5 Cairo: no

OPTIONAL DATE/TIMEZONE DEPENDENCIES datetime: present, version unknown dateutil: 1.5 pytz: 2011k

OPTIONAL USETEX DEPENDENCIES dvipng: 1.12 ghostscript: 8.71 latex: 3.1415926 pdftops: 0.12.4

ipython

hg clone https://bitbucket.org/robertkern/kernmagic ~/install/kernmagic phil@owl% python setup.py install

need development version of pyzmq don’t forget sudo ldconfig for zeromq

http://joseph.freivald.com/linux/2010/06/09/qt-4-6-3-and-qt-creator-1-3-1-1-updates-for-centos-5-5/

zeromq

http://joseph.freivald.com/linux/2010/06/09/qt-4-6-3-and-qt-creator-1-3-1-1-updates-for-centos-5-5/

linker problems with –enable-fortran

./configure –prefix=/home/phil/usr_owl –enable-hl –enable-shared –enable-cxx

/nfs/kite/home/phil/install/hdf5-1.8.7

netcdf

/nfs/kite/home/phil/install/netcdf-4.1.3 phil@owlf% export LD_RUN_PATH=/home/phil/usr_owl/lib

./configure –prefix=/home/phil/usr_owl –with-hdf5=/home/phil/usr_owl/lib –enable-shared –disable-fortran

export HDF5_DIR=/home/phil/usr_owl

export NETCDF4_DIR=/home/phil/usr_owl

need pytz and old dateutil sudo easy_install python-dateutil==1.5 edit site.cfg

http://www.riverbankcomputing.com/static/Docs/sip4/installation.html#downloading

/nfs/kite/home/phil phil@owl% sudo update-alternatives –config qmake

~/install/PyQt-x11-gpl-4.8.5 phil@owl% qmake -v QMake version 2.01a Using Qt version 4.6.2 in /usr/lib

need to make install as root:

install -m 755 -p “libpythonplugin.so” “/usr/lib/qt4/plugins/designer/libpythonplugin.so” strip –strip-unneeded “/usr/lib/qt4/plugins/designer/libpythonplugin.so” make[1]: Leaving directory `/nfs/kite/home/phil/install/PyQt-x11-gpl-4.8.5/designer’

BUILDING MATPLOTLIB matplotlib: 1.2.x python: 2.7.2 (default, Oct 11 2011, 17:30:56) [GCC 4.6.1] platform: linux2

REQUIRED DEPENDENCIES numpy: 2.0.0.dev-ec56ee1 freetype2: 9.22.3

OPTIONAL BACKEND DEPENDENCIES libpng: 1.2.42 Tkinter: Tkinter: version not identified, Tk: 8.5, Tcl: 8.5 Gtk+: no

  • Building for Gtk+ requires pygtk; you must be able
  • to “import gtk” in your build/install environment

Mac OS X native: no Qt: no Qt4: Qt: 4.6.2, PyQt4: 4.8.5 Cairo: no

OPTIONAL DATE/TIMEZONE DEPENDENCIES datetime: present, version unknown dateutil: 1.5 pytz: 2011k

OPTIONAL USETEX DEPENDENCIES dvipng: 1.12 ghostscript: 8.71 latex: 3.1415926 pdftops: 0.12.4

ipython

hg clone https://bitbucket.org/robertkern/kernmagic ~/install/kernmagic phil@owl% python setup.py install

need development version of pyzmq don’t forget sudo ldconfig for zeromq

http://joseph.freivald.com/linux/2010/06/09/qt-4-6-3-and-qt-creator-1-3-1-1-updates-for-centos-5-5/

ppl ~/install/ppl-0.11.2 phil@roc% ./configure –with-gmp-prefix=/users/user-soft –prefix=/users/user-soft/

gmp

~/install/gmp-5.0.2 phil@roc% ./configure –enable-cxx –prefix=/users/user-soft/

mpc-0.9 gmp-5.0.2 mpfr-3.0.1

cloog-ppl required autoconf to be run

~/install/autoconf-2.67 phil@roc% ./configure –prefix=/users/user-soft/ ~/install/cloog-ppl-0.15.11 phil@roc% /users/user-soft/bin/autoconf

~/install/cloog-ppl-0.15.11 phil@roc% ./configure –with-gmp=/users/user-soft –with-ppl=/users/user-soft –prefix=/users/user-soft

~/install phil@roc% tar xjvf gcc*2 mkdir gccobj

won’t find libcloog.so.0 unless you do this

~/install/gccobj phil@roc% export LD_RUN_PATH=/users/user-soft/lib

–prefix has to come first:

~/install/gccobj phil@roc% ../gcc-4.*1/configure –prefix=/users/user-soft –with-gmp=/users/user-soft –with-ppl=/users/user-soft –with-mpfr=/users/user-soft –with-cloog=/users/user-soft

netcdf4py

export NETCDF4_DIR=/users/user-soft/netcdfpgf90 export HDF5_DIR=/users/user-soft/hdfpgf90

reading/writing matlab files


from scipy import io as io io.savemat

writing npz files


with open(‘les_out.npz’,’w’) as f: np.savez(f,**npz_vars)

with idiom


with open(‘les_out.npz’,’w’) as f: np.savez(f,**npz_vars)

building pytables on roc


this setup mistakenly gives error that cannot find hdf5 shared library python setup.py install –hdf5=/users/user-soft/usr251_Centos –lflags=”-Xlinker -rpath -Xlinker /users/user-soft/usr251_Centos/lib”

using nose in a module


import nose.tools as nt

def setup_func(): f=open(‘testout.txt’,’w’) f.write(‘here i am\n’) f.close()

def teardown_func(): f=open(‘testout.txt’,’a’) f.write(‘bye bye\n’) f.close()

@nt.with_setup(setup_func, teardown_func) def test_b(): “”” Raw, unparented test. “”” print “running test_b” assert 1

class TestExampleTwo(object): def test_c(self): assert ‘c’ == ‘c’

if __name__== “__main__”: from numpy.testing.nosetester import run_module_suite run_module_suite()

using Agg backend


building PyNIO

start with hdfeos

./configure CC=/home/phil/usr64/libhdf4_25_gfortran_static/bin/h4cc

mv include files to /home/phil/usr64/libhdf4_25_gfortran_static/include/hdf

needed to install curl-config to get curl working

~/install/PyNIO-1.4.1 phil@owl% cat doit.sh export HAS_NETCDF4=1 export HAS_HDF4=1 export HAS_HDFEOS=1 export HAS_HDFEOS5=1 export NETCDF4_PREFIX=/home/phil/usr_owl export HDF4_PREFIX=/home/phil/usr_owl export HDF5_PREFIX=/home/phil/usr_owl export HDFEOS_PREFIX=/home/phil/usr_owl export HDFEOS5_PREFIX=/home/phil/usr_owl export HAS_SZIP=0 export CC=gcc export CXX=g++ export LD_RUN_PATH=/home/phil/usr_owl/lib #export CFLAGS=-m64 #export CXXFLAGS=-m64

http://www.pyngl.ucar.edu/Download/build_pynio_from_src.shtml#gctp

szip http://www.hdfgroup.org/HDF5/release/obtain5.html

hdfeos5 ./configure CC=/home/phil/usr_owl/bin/h5cc –enable-shared –with-hdf5=/home/phil/usr_owl –prefix=/home/phil/usr_owl

You will also have to hand-copy two include files:

cp include/HE5_GctpFunc.h include/HE5_HdfEosDef.h usr/local/include.

export LD_RUN_PATH=/home/phil/usr_owl/lib ldd ./build/lib.linux-x86_64-2.7/PyNIO/nio.so ldd /home/phil/usr_owl/lib/python2.7/site-packages/PyNIO/nio.so

hdf5: ./configure –prefix=/home/phil/usr_owl –enable-hl –enable-shared –disable-fortran –enable-cxx

netcdf4 http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-install/index.html http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-fortran-install.html

CPPFLAGS=-I/home/phil/usr_owl/include LDFLAGS=-L/home/phil/usr_owl/lib ./configure –prefix=/home/phil/usr_owl make -j 4 check install

mkdir -p /home/phil/usr_owl/pgi export DIR1=/home/phil/usr_owl export FC=pgf90 export F77=pgf77 CPPFLAGS=-I${DIR1}/include LD_RUN_PATH=${DIR1}/lib LDFLAGS=-lnetcdf ./configure –prefix=${DIR1}/pgi

hdf4: ./configure –includedir=/home/phil/usr_owl/include/hdf –prefix=/home/phil/usr_owl –enable-shared –disable-fortran

hdfeos ./configure –with-hdf4=/home/phil/usr_owl –enable-shared –prefix=/home/phil/usr_owl

go to src/Makefile and delete LDFLAGS = -Wl,-single_module

hdfeos5

./configure CC=/home/phil/usr_owl/bin/h5cc –prefix=/home/phil/usr_owl

go to src/Makefile and delete LDFLAGS = -Wl,-single_module

hdfeos5: cp cfortHdf.h HE5_HdfEosDef.h ~/usr_owl/include

hdfeos cp HdfEosDef.h ease.h ~/usr_owl/include

netcdf 3.6.3 mkdir -p /home/phil/usr_owl/netcdf3_pgi export DIR1=/home/phil/usr_owl/netcdf3_pgi export FC=pgf90 export F77=pgf77 ./configure –prefix=${DIR1} –enable-shared

mkdir -p /home/phil/usr_owl/netcdf3_gfortran export DIR1=/home/phil/usr_owl/netcdf3_gfortran export FC=gfortran export F77=gfortran ./configure –prefix=${DIR1} –enable-shared

getting configuration info


In [23]: numpy.distutils.__config__.show() lapack_opt_info: extra_link_args = [‘-Wl,-framework’, ‘-Wl,Accelerate’] extra_compile_args = [‘-msse3’] define_macros = [(‘NO_ATLAS_INFO’, 3)] blas_opt_info: extra_link_args = [‘-Wl,-framework’, ‘-Wl,Accelerate’] extra_compile_args = [‘-msse3’, ‘-I/System/Library/Frameworks/vecLib.framework/Headers’] define_macros = [(‘NO_ATLAS_INFO’, 3)]

netcdf install on newroc

./configure –prefix=/users/user-soft/netcdf_4.3.1.1_pgi

make install

fortran 4.2

export DIR1=/users/user-soft/netcdf_4.3.1.1_pgi CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

make install

openmpi install on newroc

newtera/tera/phil/shortruns phil@newroc% cat ~.mypgf90rc set NOSWITCHERROR=1;

./configure –prefix=/users/user-soft/openmpi_pgf90

/users/user-soft/openmpi_pgf90/bin/mpiexec -n 16 bin/SAM_CMAKE BOMEX

memmap for binary file read

””” use memmap to subset a large binary file

subset_stat.py BOMEX_cmake_ent_4.stat partial.stat 1 3 –recsize=360201 “”” import argparse, textwrap linebreaks=argparse.RawTextHelpFormatter descrip=textwrap.dedent(globals()[‘__doc__’]) parser = argparse.ArgumentParser(formatter_class=linebreaks,description=descrip) parser.add_argument(‘full_stat’,type=str,help=’top directory to list’) parser.add_argument(‘partial_stat’,type=str,help=’output name base’) parser.add_argument(‘left_limit’,type=int,help=’first record’) parser.add_argument(‘right_limit’,type=int,help=’last record’) parser.add_argument(‘–recsize’,type=int,help=’size of stat record’,default=360201) args=parser.parse_args()

from contextlib import closing import mmap nrecs=args.right_limit - args.left_limit outbytes=nrecs*args.recsize

with open(args.partial_stat,’wb’) as f: f.flush() f.write(‘\0’*outbytes)

with open(args.full_stat, “rb”) as infile: with closing(mmap.mmap(infile.fileno(),0,access=mmap.ACCESS_READ)) as input: input.flush() with open(args.partial_stat, ‘r+b’) as outfile: with closing(mmap.mmap(outfile.fileno(),0,access=mmap.ACCESS_WRITE)) as output: output.flush() in_start=args.left_limit*args.recsize infile.seek(in_start) output.write(input.read(outbytes))

installing libszip 2.1

./configure –prefix=/opt/local/gfortran48 make make check make install

# export CC=gcc ./configure –prefix=/opt/local/gfortran48 –enable-cxx –with-szlib=/opt/local/gfortran48 make j=10 make check

netcdf 4.3.1.1

export CC=gcc export DIR1=/opt/local/gfortran48 CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

#

#

export FC=pgf90 export F77=pgf90 DIR1=/opt/local/gfortran48 unset LD_LIBRARY_PATH unset LD_RUN_PATH #export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

#need to be austinp

export FC=ifort export F77=ifort DIR1=/opt/local/gfortran48 unset LD_LIBRARY_PATH unset LD_RUN_PATH #export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

export FC=gfortran export F77=gfortran DIR1=/opt/local/gfortran48 unset LD_LIBRARY_PATH unset LD_RUN_PATH #export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} export LDFLAGS=’-L${DIR1}/lib -lgfortran’ CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

export F77=gfortran export F90=gfortran DIR1=/opt/local/gfortran48 unset LD_LIBRARY_PATH unset LD_RUN_PATH #export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH} export LD_RUN_PATH=${DIR1}/lib:${LD_RUN_PATH} mkdir -p ${DIR1} export LIBS=’-lgfortran’ CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure –prefix=${DIR1}

gfortran -o outpha -I/users/austinp/install/nrecipes/recipes_f-90/recipes -L/users/austinp/install/nrecipes/recipes_f-90/recipes xpoldiv.f90 -lnr -lgfortran

pandas

move to new readme!

and check this out

test for scalar arguments

def test_scalar(*args): “”” return true if every argument is a scalar “”” isscalar=True for item in args: isscalar = isscalar & np.isscalar(item) return isscalar

isscalar = test_scalar(press,Temp,rt)

def itercheck(obj): return hasattr(obj, ‘__iter__’) and not isinstance(obj, str)

h5py how to write

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment