Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, May 19, 2012

Automatically extracting bomb drops from the Blitz Bomb Census maps

I just finished Blackout by Connie Willis and I was wondering where she did get all the exact times when the air raids of The Blitz were happening.
I am curious because I was thinking that a timeline map would give a visual effect of the huge destruction and hard times the Londoners had to go through...so I googled for it and found the following:
Both examples show nice data visualization opportunities, but they both show how difficult it is to obtain data. Digital access to historical data could triggers a blossoming of applications!

Anyway I experimented with the little map from the first blog and wrote a little program using SimpleCV.

This is were I started from:
and this is what I got (without too much work, I must admit):


The code is quite simple and the parameters could be changed to get higher accuracy.

blz = Image("./sampleimages/the_blitz.png")
img = blz.copy()
dist = img.colorDistance(SimpleCV.Color.WHITE)
dist.dilate(2)

segmented = dist.stretch(240, 255)
blobs = segmented.findBlobs()
if blobs:
 circles = blobs.filter([b.isCircle(0.6) for b in blobs])
 for c in circles:
  img.drawCircle((c.x, c.y),
                 c.radius(),
                 SimpleCV.Color.YELLOW,
                 2)
 img.show()

Monday, October 26, 2009

PyCalCal is out!

I finally set to put PyCalCal out in the open.
I will need to finalize and perfect it but that is a good starting point.
I also added a demo web app using it.

My idea is for PyCalCal to be used as a Python library and as such use it to provide calendrica calculations as web services.
Stay tuned if you are interested.

Sunday, June 14, 2009

Scons and noweb

I was curious to see how I could integrate noweb and Scons.
You can download my little Sconstruct for this, Sconstruct.example. It defines two builders. NoWeave is used to produce TeX or LaTeX documents, while NoTangle extracts the non-document artefacts, i.e. programs, config files, scripts ... It also includes productions for generating a sample program about Ackermann function:

ackdoc = env.NoWeave('ack.tex', 'ack.nw')
ackcode = env.NoTangle('ack.py', 'ack.nw')
acktest = env.NoTangle('ackTest.py', 'ack.nw')

The noweb source is ack.nw and the companion BibTeX file is ack.bib

It contains the doc chunks describing the function, the source code chunck for the relevant Python code and the code chunk for the unit test

You can try it out executing

$ scons -f Sconstruct.example
You will get the following artefacts, ack.py, ack.tex, ackTest.py and ack.pdf

Remember to run BibTeX first...

Tuesday, February 24, 2009

LaTeX, Python and Literate Programming

In my spare time (a couple of hours per weekend...!) I am implementing calcal, a Python version of calendrica-3.0.cl, the Common Lisp implementation of the calendars from N. Dershowitz, E. M. Reingold Calendrical Calculations, 3rd Edition. (In case you are interested you can find a preview in my google page.)
At some point I decided to go Literate [Programming] using noweb. This is an experiment in the experiment but so far it has been a good choice because I can define all I need in the same place and generate documentation, source code (Python, shell scripts ...) from the same source.
I also found something interesting (on a now disappeared blog ttp://usefreetools.blogspot.com): executing Python from within LaTex! I could use it to avoid to hardcode results in my doc and just calculate them on the fly...
The same blog was showing how to build LaTeX docs using SCons: I will defenitly use it; my Makefile isn't that great nor easy to mantain.