Friday, March 27, 2009

Psycho on Mac

svn co http://codespeak.net/svn/psyco/dist/ psyco-dist
sudo python setup.py install

Saturday, March 21, 2009

Maximum number of open files in Python

So here I was merrily writing a python module to extract neural data from the Cerebus system's giant .nevs file and split it into smaller files - one per neural unit. I had been extracting one channel at a time and all was well. So now I copy the code over to the lab machine and tell it to extract all the data and split it into 96*4 files.

Traceback (most recent call last):
File "convert_nev.py", line 11, in
File "/Users/kghose/Experiments/Python/nev.py", line 270, in fragment
IOError: [Errno 24] Too many open files: '../Neural/DJ2009/20090320//Frag//electrode64unit02.bin'


Whaaa? Whats all this? Well, it turns out you can't have too many files open at the same time. And the resource module can tell you exactly how many files you can have open at a given time:

resource.getrlimit(resource.RLIMIT_NOFILE)
(256L, 9223372036854775807L)


Which means the current soft limit is 256 files and the hard limit is some number so large only astronomers and people who write stimulus bills can deal with it. And so for my application, I can change the limit by doing:

resource.setrlimit(resource.RLIMIT_NOFILE, (500,-1))

(-1 means set the hard limit to the maximum possible)

Why I love matplotlib + python


Note this graph. The upper trace just goes from 0 to 1.6ms. The lower trace was a series of such waveforms ocurring from 0 to 10 s. I zoomed in to see one wave. When you do that in Matlab the tick labels would take the form 8.168, 8.169, 8.170 which is legitimate, but gets hard to read when you zoom in a lot and you get lost in the digits. Matplotlib, on the other hand, produces the zoom plot pictured here. It shows you the offset on the right (8.168) and then just shows you the vernier values. Now THAT is what I call service. The matplotlib guys are really good. Its like they actually use their product for data analysis. They must be scientists or something :).

Percent sign in python format string

From here: just use a % sign as an escape character.

so:

print '22%' works

print '%d' %(22) works

print '%d%' %(22) throws an error and the solution is

print '%d%%' %(22)

People say this is hacky. They 'fixed' it in Python 3.0 but I'm not upgrading soon. Imagine having to go through all your code because of this nonessential thing!

Sunday, March 15, 2009

Slow Matlab editor on Mac OS X

From macoshints:

If you've upgraded to Leopard and now find the IDE of the new Matlab release 2007b to be super-slow, create a file called java.opts in your /Applications/MATLAB_R2007b/ directory, and add the following line to it:
-Dapple.awt.graphics.UseQuartz=true
Then restart Matlab. This will switch Matlab back to using the Quartz drawing enginge (as it was in previous versions of OS X).

Saturday, March 14, 2009

Getting clips from DVD

Sometimes I find howlers on DVD that I want to store. On a Mac the sequence is:
  1. Open the DVD in VLC and find out which title and chapter the clip is in.
  2. Use MacTheRipper to extract that title and chapter to .vob format
  3. Open it up in VLC, note the seconds offset for the part of the clip we want and then use File->Streaming/Export wizard to export the clip. I use H.264 (3072 kb/s) for video and MPEG-4 audio and mp4 container.
Here's an example:

video
The what controls what again?

Muggles

I thought the author of the Harry Potter books invented the word 'Muggle' but I ran into it in Steinbeck's 'Sweet Thursday'. Couldn't figure out what it meant though.

Multiple versions of Rails

You can have multiple versions of Rails on the same machine.
You can tell your app which version of Rails to use by adjusting RAILS_GEM_VERSION in config/environment.rb
You can also freeze all the plugins etc that you use into your code tree before deployment rake rails:freeze:gems.

Friday, March 13, 2009

Installing analysis tools on a mac via commandline


ftp http://www.python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg
sudo hdid python-2.5.4-macosx.dmg
sudo installer -pkg /Volumes/Universal\ MacPython\ 2.5.4/MacPython.mpkg/ -target "/"
sudo /Applications/MacPython\ 2.5/Update\ Shell\ Profile.command ##!!!IMPORTANT!!!

ftp http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg
sudo sh setuptools-0.6c9-py2.5.egg

ftp http://ipython.scipy.org/dist/ipython-0.9.1-py2.5.egg
sudo easy_install ipython-0.9.1-py2.5.egg

ftp http://r.research.att.com/gfortran-4.2.3.dmg
sudo hdid gfortran-4.2.3.dmg
sudo installer -pkg /Volumes/GNU\ Fortran\ 4.2.3/gfortran.pkg/ -target "/"


ftp ftp://ftp.fftw.org/pub/fftw/fftw-3.2.1.tar.gz
tar -xvf fftw-3.2.1.tar.gz
cd fftw-3.2.1
./configure
make -j4
sudo make install

ftp http://downloads.sourceforge.net/numpy/numpy-1.2.1-py2.5-macosx10.5.dmg?use_mirror=internap
sudo hdid numpy-1.2.1-py2.5-macosx10.5.dmg
sudo installer -pkg /Volumes/numpy-1.2.1-py2.5-macosx10.5/numpy-1.2.1-py2.5-macosx10.5.mpkg/ -target "/"

ftp http://downloads.sourceforge.net/scipy/scipy-0.7.0-py2.5-macosx10.5.dmg?use_mirror=superb-east
sudo hdid scipy-0.7.0-py2.5-macosx10.5.dmg
sudo installer -pkg /Volumes/scipy-0.7.0-py2.5-macosx10.5/scipy-0.7.0-py2.5-macosx10.5.mpkg/ -target "/"

ftp http://downloads.sourceforge.net/matplotlib/matplotlib-0.98.5.2-py2.5-mpkg.zip?use_mirror=superb-west
unzip matplotlib-0.98.5.2-py2.5-mpkg.zip
sudo installer -pkg matplotlib-0.98.5.2-py2.5-macosx10.5.mpkg/ -target "/"

NOTE:

Wrong version of python: import pylab fails, import numpy gets 1.0.1: Doh! Forgot to set new path

  1. sudo /Applications/MacPython\ 2.5/Update\ Shell\ Profile.command #To set path to new python verion
  2. sudo sh setuptools-0.6c9-py2.5.egg #easy install should know of this
  3. sudo easy_install ipython-0.9.1-py2.5.egg
  4. sudo rm /usr/local/bin/ipython #To make sure
  5. logout and back in to have paths take hold

Tuesday, March 10, 2009

Archery meet!



The last end was the best end. Some people would be ashamed of this scoresheet. I am not one of them :) I had a lot of fun!

How much does Harvard Medical School cost?

From an email the tuition office sent out
  • $42,500 for academic year 2009-2010
  • the typical 2008 HMS student graduated with $115,500 of total educational debt, as compared with a national mean of $173,000
  • Parent contribution waived for families whose yearly incomes are $120,000 or less
  • Unit loan package for current and newly admitted students $24,500
  • For all students qualifying for the unit loan, the 2009-2010 package will continue to consist of loans that do not accrue interest while the student is in school
A more extensive breakdown of costs is here.

Friday, March 6, 2009

What happened to firefox?

I did the auto update and now it crashes on every second webpage. Bad browser, baad browser.