Higher much higher

The only blog not featuring an ipod.

How to solve the bounding box problem with matplotlib generated eps files

The situation is the following: you generate an eps file using matplotlib and then import it into a latex document which you compile to pdf. Some viewers have no problems with it, other's refuse to open it (old versions of chrome's viewer on macosx, for example). Furthermore, some  latex compilers will crop / truncate the image when converting it to pdf as an intermediate step.

I have come across this scenario when doing a submission using manuscriptcentral that included some plots generated in matplotlib, which were quite large in size. Smaller plots seem to have no problem. The compiler on the site generated the proof pdf with the large images truncated on the left. Rotating the image in latex didn't solve the problem.

Apparently, the way compilers and viewers handle postscript bounding boxes that have corners with negative coordinates is inconsistent and has been so for over 10 years.  One way to go around it, taken from here, is the following:

suppose the offending file is called  plot.eps

  gs -o testaa.pdf -sDEVICE=pdfwrite -dEPSCrop plot.eps 
  gs -o plot.eps -sDEVICE=epswrite testaa.pdf 

gs is the command for ghostscript, a decades old compiler viewer for postscript and related files. It is available both for debian and windows, at least. 

networkx gephi and graphml: missing node attributes

You are exporting graphml files using networkx, loading them into gephi and not being able to see all the attributes your node has?
read on!

There's one dirty secret of gephi: some attribute-id's of graphml files have reserved status.
The problem is, networkx's write_graphml function produces id's that, sometimes, fall into this category.
Here's the scenario:

You create a graph with networkx and put attributes into the nodes using them as dictionaries.

let G be some networkx graph object with num_nodes nodes and let attMatrix a num_attributes x num_nodes (numpy) matrix that contains some numbers you want to put on the nodes

for v in V:
for i in range (num_attributes):
G.node[v][str(i)] = int(attMatrix[i,v]);

networxx.write_graphml(G, "myGraph.graphml")

It turns out, if num_attributes >=4  then there's going to be one attribute you won't be able to use.. the fourth. If you peak into the graphml you will see that that attribute is assigned  id="d3" which gephi chooses to ignore.

The simplest workaround:   open your graphmlfile and replace all id= with idd= 

The slightly better workaround: open  networkx/readwrite/graphml.py  and change, in line 260  new_id = "d%i" % len(list(self.keys))     to   new_id = "dd%i" % len(list(self.keys))
then reload networkx module and re-export (you might have to re-start python altogether). This makes more sense if you are going to be exporting more graphs.

There is, for sure, a better workaround: modify the  write_graphml function so that it accepts this "d" or "dd" as a parameter. But that should be done by the networkx people, I guess.

Bias at its best

The set of numbers within [0,1] that are not normal has Lebesgue measure 0. Thus, if one picks a number in the unit interval at random, it is almost sure that it is normal. However, the set of known normal numbers (for which we know the decimal expansion, i.e. excluding those with an uncomputable one) is rather small. So, if mathematics is to be regarded as a sampling process, it is an extremely biased one.

Installing ctrax on Ubuntu 11.04 Natty OR Debian jessie / wheezy [Updated 2014.07.14]

Ctrax is a video tracking software developed specifically to track trajectories of fruit flies.

Currently (Jan 2012), there are packages available for Ubuntu 10.04. If you want to install it in 11.04 you can't use those packages, you will get an error. My solution is the following.

This solution also works "as is" on debian whezzy, using ctrax version 0.5.0-1_amd64.deb (July 2014).
If you are running debian jessie, you might run into a couple of problems, whose workarounds are marked in bold below.

1. First some prerequisites and one package you Can install:
sudo apt-get install equivs python-setuptools python-dev python-matplotlib python-scipy python-wxgtk2.8 libavbin0

     Note: If you are trying this in debian Jessie, libavbin0 is not available for this version of the distro. You have to1. set up the sid repositories on your apt sources and run apt-get update2  install ONLY libavbin0, (apt-get install libavbin0)3. remove the sid repositories from your apt sources4. install the rest of the packages with sudo apt-get install equivs python-setuptools python-dev python-matplotlib python-scipy python-wxgtk2.8 

