Sunday, September 27th, 2009

Updating NumPy, SciPy, and Matplotlib

I recently upgraded to NumPy to 1.4.0.dev7419, SciPy to 0.8.0.dev5953, and matplotlib version 0.99.1.1.

svn co http://svn.scipy.org/svn/numpy/trunk numpy
cd numpy
python setup.py build
python setup.py install
cd ..

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

python
>>> import numpy
>>> numpy.__version__    # '1.4.0.dev7419'
>>> numpy.test('1','10') # 26 errors in 2231 tests, but usable
>>> import scipy
>>> scipy.__version__    # '0.8.0.dev5953'
>>> scipy.test('1','10') # 165 errors in 4515 tests, but usable

rm -rf /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib*
wget http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99.1/matplotlib-0.99.1.1.tar.gz/download
open matplotlib-0.99.1.1.tar.gz
cd matplotlib-0.99.1.1
python setup.py build
python setup.py install
cd ..

ipython -pylab
>>> plot([1,2,3])

/developer   〆   permalink

Monday, July 13th, 2009

Python Link Roundup

Intra-package References

I just found out that Python 2.5 or newer allows relative imports, something I had been writing custom code to work around. Python documentation gives examples in 3 forms:

from . import echo
from .. import formats
from ..filters import equalizer

Packaging Tools

Alex Clemesha explains modern python hacker tools virtualenv, Fabric, and pip. I find all three of them intersting.

pip is an alternative to easy_install where you can install and upgrade python packages easily with commands like:

pip install -U ipython

Fabric facilitates deploying code to a remote location.

virtualenv lets you setup and manage working environments that aren’t littered with everything you ever installed into your global site-packages directory.

I also recommend virtualenvwrapper, which puts a nice interface on top of virtualenv.

/developer   〆   permalink

Thursday, March 12th, 2009

Ophthalmology Explained: What are those numbers in an eyeglasses prescription?

After visiting the Ophthalmologist yesterday, I received a prescription for corrective lenses with some crazy numbers on it. It looked something like this:

        SPH    CYL  AXIS
O.D.: -1.00  +0.75   180
O.S.: -1.25  +0.75   165

What does all that mean? I turned to the Wikipedia explanation for answers.

It turns out that this is a precription for distance vision only (near vision corrections are usually not necessary for a 25-year-old).

What are the abbreviations?

  • O.D. abbreviates oculus dexter, Latin for “right eye”
  • O.S. abbreviates oculus sinister, Latin for “left eye”
  • SPH stands for spherical diopter units
  • CYL stands for cylindrical diopter units
  • AXIS defines the angle of the CYL correction in degrees

The spherical component is the main correction as it acts equally to correct blur in all directions. The cylindrical component corrects blur in only one direction — therefore it is useful in correcting astigmatism. The axis angle defines the direction of the necessary cylindrical correction.

/life   〆   permalink

Sunday, February 1st, 2009

My Hat Size

Future me, your head is 22 5/8 inches around, making you a hat size 7 1/4. You will thank present me for that information one day.

/life   〆   permalink

Saturday, January 31st, 2009

Agreed. Git is Awesome.

I agree with every word in Fine. Git is Awesome.

/developer   〆   permalink

Saturday, January 17th, 2009

Mercurial and Git Links

Useful Mercurial Setup suggestions from Ted Naleid.

Daily Git tips at git ready.

/developer   〆   permalink

Saturday, January 3rd, 2009

Introducing numpyIO.py

I implemented numpyIO.py because I often use scipy.io.numpyio.fread() and scipy.io.numpyio.fwrite(), but I don’t want to depend on scipy. It uses numpy’s tofile/fromfile functions instead.

Why might you want this instead of SciPy’s numpyio? Well, I can think of a few reasons:

  • it imports faster because it only depends on numpy, not scipy
  • easier to package with py2exe or py2app
  • it is slightly faster
  • it lets you avoid rewriting legacy code that makes extensive use of scipy’s deprecated fread/fwrite

Grab the numpyIO project from bitbucket or clone the repo with:

hg clone http://bitbucket.org/lannybroo/numpyio

/developer   〆   permalink

Saturday, January 3rd, 2009

Updating to Python 2.6 on Mac OS X Leopard 10.5.6

Install Python from source.

cd ~/tmp
wget http://www.python.org/ftp/python/2.6.1/Python-2.6.1.tgz
untar Python-2.6.1.tgz
cd Python-2.6.1
mate Mac/README
./configure --enable-framework
make
make install
cd ..

Update setuptools so that easy_install works.

wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c9-py2.6.egg
sh setuptools-0.6c9-py2.6.egg

Add the following to my .profile so that the binaries installed by easy_install take precedence over my old Python 2.5 stuff.

export PATH=/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH

Easy install various packages I use frequently.

easy_install IPython
easy_install nose
easy_install pexpect
easy_install cheetah
easy_install clonedigger
easy_install pyserial
easy_install markdown2
easy_install euclid
easy_install psyco

