12 March 2010

It's science, ok

Today I had a little fun with my code. As I've mentioned too often, it's written with a Python front end. That means I can very easily interact with the hundreds of Python modules out there. Well, this being a Friday afternoon, I decided to tie it into an image processing library, which will let me turn an image into a series of values, which I can then define as a field on my mesh (e.g., the total cross section). So I did that with a test image, and ran it through my transport code.

The code to load an image as grayscale, create the mesh, and set the cross sections:

    im = Image.open(fname).convert("L").transpose(Image.FLIP_TOP_BOTTOM )
    values = ( (255.0 - x) / 255.0 for x in im.getdata() )
    args = list(im.size) + list( 10.0 * float(i) / max(im.size)
                                  for i in im.size )
    mesh = meshlib.Mesh(*args)
    sigma_t = meshlib.CellFieldFloat(mesh, meshlib.VectorFloat(values) )

I also did this with a picture of my advisor.