Skip to main content


Showing posts from 2007

Far Cry levels

After finishing far cry I was on the look out for more levels and mods. (Of course I'm drooling with anticipation for far cry 2). I found that Matto's mods/maps were amazing. I played Matto3 and had a lot of fun. Matto has injected a lot of wry humor into the scenery. Also, if you are the kind that investigates every corner of the map, you may receive unexpected "rewards" !

I found that filefront has a bunch of far cry mods and files and a terrible page layout. Here are the single player maps and mods. Always be careful with mods!

Now, I gotta try Matto 4!

Upgrading RRiki to Rails 2.0

Ok, in a moment of distraction I upgraded my Rriki setup to rails 2.0. Boom. It stopped working. Even the front page wouldn't work, giving me a 500 error. I looked through the log and found that it was some cookie thing and it was fixed by adding the line

config.action_controller.session = { :session_key => "_rriki_session", :secret => "some secret phrase of at least 30 characters" }

to the environment.rb file

I tried it again. Firefox would just not load, saying localhost was taking too long to respond. I went into panic mode trying out different things, untill I tried to load google and cnn. Neither worked. I restarted Firefox and got things back. But now I got a

undefined method `extract_options_from_args!'

error, even on the first page. I started to mess mess with my find syntax but decided that shouldn't be the problem. After looking at the error message closely I realised that even though I thought I had no strange (i.e. foreign, not written by …

Inkscape, vista and windows explorer

On vista, I've had this problem that windows explorer will suddenly crash. It restarts itself, but I have to reopen all the folders I've had open. Other people have had this problem. One condition that causes the crash is if I write a new .svg file to a folder that is open.

This page suggests to turn off the DEP, but that looks risky to me.
This page suggests turning off search indexing, but my indexing is off.

Opensource note taking software

Jarnal allows you to write notes on top of a pdf background (you can also use it as just a note taker). If you have a tablet pc bully for you, other wise you can type in notes on top of the pdf. It would be neat if you could embed this in a browser, say to use it from within Rriki.

Notelab is meant for tablet pc users to take notes on a digital note pad.

Beamer on MikTeX

Need xcolor and pgf for the new beamer to run. MikTeX kept failing on pgf install. Led to discovery of problem with MikTeX 2.6 and LZMA compressed package archive files. Had to update just the miktex-bin, then update the rest to get the latest package manager. Remember, don't have package manager and updater running at the same time - they access some same files and can lock each other out on windows.

MikTeX on vista

MikTeX works fine on vista, except on occasion if I don't run package manager as root I get a com surrogate error. I just start package manager as root (run as administrator) to get around this problem.

Odd error with mlab and lighting - TVTK

Is there a time delay to the lighting manager being instantiated when a figure is set up?

In ipython the following lines work fine

fig = mlab.figure(browser=False)

But this doesn't

fig = mlab.figure(browser=False);fig.renwin.light_manager.lights[0].move_to(0,-45)

In the noninteractive mode (i.e. running a script as opposed to typing in commands in the shell) even the first version does not work. I tried inserting a delay (time.sleep()) but that does not help

l = light_manager.CameraLight(fig.renwin)

Figure properties - TVTK

fig.renwin.off_screen_rendering = True #allows you to minimize the window and keep drawing/saving to file

.light_mode = 'vtk' or 'raymond'

light[0] seems to be the important one. azimuth , elevation, with 0 elevation being right over head

The rendering properties (size etc.) are controlled from

.aa_frames =

.size = array([width, height]) OR
.set_size(width, height)

fig.renwin.show_axes = True #turns on the little axis orientation indicator

Some important properties - TVTK

(For how to access object properties see this post)

fig = mlab.figure(browser = False)
s = mlab.Surf(x,y,z)

.representation =
'w' wireframe's' surface.opacity = 0...1
.interpolation =
'phong'.ambient = 0...1 #uniform (direction independent) lighting on surface
.color = [r,g,b]
.specular = 0...1
.specular_color = [r,g,b]
.specular_power =0...1

view manipulation - TVTK

You have to manipulate the camera which is a
enthought.​pyface.​tvtk.​decorated_scene.​DecoratedScene object

if fig is a figure window handle returned from mlab.figure() rotate scene by .. degrees rotate scene by .. degrees zoom in/out

remember to call fig.renwin.render() to see the changes

Setting surface rendering properties - TVTK

From a hint here

import scipy

x = scipy.arange(-7., 7.05, 0.1)
y = scipy.arange(-5., 5.05, 0.1)

[X,Y] = scipy.meshgrid(x,y)
Z = 3.0*scipy.sin(X*Y+1e-4)/(X*Y+1e-4)

from import mlab
fig = mlab.figure(browser = False)
s = mlab.Surf(X, Y, Z)

act = fig.objects[1].actors[0] #object[1] is the surface, it has one actor, which turns out to be a surface = 'w' #make it a wireframe = 's' #turn it back to a surface!

Getting mlab/ivtk/mayavi to work

Download and run Enthought Enstaller.
It pulls of various things from Enthought's website and installs them in the site-pacages etc. Crucially it will put enstaller.exe under \python25\ScriptsRun enstaller.exeIn the GUI tab to repositories and check Mavavi, VTK, enthought.traits, enthought.tvtk, wxPython
click install packageschange ipython to run with wthread commandline option (ipython -wthread)follow any number of examples from the cookbook for mlabeg:

from import mlab
fig = mlab.figure(browser = False)
mlab.test_surf(fig) #a built in test function for a nice looking surface

t = mlab.Title()#add a title object
t.text = 'Ha'

fig.pop() #remove the last added object (in this case the title) ='tada.png') #save the figure to png

Useful links:

Memory leaks in matplotlib

On windows, with Python 2.5 matplotlib has a memory problem using the default tk backend. Say I have to generate 100 figures in succession, dumping each to a file because I want to create and animation from them. Using tk the memory consumption just keeps increasing. The trick is to use the agg backend for such tasks (see this post). The agg backend does not have this memory leak.

A note on the bow stringer

The bow stringer I have came with instructions to step on the string with both feet about shoulder width apart. I didn't understand why, especially since some instructions elsewhere (and here) say to stand on the string with one foot. Today I think I figured out why, at least with my bowstringer.

The cup, which covers the upper tip, into which you are trying to slide the bowstring, has a tendency to cover the tip more and more closely, eventually pinching off the notch in the tip into which you need to slide the bowstring.

By standing with your feet apart, you cause the tension in the string to act more perpendicularly to the limb, and so the cup is less likely to slide inwards and cover the notch.

If you stand with only one foot on the stringer, or with feet close together, the string makes a shallow angle with the limb. This pulls the cup more tightly onto the tip, sliding it over the notch.

An additional benefit is that you are causing less tension in the bowstringer.

(Note that the…

Ditching blender for Alibre free edition

Ok, either I am doing something wrong or Blender really has a problem with stl export. When I export my models to stl I can load the models just fine in Myriad 3D viewer , but when I load them in Zcorp's Zprint the normals are wrong and they show up as wire frames and not solid models. Hyunyoung from the fab-lab suggested I try out Alibre Design Xpress, which is a free version of their CAD software. I got it to work with minimum hassle. The only thing I could not figure out how to do was sketch elipses!

I needed the latest JVM

Subplot with polar

If you want to do a polar plot in a subplot you will be surprised -
when you do subplot(1,2,1) (say) this sets up the axes in cartesian mode. You need to do

subplot(1,2,1,polar=True) to set the plot in polar mode

Setting up SVN repository on a linux machine

Refer to SVN manual at

What worked for me:

repositories created by
svnadmin create /path/to/repo/module

initial import via svn import module file:///path/to/repo/module -m "initial import"
make sure you have the following subdirectories in this initial folder that you import
trunk (all the code goes here)
tags (empty)
branches (empty)

local checkout:
svn checkout file:///path/to/repo/module/trunk module
Tortoise CVS checkout repository URL like:

User management for svn repositories
Initial setup:
groupadd svnusers #add a new group for svnusers
chgrp svnusers repo/ -R #repo is now under svnusers
chmod g=swrx repo/ -R #the directory tree is now writable by group

For each new svnuser with write access:
usermod -a -G svnusers newuser #add newuser to the svnusers group
id newuser #make sure it took

Rescind SVN write permission from a user
gpasswd -d newuser svnusers

Blender saga Part II

I used blender to make some 3D models that want to fabricate. When I went to do that today at the Device Realization lab, we found that the model was only displaying as a wireframe, with the faces not filled in. I checked with the free viewer from Myriad and the models seemed fine. I found this page that lists some free stl viewers.

Why you should hold the bow with an open grip

Today, while shooting some ends with my new bow, I finally figured out the major reason why archers are told to shoot with an open grip. I read stuff about vibration and shock etc., but I think the real reason has to do with how the string is pulled. As you pull the string you need to pull it perpendicular to the plane of the bow. If you hold the bow in a tight grip you can potentially pull the string to one side, rather than straight back. This will impart a lateral component to your arrow release, causing a lot of fish-tailing. If you use an open grip, no matter how you pull the string the bow will yaw so that the limbs are perpendicular to the pull. This will reduce fish tailing.

Backstroke of the west OR Gained in translation

A pirated version of "The revenge of the sith" apparently gained something in translation. This website has a list of screenshots from a Star Wars III DVD bought in china with hilarious closed captioning.

The title itself "Revenge of the Sith" has the interesting translation "Backstroke of the west", leading me to all sorts of conspiracy theories of how in Totalitarian China, the evil empire in Star Wars is called "The West"

Making a model using blender

Well written tutorials and documentation are found on the wiki.

Some tips:
Blender's top "menu bar" can be resized by dragging down, to reveal a preferences menu (Enable auto save on this menu, while you are at it)BUG: Blender 2.44 on windows, boolean operation : union is actually difference and vice versaCopying an object from one file to another (or even the same file). Remember: go into the 'OBJECT' subtree.Export to STL: Remember: blender exports the currently selected object.
Keyboard short cuts:

tab - switch between object and edit mode
a - toggle between select all and select none
b - box select, select a bunch of vertices by dragging
e - extrude
g - grab
m - move object to layer dialog box
s - scale
w - boolean operation menu
shift-k - scissors

Web frameworks with python

I was writing a tutorial for SNAIU when I started to wonder what facilities Python has for writing browser based GUIs. I know that R has Rweb. I have had a great experience with Ruby On Rails, writing RRiki to handle my note taking and reference management needs. So I started to look into what Python has by way of web frameworks.

The python wiki has two relevant pages: web frameworks and web programming. I was attracted to Pylons, because it was the closest to Rails. But for my app what I need is something closer to Rweb, where you can create webpages with links that call actual code and return results on the webpage itself. A browser based GUI!

If anyone knows of any such solution, please tell me. Meanwhile, I think Pylon is the closest I can think off.

2007.11.1 - and then I discover SAGE. It looks like Rweb enhanced. Looks very promising.

Archery quick tips

Some factoids/tips I found useful (and which may not apply to you!)
A toxophilite is a person who is devoted to archery
A right hand bow is held in the left hand and shot by a right eye dominant personAn adult taking up archery should start with a 30# or less bowFor target archery a bow with 30-40# is sufficientFor target archery 75gr points are sufficientA longer bow is more stable. For a medium height person a 62-66" bow is recommendedBow poundages are measured at 28" drawDrop-away arrow rests are meant for compound bows, not recurves, which use at most a plunger.Outdoor target archery ranges are from 30m to 90m

Resources for begining recurve archery

I took up archery with instruction books, rather than an instructor. Time will tell if that was smart. I read a lot of stuff from websites and some from books. In the UMD library I could not find an archery book more recent than some time in the 1970s ! I guess UMD is not big into archery!

I read the following books:

"Shooting the Bow", Larry C. Whiffen, The Bruce Publishing Co, Milwaukee 1946.
This is an instructional book with charming mid-20th century black and white pictures written in a charming and humorous mid-20th century style. It has hand illustrations for stance, grip etc. It has a one page chapter about correcting errors.

"Archery", Lorraine Pszczola, W.B. Saunders Co, 1976
This is meant as an instructional booklet for college/school archery programmes. Filled with illustrations about stance, and grip etc.

"Archery for beginners", John C. Williams, Contemporary Books, 1976
This was the one I referred to the most. The archers in bellbottoms are a hoo…

Regular expressions in SciTE

From the SciTE's documentation webpage, you need to check 'Regular expression' in the search dialog box, and then the regex parts of your search will be demarcated by \( and \). For example, to replace all occurences of AUTO_INCREMENT=??? where ??? is some number by nothing, you would set the Find box to be AUTO_INCREMENT=\([0-9]+\) and the Replace box would be untouched.


I took up archery recently, and I have really gotten into it. I've added some archery related links on the blog.

I started out cheap, since I was interested in it enough to want to buy equipment, but I didn't know if it would be a hobby that would stick.

No-brand fibreglass recurve bow 60", 30-35# pull at 28" -- $50 (esportsonline)

Shooting glove -- $10
Quiver -- $10
Arm guard -- $10
6 carbon express thunderstorm arrows -- $34
Points 75gr and 125gr - $12 total - (all from Basspro)

Total approx $125

The closest basspro shop did not carry cheap recurves (they were all selfbows, and looked very nice and something you would hang over your fireplace and cost something like $500). They carried a lot of compounds, and a few recurves for children (54" high and 9lbs draw). I found more stuff online.

Basspro is fine for most things and esportsonline service is fine.

The no-name recurve bow I got is an OK starter. It's a generic kind of ambidextrous bow that …

Perfect Chaos

matplotlib has a very artistic line color choice algorithm.

GUIs are evil

Well, not really. Like most things a GUI is neither good nor evil, but a shade of something in between. However, for a while, before I caught myself, I was spending large amounts of time writing GUIs for analysis. Time that would have been better spent writing analysis code and debugging it and documenting it and writing papers as a result of it. I taped a piece of paper in front of my desk that said 'NO GUIs' to remind myself.

Programming a GUIs is a time trade. Creating a GUI trades time now for time later. The catch is that the time later usually goes to an 'end user' rather than you.

When to write a GUI:
A GUI for MATLAB or Python is good for code that will be repeatedly used to run analysis by people who have no interest in knowing the underlying code.A GUI is good for tasks that have a strong visual component: this means analysis that is done by displaying data on screen on which you have to indicate things by clicking on them.Your analysis code is all finished and …

Loading matlab binary (.mat) files into python

It happens. You have old data in matlab .mat format or your colleagues insist, for some obscure reason, on using MATLAB. You need and from scipy.

X ='mydata.mat')

X now contains a dictionary whose keys correspond to the variable names saved in the original mat file.

Nested dictionaries seem to be a problem. A kind soul has a short set of methods that converts nested dictionaries here.


Look here (scipy cookbook) for how to handle mat files from recent versions of matlab

Gravity Pods

I was looking for a 'game' just like this!

Set your initial trajectory so that the projectile winds is way to the target following a iso-potential line. Adjust sources and 'sinks' of gravity to adjust the iso-potential lines so that your projectile hits the target.

Betch'a didn't even think of iso-potential lines as you were busily setting up that rube-goldberg contraption!


Bloxors is a great puzzle game. Play it between neural recordings, behavioral training sessions, when you take a break from writing that paper and when the reviewers make you mad.

The fun in bloxors comes from the fact that your footprint (how many floor blocks you block occupies) varies with the moves you make. You start 'standing up' and must end, standing up, over the gap, so you fall in.

Step -1
You must aim, therefore, to be 'lying down' next to the gap, with your footprint in one of the four cardinal squares (North, South, East or West), radially, such as:


Step -2
Work backward from such configurations in terms of rolling or tumbling, till you get to your current starting point.

This puzzle has enough degrees of freedom and enough constraints to make it fun.

The teleporter adds some spice, though I think it is an unnecessary complication.

My Codes:

Making a poster using Inkscape

Inkscape turned out to be great for making my Vancouver poster. The following things were not so great
Export to pdf is bloated. My poster on export came to 303 MB(!). Using the 'reduce file size' option in acrobat resulted in a 2.3 MB file. Obviously Inkscape is doing something screwy here.Export to pdf does not honor image clipping. I was using rectangles to mark out a part of an image (an equation screen shot from latex pdf output) and the clip the image. The clipping worked fine in SVG, but when exported to pdf the entire figure was visible, not just the clipped part.
Obviously, I was doing this because Inkscape does not have good equation support. There are two plugins that use pstoedit to convert latex dvi output to svg, but I could not get it to work on my windows machine.I just learnt about Scribus, and wonder if that would be a better poster making tool

Opensource Workflow

My efforts to shift my work flow to rely more on open source tools has been going relatively smoothly. My current work flow is
Create figures using python and pylab (matplotlib)Save the figures in svg format from pylabImport the svg figures into inkscape and annotate them (eqtexsvg to insert latex equations)Save the figures as pdfInclude them in my latex source and compile with MikTeX I'm currently using inkscape to make my Vancouver poster. Its better than powerpoint, but I have problems with text formatting e.g. bullets

Using PCA in MDP

I found mdp on sourceforge. I needed to do PCA for some of my simulations. The mdp.pca function is easy to handle. The input is a m x n matrix, n is the dimension of the space, and m are the observations (rows = observations, cols = dimensions. The doc string is confused as to this point)

The output is a matrix also m x n, but the vectors have been transformed, so that the first column is along the direction with greatest variance etc.

An example is below:

import pylab as m
import matplotlib.axes3d as m3
import mdp

x1 = m.rand(10,3)
x2 = m.rand(10,3) + m.array([[2.,-2.,0.]])
x = m.concatenate((x1,x2))
y = mdp.pca(x)

fig = m.figure()
ax = m3.Axes3D(fig)
ax.scatter3D(x[:10,0].squeeze().T, x[:10,1].squeeze().T, x[:10,2].squeeze().T, marker = '^')
ax.scatter3D(x[10:,0].squeeze().T, x[10:,1].squeeze().T, x[10:,2].squeeze().T, marker = 'o')
m.axes([.7, .8, .2, .2])
m.plot(y[:10,0], y[:10,1],'k^')
m.plot(y[10:,0], y[10:,1],'b.')

Custom colormaps

From an excellent post here , we have a clear explanation of how to make custom colormaps. Under matplotlib there is a colors module which has a method called LinearSegmentedColormap that can create a colormap for your use.

First you need to make a color dictionary which looks like this:
cdict = {
'red' : ((0., 0., 0.), (0.5, 0.25, 0.25), (1., 1., 1.)),
'green': ((0., 1., 1.), (0.7, 0.0, 0.5), (1., 1., 1.)),
'blue' : ((0., 1., 1.), (0.5, 0.0, 0.0), (1., 1., 1.))
For each 'primary' additive color (rgb) you have to specify a tuple (...) which inturn is a collection of triples. Each triple defines a pivot point for that color in your color map.

The triple (0.7, 0.0, 0.5) for instance, means for 'green' when the normalized value is just below 0.7 the green component should be 0.0, and just above 0.7 the green component should be 0.5. This of course creates a discontinuity in the map at 0.7. To make a continuous map all the pivot points should have the…

Pretty picture

String formatting

String formatting is weird in Python, but rumor has it that Python 3000 will break backwards compatibility and fix that. Currently (Python 2.5) you do this
x = 'Rabindranath Tagore'
y = 1861
z = 80.25
print '%s was born in %d and lived %2.2f years' %(x,y,z)
Weird, ain't it?

Incidentally, python has no 'num2str' like matlab, so this is how you do it

Latex and SVG export

Pylab will render LaTeX equations (yeehah!). But there are glitches when the figures are saved to svg. First, you have to take the BaKoMa fonts (TrueType version of the Computer Modern fonts) located in the "matplotlib/mpl-data" dir (the cm*.ttf files) and install them. Now you can see the glyphs. However, the subscripts and superscripts are messed up (inverted). Which can be fixed in Inkscape, but eats time.

Thanks to Edin Salkovic on the [Matplotlib-users] list

Figures : plot without showing

Now why would you want to do that? Well, you could want to run a script on a remote machine from a (non graphical) terminal and just save the figure to a file, which you then retrieve. In my case I was making animations of simulations and wanted to do the animation on a remote machine, stitch the images together using mencoder and just retrieve the resultant movie file. At the top of the file add the linesimport matplotlib as mp
mp.use("Agg") This causes the Agg backend to be used.Thanks to Christopher Barker of NOAA for this.

Indexing or 'Slicing'

In Python, indexing is called slicing. It took me a while to catch on. Slicing an array is the same as MATLAB, except indexes are C indexes (start at 0). index -1 is last element, -2 penultimate etc.


In MATLAB when ever I had to make arrays of inhomogeneous data I would use arrays of structs. In Python 'Lists' can be used for that. Lists are indexed containers for any mixture of data. So for instance, I need to store event times for a series of nodes. The nodes go from 0..N-1 and each node has an array of event times (that can also be a zero length array) In Python we initialize this list of lists as ras = [[]]*N #empty list with N elements
ras[9] = [2, 4] #10th node now has two events 2 and 4
ras[9].append(4) #and now a third event 4

Reload of module after modification

If you change the code to a module, unlike MATLAB, Python will not use the new code. Even typing 'import' again will not refresh the code. You need to do 'reload(module)'
If you have a module that loads other modules and you are in the interactive session you will need to either put in 'reload's in the importing module or import and then reload it manually in the interactive session

Class variables, instance variables, local variables

Try out the following pieces of code #Instance variable
class A:
def __init__(self):
self.x = 22

a = A()
print a.x

#Local variable, only accessible inside init and vanishes afterwards
class A:

def __init__(self):
x = 22

a = A()
print a.x

#x is an instance variable
class A:

x = 22
def __init__(self):
return None

a = A()
b = A()
a.x = 15
print a.x, b.x

Split statements across multiple lines

Use backslashes '\'. Like a = \
22 + \
99 You only need backslashes for multi-line statments that could have been interpreted as a sequence of single line statements. So if you are entering a list of arguments to a function you can break it across multiple lines without back slashes because Python expects an argument list to end with a close parentheses.

Equivalent of switch statements

There is no native switch statement in Python. However the following construct does the job (based on code here: result = {
'case a': function1,
'case b': function2,
'case c': function3
}[value](parameters) This is a code dictionary that matches 'value' with the keys and then executes (returns) the respective functions.Another way is to use a sequence of if and elif statements

New style classes and slots

By typing in 'object' in a class declaration (see below) we create a new style class. (In Python 2.5 default classes are old-style objects). My use for new-style classes was the __slots__ feature. Python normally uses a dictionary __dict__to store the available attributes of a class. Therefore an object's footprint in memory is the memory required to store the attributes plus memory for the lookup dictionary. In a new-style class we can instruct Python to not use the dictionary, and reserve slots for attributes in the declaration. This reduces memory use by getting rid of __dict__, and is useful if you have large numbers of a class. class Synapse(object):
"""This stores the parameter data for the synapses as well as routines for file I/O of the parameters"""
__slots__ = ('id','sourceneuron','g_max','E','alpha','beta','T_max','t_pulse')

def __init__(self):

Essential software

Pylab - Nicotine patch for MATLAB junkies. Plot data better than in matlab. Save to SVG. Annotate in Inkscape. Publish in paper.winpdb - Python's weak point is debugging. This helps a bitipython - Good old interactive command line. With autocompletion! (hit tab) Don't forget to download pyreadline toopygtk - For GUIs. Haven't used it much, but it is nice.

In the begining...

As I was coding in python for my simulation project I tried to maintain a document of what I learned first as a text file, then as a html file. It all got too messy and cumbersome. I needed to organize each snippet of information for quick retrieval. I needed a database. But I was too lazy to setup a database. Then I thought, why not start a blog about it? So here we are. To be precise, we are here (*).