Archive for the ‘Python’ 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

MoinMoin wiki on Debian, Installation and configuration – 11. September, 2009

Sometimes, installation of Debian packages is too easy, but them configuration can be quite confusing.

This is the case, in my opinion, with the README.Debian file which describes an example of moin-moin wiki installation under a subdomain wiki.example.org.

Here are my notes of how to install moinmoin package from Debian Squeeze on Debian Lenny.

First, you need to install python-support from debian-backports.org.

Second, download manually or with apt-get the package of debian lenny for python-moinmoin.

Install both packages, if you downloaded them manually with the command:

dpkg -i python-support_1.0.3~bpo50+1_all.deb python-moinmoin_1.8.4-1_all.deb

After that you need to issue the following command, which are also described in the README.Debian:

1) Create and populate /var/www/mywiki

mkdir /var/www/mywiki
cp -r /usr/share/moin/server/moin.cgi /var/www/mywiki
mkdir /var/lib/mywiki
cp -r /usr/share/moin/data /usr/share/moin/underlay /var/lib/mywiki

2) Pass on the wiki to Apache:

 chown -R www-data: /var/www/mywiki /var/lib/mywiki

3) Configure Apache2:
Add the following as /etc/apache2/sites-available/mywiki:

<VirtualHost *:80>
 #comment the line below if you intend to use only http://localhost/mywiki
 ServerName wiki.example.org
 DocumentRoot /var/www/mywiki/
 Alias /moin_static184/applets/FCKeditor/ "/usr/share/fckeditor/"
 Alias /moin_static184/ "/usr/share/moin/htdocs/"
 ScriptAlias /MyWiki "/var/www/mywiki/moin.cgi"
</VirtualHost>
<Directory /var/www/mywiki/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride None
 Order allow,deny
 allow from all
 Options +ExecCGI
</Directory>

4) Configure MoinMoin:

Edit /etc/moin/farmconfig.py to commentout data_dir and
data_underlay_dir (we need those defined separately for each wiki)

Edit /etc/moin/mywiki.py to include these lines:

 sitename = u'MyWiki' # [Unicode]
 data_dir = '/var/lib/mywiki/data'
 data_underlay_dir = '/var/lib/mywiki/underlay'

Edit /etc/moin/wikilist to include this line:

 www-data wiki.example.org/

5) Activate wiki:

a2ensite mywiki
invoke-rc.d apache2 reload

6) Enjoy your new wiki at http://your.site/MyWiki/

A Note about themes, debian, moin-moin

Debian is intended for the server… Thus it’s quite biased for a wiki-farm rather than a personal use wiki. Default moinmoin shares lot’s of files between different possible moinmoin installations.

The appropriate directory for installation of themes, under Debian won’t be the data directory (in the above example, /var/lib/mywiki/data)  rather a shared directory under /usr/share/moin/htdocs.

So the css/, img/, js/ directories of a plugin go there, and the python module of the theme goes to /var/lib/mywiki/data/plugin/theme.

Here is an example of how I installed fixedleft theme:

ls -p /usr/share/moin/
config/  data/    htdocs/  server/  underlay/

ls -p /usr/share/moin/htdocs/
applets/  common/      fixedleft/  modern/    rightsidebar/
classic/  favicon.ico  index.html  modernized/    robots.txt

ls -p /usr/share/moin/htdocs/fixedleft/
css/  img/  js/

ls -p /var/lib/mywiki/data/plugin/theme/
fixedleft.py  fixedleft.pyc  __init__.py  __init__.pyc

To activate the theme, you need to /etc/moin/mywiki.py, add the following line:

theme_default = 'fixedleft'

to activate fixed left as the default theme.

If you have two lines like this:

theme_default = 'rightsidebar'
theme_default = 'fixedleft'

The last one will be the effective one.

Posted in Debian, Python

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