US energy consumption

US Energy consumption (2008) by sector and energy sources taken from data published in the Annual Energy Review of the US Energy Information Administration.

Energy Consumption (QBtu)

Not surprisingly, most of the oil use goes to transportation, while coal and nuclear are mainly used for generating electricity.

Posted in energy | Tagged , | Comments Off

Spreadsheets and automatic recalculation in python

It wasn’t until a year ago that I started using spreadsheets at work. Though at first I found them annoying (and I still sort of do), one thing that I found interesting was the automatic recalculation of values. That is something that is not available in python’s interactive mode, and I wondered if it was possible to do something similar with python.

I focused on creating an interface for a subset of python based on declarations. Both variables and functions (using the lambda statement) could be declared. Whenever a variable is assigned, all dependencies should automatically be updated. In a way, this is equivalent to constraining python to a sort of first order functional programming language with automatic recalculation. On top of it, because I wanted to do something useful with it, I allowed for import statements.

The key for having automatic recalculation is to create and update a dependency tree. The simplest implementation I thought of was using a dictionary that lists the dependencies for each variable. When a value is changed it triggers a traversal of the dependency tree. I used cmd for the command line interface, tokenize for extracting the tokens, verifying that the input is of the var = expr form and getting the variable name and its dependencies. The assignments are evaluated using exec() in its own execution context. The simplest version, without exception handling, takes less than 100 lines of code. You can have a look at it here.

Posted in python | Tagged , | Comments Off

Science editorial – Inspirational Chemistry

Gray and Labinger from Caltech penned this editorial in Science where they defend the relevance of chemistry in solving some of the biggest issues facing our society.

Posted in science links | Tagged , | Comments Off

weird gnuplot

Besides fast plotting, Gnuplot let you define functions and variables. However, what I found interesting is that it apparently allows multiple definitions with the same name coexist as long they depend on a different number of parameters (at least on v4.0).

The following snippet:
f(x) = x
f(x,y) = x + y
f=2

does not overwrite the definition of f, but it creates three different elements in the stack. Coming from C and Python, that’s unusual…

Posted in scientific programming | Tagged | Comments Off

nanotechnology in consumer products

The Project on Emerging Nanotechnologies has an inventory of nanotechnology-enabled products.

Posted in nanotechnology | Tagged | Comments Off