Do the slightly tougher installs: NumPy (svn rev 6271), SciPy (svn rev 5300), matplotlib, and euclid. See http://www.scipy.org/Installing_SciPy/Mac_OS_X for details. Before starting, I also updated to the latest apple developer tools, although this isn’t strictly necessary.

wget http://r.research.att.com/gfortran-4.2.3.dmg
open gfortran-4.2.3.dmg # install using GUI

wget http://www.fftw.org/fftw-3.2.tar.gz
untar fftw-3.2.tar.gz
cd fftw-3.2
./configure
make
sudo make install
cd ..

svn co http://svn.scipy.org/svn/numpy/trunk numpy
cd numpy
python setup.py build
python setup.py install
cd ..

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

python
>>> import numpy
>>> numpy.test('1','10') # 6 problems in 1897 tests, but usable
>>> import scipy
>>> scipy.test('1','10') # 168 errors of 3990 tests, but usable

sudo port install libpng
sudo port install freetype
easy_install matplotlib

ipython -pylab
>>> plot([1,2,3])

svn checkout http://pyeuclid.googlecode.com/svn/trunk/ pyeuclid
cd pyeuclid
python setup.py install
cd ..

Install wxPython and PythonCard for GUI development.

wget http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-unicode-2.8.9.1-universal-py2.6.dmg
wget http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-docs-demos-2.8.9.1-universal-py2.6.dmg
open wxPython2.8-osx-unicode-2.8.9.1-universal-py2.6.dmg
open wxPython2.8-osx-docs-demos-2.8.9.1-universal-py2.6.dmg

wget http://prdownloads.sourceforge.net/pythoncard/PythonCard-0.8.2.tar.gz
untar PythonCard-0.8.2.tar.gz
cd PythonCard-0.8.2
python setup.py install
open /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PythonCard/samples/minimal/

Then, Ctrl-click and open minimal.py with Python Launcher to test.

/developer   〆   permalink

Tuesday, December 23rd, 2008

Hi-Def Video Playback on Windows

Jeff Atwood’s great tips on Hi-Def video playback for Windows.

/tech   〆   permalink

Sunday, November 30th, 2008

Git-SVN Cheat Sheet

Set good “don’t mess with my line endings” option before first checkout:

git config --global core.autocrlf false

Do this one time to suck in the repo w/history from SVN:

git svn clone svn://myrepo.com/project/

Do this loop over and over until your code ready to push back to SVN. The cool thing about this is that the adds and commits can be done off the network! Don’t forget to merge and re-test your changes after the rebase:

git add .
git commit -m "Added some awesome stuff"
git svn rebase

Push all local changes back to the SVN repo, which will now have all the local commits you did when you were on the airplane:

git svn dcommit

One other key tip is what when you want to decommit or rebase but you are in the middle of some changes, don’t worry. git-stash to the rescue:

git stash
git svn rebase
git stash apply

Also, here are a few links that inspired this post:

/developer   〆   permalink

Sunday, November 30th, 2008

Speedy Python

A great reference: Tools for Accelerating Python. I learned about quite a few new ways of getting Python code to run faster …

/developer   〆   permalink

Sunday, November 30th, 2008

Git Link Roundup

I’ve been working more with git lately and have found a few more interesting sites I’d like to share.

The Git Community Book is a great quick reference for finding out how to use a command if you can’t recall from the man page.

If you want to really understand the gory details of branching and merging with git (and I do highly recommend understanding them … easy branching is the best part of git coming from a svn background), then read this long article on LWN.net.

Also, R. Tyler Ballance has a series of blog entries on moving his team from subversion to git. I especially liked Team Development with Git which details the bad habits of developers that are just becoming familiar with distributed source control.

The Battery Powered blog tells us how to deploy a Git Repository Server in Ubuntu, which may prove useful soon. Currently, I’m just using Git for my local work and then pushing to a SVN repo, but I’d like to move others to Git soon.

scie.nti.st also explains how to host a Git repo. Both this and the Battery Powered link above use gitosis to make setup easier.

/developer   〆   permalink

Monday, October 6th, 2008

Decent Python References

I’ve been doing some more Python development lately. Wanted to document the following decent references online.

/developer   〆   permalink

Sunday, September 14th, 2008

Amanda’s Marathon Training Video

Amanda and I are running the Chicago Marathon this year. We’re hoping our friends will want to come watch us run on Sunday, October 12!

We are running as part of a fundraising group that supports the Chicago Children’s Memorial Hospital. So, Amanda made a fun video showing her unique Rocky Balboa training methods.

Anyway, hope you enjoy the video. If you like it and want to sponsor us, head to Amanda’s donation site and make a pledge to support her. Or, you can pledge to support me here.

Watch below, or check it out in HD on YouTube.

/life   〆   permalink

Monday, June 30th, 2008

Announcing Haiku Of the Day (HOD)

I helped put together a simple website and RSS feed of Haiku published by Bronze Man Books. Read the announcement or check out today’s haiku of the day!

