Skip to main content

Posts

Showing posts from March, 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 wh

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!

The time travelling Mac

Finder has a little bug:

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).

Getting clips from DVD

Sometimes I find howlers on DVD that I want to store. On a Mac the sequence is: Open the DVD in VLC and find out which title and chapter the clip is in. Use MacTheRipper to extract that title and chapter to .vob format 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: 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 .

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.

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 .