Archive for the ‘science’ Category

 

Evalution of Tracer Test with Python scipy.optimize – 10. October, 2009

This post is not intended only to hydrogeologists, but also to any one who needs a working example of the use of a function minimum search.

It is very common for many scientific problems to search for a minimum condition. In optimization of problems it’s very common to use a minimum of least squares function between measured results and some model function.

In the following code you can see the results of a tracer test procedure preformed at a test site called Lauswiesen, at the skirts of ‎‎Tübingen in southren Germany. This tracer test was performed as part of a course called Field Methods in Hydrogeology given in the Master’s program of Applied Environmental Geosciences.

(more…)

Posted in Python, science

Making Octave ploting nicer – 21. May, 2009

Personally I prefer python over Octave/Matlab. But since I’m being forced to write Matlab code for one of my course, I started playing around with octave.
By default octave makes ugly ugly plots because it uses the X11 terminal. But there’s a solution, you can switch to wxt terminal. In order to do that, add in the bottom of your .bashrc the following line:
export GNUTERM=wxt

And a magic will happen:
Before:

UGLY !!!

UGLY !!!

After:

NICE !!!

NICE !!!

That’s all folks.

Posted in Debian, Linux, science

3D plots with matplotlib – 17. May, 2009

Today I built matplotlib from svn. The answer why I did it is in the post’s title. 3D plots are back to this wonderful tool !

So, if you build matplotlib version 0.98.6svn or later, you can enjoy this. It’s sometimes a little bit cranky. With plots of multiple points I got one big black surface, but for simple stuff it works great.

Here is an example of 3D plot of hydraulic head on a coordinate system:

import pylab as pl
from numpy import *
import mpl_toolkits.mplot3d.axes3d as axes3d

       #  x      y     head
head = ((25, 225 , 240.1178), #h1
		(75,  225,  242.3238),#h2
		(125,   225, 244.8013),#h3
		(175,   225,    247.2736),
		(225,   225,    248.8057),#h5
		(25, 175 ,  241.7646), #h6
		(75,  175,  242.0468),#h7
		(175,   175, 248.2085),  #h8
		(225,   175,    249.1382),#h9
		(25,   125,    243.1239), #h10
		(225, 125 , 249.5332), #h11
		(25,  75,  244.4780),#h12
		(75,   75, 245.1523),  #h13
		(175,   75,    248.9717),#h14
		(225,   75,    249.4562),#h15
		(25, 25 ,  245.1523), #h16
		(75,  25,  245.8214),#h17
		(125,   25, 247.1543),  #h18
		(175,   25,    248.4819),#h19
		(225,   25,    249.3144)) #h20       

x, y, z = zip(*head)
xi, yi = pl.arange(0, 250, 5), pl.arange(0, 250, 5) #create grid
head = pl.griddata(x, y, z, xi, yi) #interpolate the scattered data !
print shape(head)
print shape(xi)
print shape(yi)
f = pl.figure(1)
pl.scatter(x, y)
pl.contour(xi, yi, head)
pl.colorbar() # draw colorbar
#pl.show()

f = pl.figure(2)
ax = axes3d.Axes3D(f)
#X,Y,Z = axes3d.get_test_data(0.05)
cset = ax.contourf3D(xi,yi,head)
ax.clabel(cset, fontsize=9, inline=1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Hydraulic Head')

f = pl.figure(3)
ax = axes3d.Axes3D(f)
#X,Y,Z = axes3d.get_test_data(0.05)
cset = ax.contour3D(xi,yi,head)
ax.clabel(cset, fontsize=9, inline=1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Hydraulic Head')

pl.show()

and the output is:
head 3D

Another 3D plot

Another 3D plot


old fashioned...

old fashioned...

As usual, have fun with python !

Posted in Python, science

A matplotlib tutorial – 5. January, 2009

Most people that find my blog in the end of the internet arrive here while looking for python matplotlib tutorial. That’s thanks to the crazy matplotlib tutorial I already have in my blog. However, this tutorial is not very useful. And since I’m using matplotlib to do some of my homeworks, I been wanting to post some real life tutorial. After all why not give the audience what it wants?

So here it is – a real life, hydrological problem solved with python matplotlib. First, some background. (more…)

Posted in Python, science

Installing MapServer on Debian Lenny – 27. October, 2008

In this post I will document my playing around with MapServer. I’ll do my best to update this as best I can, but consider this as on ‘under construction status’…

Debian Lenny comes with version 5 of MapServer, so in order to install it you just need to type in the terminal as root:

apt-get install cgi-mapserver mapserver-bin mapserver-doc  php-mapscript python-mapscript.

If you don’t have apache2 running and configured than you should also install apache2.

In debian cgi-scripts are install by default to /usr/lib/cgi-bin but are linked to /cgi-bin in the default install of apache2 in debian.

(more…)

Posted in Debian, Python, science

Crazy Matplotlib tutorial – 26. July, 2008

Note: A better and more realistic tutorial can be found here.
I started using python’s matplotlib to plot graphs in my Oceanography courses. Matplotlib is pretty easy to understand if you already know some python. However it’s documentation is somewhat frustrating, even though it comes with a plethora of examples.

So I turned to seek help on the user’s list, and that was a great experience. I got responses almost immediately, and many times the respondent was the author of the program himself. That was very nice, but people kept telling me I should read the tutorial and user guide and I kept answering that I prefer to learn by doing. Which is true. I use another program which has a steep learning curve called latex-beamer. It comes with a wonderful 300+ pages user guide. I read bits and parts of it. But mostly, I just saw other people code and copied it and changed it to fit my own presentation needs. Unfortunately, I couldn’t do the same with Matplotlib, maybe because graph codes is not something people show around like beamer presentation.

So I ended up quite frustrated and I wrote the following to the mailing list:

I am a lost case about reading tutorial at the moment.
I am in a middle of a very intense course, and they expect us to do crazy stuff with matlab. so it’s either that or solving with python. I’ll do read it when I have time…

I am mostly frustrated with documentation writers who write very nice tutorials describing
how to plot completely unuseful graphs of spheres inside loops and a dolphin swimming
in the middle. Come on, this is not what users need. I am talking about what many students
feel. We need real tutorials, this why I wrote my own little tutorial here
http://www.tabula0rasa.org/?p=21.

So I vented a lit bit my frustration. The reply didn’t wait long before arriving in a very funny way:

(more…)

Posted in Python, science