/web   〆   permalink

Saturday, May 10th, 2008

Run Your Software on Your GPU

Check out GPULib from Tech-X Corp. It gives you the ability to run mathematical functions on your GPU card (certain NVIDIA models only, as the moment). Includes a blog and bindings for Python (pystream) and MATLAB.

/developer   〆   permalink

Tuesday, May 6th, 2008

Idiomatic Python, the Cheese Shop, PyEuclid

Today is becoming python link day, so here are a few more:

  • Idiomatic Python has some great tips on how to use python as it was intended.
  • The Python Package Index is a good place to look for code someone has already written that might solve the problem you’re thinking about, and probably in a much cleaner way than you were thinking. This used to be known as the Cheese Shop.
  • pyeuclid is a nice 2D/3D vector, matrix, and quaternion math library (that needs better docstrings and a ray-sphereoid intersection).

/developer   〆   permalink

Tuesday, May 6th, 2008

Numpy for MATLAB Users

Great reference for those of us recovering from a MATLAB addiction, like this guy, who recently moved his scientific workflow to Python.

/developer   〆   permalink

Thursday, May 1st, 2008

Python-by-example

Straight-forward Python reference the explains the standard library rather completely and cleanly just by showing a simple example for each module and function. Very nice for a quick lookup of something you don’t quite remember.

/developer   〆   permalink

Monday, April 28th, 2008

Universal Sole 10

Amanda, Shayna, Mark, and I ran the 10-mile Universal Sole race in Lincoln Park yesterday. Here’s an excerpt with our times (full results):

O'All No. Name   Div/Tot  Rank 5 Mile  Pace  Finish    Pace 
===== === ====== ======== ==== ======= ===== ========= =====
  788 369 MARK   103/120   960   49:11  9:51 1:33:00.4  9:19
  883 155 ALAN    57/66    961   49:12  9:51 1:35:53.2  9:36
 1148 370 SHAYNA 119/130  1181 1:00:52 12:11 1:56:42.8 11:41
 1149 156 AMANDA 120/130  1182 1:00:53 12:11 1:56:44.4 11:41

/life   〆   permalink

Thursday, March 13th, 2008

Installing IPython, SciPy, and Matplotlib into Apple’s Python on upgraded Leopard

Start by reading this reference and some tips at MacResearch.

Because it obscures the nice Leopard python that includes Numpy and Dtrace, remove your old Python completely.

sudo rm -rf /Library/Frameworks/Python.framework/

Check that NumPy is already installed and working.

python
import numpy
numpy.test(1,10)

Install latest IPython, version 0.8.2. Note that I always alais untar='tar xvzf' in my bash setup.

wget http://ipython.scipy.org/dist/ipython-0.8.2.tar.gz
untar ipython-0.8.2.tar.gz
cd ipython-0.8.2
sudo python setup.py install

Install a fortran compiler binary because it is needed to compile/install Scipy. I get the PPC version of gfortran. You can also find the Intel version at HPC Mac OS X.

wget http://internap.dl.sourceforge.net/sourceforge/hpc/\
gfortran-ppc-leopard-bin.tar.gz
sudo tar -xvf gfortran-ppc-leopard-bin.tar.gz -C /

Edit a disttools file in Apple’s NumPy distribution so it is more lenient in allowing the use of the above gfortran compiler when building SciPy. Inspired by this note.

cd /System/Library/Frameworks/Python.framework/Versions/2.5/\
Extras/lib/python/numpy/distutils/fcompiler
sudo cp -p gnu.py gnu.py.bak

And edit the following lines as follows (I use mate gnu.py to edit in TextMate).

- version_match = simple_version_match(start=r'GNU Fortran (?!95)')
+ version_match = simple_version_match(start=r'GNU Fortran')
- version_match = simple_version_match(start='GNU Fortran 95')
+ version_match = simple_version_match(start='GNU Fortran')

Build and install SciPy 0.6.0. Source available here.

wget http://internap.dl.sourceforge.net/sourceforge/scipy/\
scipy-0.6.0.tar.gz
untar scipy-0.6.0.tar.gz
cd scipy-0.6.0
sudo python setup.py install

This installs SciPy here: /Library/Python/2.5/site-packages/scipy, which isn’t seen by Python at first. I added the following to my .profile.

export PYTHONPATH="/Library/Python/2.5/site-packages"

Test it after closing your terminal and re-opening. I actually have 2 failures and 3 errors, but they are things I don’t care about at the moment.

python
import scipy
scipy.test(1,10)

Install matplotlib binary.

wget http://internap.dl.sourceforge.net/sourceforge/matplotlib/\
matplotlib-0.91.2-py2.5-macosx-10.3-fat.egg
sudo easy_install -N matplotlib-0.91.2-py2.5-macosx-10.3-fat.egg

Test it out and be happy that you’re done!

ipython -pylab
plot([1,2,3])

/mac   〆   permalink