2. Get the latest version of ctrax from here. I tried this on 0.3.0-1_amd64 and 0.3.2-1_amd64.deb and 0.5.0-1_amd64.deb
Place it in a certain folder, say ~/ctraxinst and

cd ~/ctraxinst

3. Now, since this package depends on some python packages which are not available (or not in the correct version) for 11.04, it is necesary to install them by hand:

sudo easy_install motmot.wxvideo
sudo easy_install motmot.wxglvideo
sudo easy_install motmot.wxvalidatedtext
sudo easy_install motmot.imops
sudo easy_install pygarrayimage
sudo easy_install pyglet

4. This installs the python packages, the problem is that since they were not installed using the packaging manager, when we try to install ctrax it will report unmet dependecies. Here comes the dirty part, we will make some dummy packages and trick the packaging system into thinking this python modules are installed, well, not tricking because they actually are, lets call it, informing it of their installation.

mkdir fakes
cd fakes
equivs-control python-motmot-wxvideo
equivs-control python-motmot-wxvalidatedtext
equivs-control python-motmot-wxglvideo
equivs-control python-motmot-imops
equivs-control python-pygarrayimage
equivs-control python-pyglet

This will create six files named as the packages, in side each of them is the information on the respective fake package, we just need to edit one line in each of them. For example

nano python-motmot-imops

and make sure the 8th line says:

Package: python-motmot-imops

(this means you have to replace the defaults with line

Now you can actually build the packages

equivs-build python-motmot-wxvideo

equivs-build python-motmot-wxvalidatedtext
equivs-build python-motmot-wxglvideo
equivs-build python-motmot-imops
equivs-build python-pygarrayimage
equivs-build python-pyglet

this makes six .deb files which can be installed

sudo dpkg -i python-motmot-wxvideo_1.0_all.deb
sudo dpkg -i python-motmot-wxglvideo_1.0_all.deb
sudo dpkg -i python-motmot-wxvalidatedtext_1.0_all.deb
sudo dpkg -i python-motmot-imops_1.0_all.deb
sudo dpkg -i python-pygarrayimage_1.0_all.deb
sudo dpkg -i python-pyglet_1.0_all.deb

5. And now you can install the ctrax file you downloaded

sudo dpkg -i ../python-ctrax_0.5.0-1_amd64.deb

That should do the trick :)

NOTE:  In Debian jessie you might get an error, when running Ctrax, about matplotlib not finding one of its libraries. 
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/tkagg.py", line 2, in
    from matplotlib.backends import _tkagg
ImportError: cannot import name _tkagg

I don't fully understand what the backends of matplotlib are, but one workaround for this is to use another backend. This can be done by editing matplotlib's config 
  sudo nano /etc/matplotlibrc
and changing the line backend      : TkAgg so that it reads:
   backend      : QT4Agg

This should do the trick.

50 años.

De vivir en el futuro.

Xeon 5620 lm-sensors, problems with coretemp

I post this here because of lack of a better place to get it visible to search engines.

If you are trying to get lm-sensors to work on Debian with a E5620 Xeon or two, you will probably get an error about no sensors found (even after going trough sensors-detect). If you try to manually load the modules required, you will see that an error pops up when trying to load the coretemp module. Something about "devide not found".

The solution is simple, you must install kernel 2.6.37-2-amd64. This cannot be done if you are running either stable or testing. You must use the unstable repositories (http://jaqque.sbih.org/kplug/apt-pinning.html for a how-to) and from there install with apt-get install -t unstable linux-image-2.6-37-2-amd64

This new kernel has a new version of the coretemp module which is capable of dealing with these (not-so-)new intel models.

This might also be necessary for the newer high-end i7 as well as other 5600 series Xeon cpus.


Alguien me habló todos los días de mi vida al oido, despacio, lentamente. Me dijo: ¡vive, vive, vive! Era la muerte. (JS)