Taken in Portugal

Help Yourself: Predator Prey Simulations with PyQt4

As you may know I am a biology teacher. Next term I will teach Ecology. One part of that is the relationship between predators and prey (wolves and rabbits, for example). There are quite some mathematical model for these relationships, in school we mostly teach a simplified version of the Lotka-Volterra system.

This kind of stuff really needs a simple application to test the influence of certain factors. For example,

  • what happens if after two years we kill all but 5 predators?

  • what happens if after two years we kill all but 5 prey?

  • what happens if after 1 year, for whatever reasons, the rabbits become more fertile?

There are tools schools can buy, but a) they suck and b) they are very expensive.

Introducing: "Predator and Prey" by Carsten Niehaus (tm)

Free Image Hosting at www.ImageShack.us


As you can see the basic stuff all works. When happens when I start with just on predator but 20 prey but let the predators be more efficient hunters? Look here:

Free Image Hosting at www.ImageShack.us


The application is written in PyQt4 using matplotlib. I would really like to express one thing: Python + Qt4 rocks. Seriously, the whole application has only 306 lines including comments!

Are you interested in the code or even in helping me writing a cool PP-Simulation? Do you think this should go into KDE EDU? I am hosting everything in GitHub: PP in GitHub.
Taken in Portugal

[LazyWeb] DualHead: Hardware suggestion


I just got a second LCD for free. Of course I'd like to use it ;-) Currently, my computer has an old ATI card which doesn't support a second LCD-Panel (it is an ATI RV350 AR Radeon 9600).

I just noticed that I have 0% knowledge about graphics adapters... And I don't care about them, to be honest. All I want is KDE on two LCDs and be able to move windows between the two panels ;-)

I never ever play games on that machine and only do EMail, Firefox and OpenOffice on it. That means 3D performance is completely unimportant, I am sure the slowest chip is more than fast enough. As I am using the machine a lot passive cooling would be really nice. 3D effects in KDE would be nice, of course.

Question: Which graphics card would you buy if you were me?

  • Works on Linux (I am using Chakra (Arch Linux))

  • Dualhead is easy to configure (that means documented and I don't need to compile my own X.org or kernel and such)

  • Inexpensive

  • Silent

Thanks you for your suggestions.
Taken in Portugal

Python class variables and code dupclication


I am having a Python problem. I have two classes, both inheriting the class 'Animal'. I want a counter, that means Animal.count_of() should return the number of objects.

Please have a look at this code:

class Animal(object):
    number = 0
    def __init__(self):
        Animal.number += 1
    def __del__(self):
        Animal.number -= 1
    def count_of(self):
        print Animal.number
class Laus(Animal):
    def __init__(self):
class Bug(Animal):
    def __init__(self):

l1 = Laus()
l2 = Laus()
l3 = Laus()
l4 = Laus()

b1 = Bug()

This is not working because both classes are using the same class variable (number) which means the number in the last line is 5, not 1. I could obviously have one class variable for Bug and one for Laus, but that would mean I'd have to have two .count_of()-methods as well (and more would have to be duplicated, I only pasted a stripped down code).

Is there a trick to have one base-class Animal with a counter or do I really have to do everything twice?

Taken in Portugal

OpenStreetMap and routable maps


I just prepared a geocachingtour. I am using a Garmin GPS device and the OpenStreetMap maps. Even though my city is really complete (over 99% of the streets, pretty much ever pub is in ;-) I update the map every month or so. Spelling mistakes, the rural areas get better and better each day and so on.

Today I discovered that the map for Garmin devices is now routable! That means I have a navigation system for my bike. How cool is that?!

OSM starts to seriously rock. A year ago and today: What a difference.
Taken in Portugal

Casting an int to a float in Python 2.6



%d / %d is %f" % (num1, num2, float(num1)/num2)

have any (dis)advantages over

%d / %d is %f" % (num1, num2, float(num1)/float(num2))

? Both work. If one number is a float both are treated as a float, as far as I know.

Does the first line have any (technical) disadvantages over the second?

Taken in Portugal

Wifi-Map of my school

In my school we are currently rearranging many things including our Wifi-network. We have many (30 or so) Accesspoints all over the school. We want to know two things about our network:

  • So far the accesspoints are were we _think_ they should be. But for obvious reasons (like we don't know how think some walls are, if certain fire resistant doors absorb wifi-signals or not...) we have no clue if our distribution is good or not. So we want a "signal strength map" of our school.

  • Second, we want a map on which we can see if a certain accesspoint is in reach of another accesspoint. This is of course a sub-project of the first point.

As we are a school we don't want (or can) spend money here. The best tool so far seems WireShark, NetStumbler is Windows-only, but seems even better. Kismet is also such a tool but its GUI looks like I need a year to learn how to use it.

Do you have other suggestions?
Taken in Portugal

New Python app: Python really rocks :) (I still don't know where to hosts those apps)

Just like earlier I needed an application. This time I needed something that simulates the relations between predator and prey (see here). My students will use a simple simulation with dices so see those relations. The problem is that it takes ages to roll 400 times (that is what you need to get good statistics). So they only roll the dices for about 50-70 times, discuss the trends they see.

The next step will be my simulation based on the same rules. 77 python lines later that app is done :-) "All" I need is a nice PyQt4 interface for it, right now it is a pure shell application. But it already exports to CSV (just three lines :). In OOCalc this loooks like this:

Free Image Hosting at www.ImageShack.us


Quite nice and the code is really simple. Python rocks.

PS: No clue where to host this, I don't want such a tiny tool on sourceforge.net. Perhaps I should bundle all my biology simulation tools in one application (KSmallBiologyTools like (and no, I will not use that name)) and host _that_ application somewhere.
Taken in Portugal

PyQt4 rocks... Is there a (public) need for this kind of application?


As a biology teacher I am sometimes teaching about how our brain (memory) works. One way to test it is to read out loud the words while my students listen (between 10 and 40 words). When all words have been read they have 2 minutes to write them down.

Depending on the number of words and on the words themselves the results differ a lot. For example, if the words are interconnected ("hammer", "nail") those pairs are remembered quite well.

If you do this with 10 groups you have a problem: There is no way to read the list 10 times in the same way. Two solutions:

(1) Tape you reading and simply play the MP3-file.

(2) Display the words.

As a programmer (2) is much easier and more fun ;-) As I love PythonQt4 I simply wrote an application doing this:

As you can see I added a couple of words lists: One syllable, two syllables, more than two syllables and five lists of similar sounding words (man, ham, spam, damn, ...). You can configure the display time and see all words of a list. I am using a projector to display the words in the classroom.

This application is doing exactly one thing and is doing it well (ok, it won't win a design award...). As far as I know there is no such tool for schools around. So I wonder if there is a place for this kind off application. It is to specialized for kdeedu or Plasma, I think.

By the way: The application has only 129 lines of code including 11 lines of licence, 10 lines for the data, comments and white space. Python + Qt4 rocks :-)