Sunday, December 12, 2010

PyQt4 and the United Nations Universal Declaration of Human Rights

What is PyQt?



"PyQt is a set of Python bindings for Nokia's Qt application framework and runs on all platforms supported by Qt including Windows, MacOS/X and Linux. There are two sets of bindings: PyQt v4 supports Qt v4; and the older PyQt v3 supports Qt v3 and earlier. The bindings are implemented as a set of Python modules and contain over 300 classes and over 6,000 functions and methods."


Source:  http://www.riverbankcomputing.co.uk/software/pyqt/intro


Why do we care? Because OPUS uses PtQt4 for its GUI.

Where does the UN Universal Declaration of Human Rights come in? The same place the Bill of Rights and the Declaration of Independence are:

Part III: Intermediate GUI Programming
- Chapter 9 - Layouts and Multiple Documents
\opus\doc\Libraries\PyQt4\Rapid GUI Programming with Python and Qt\chap09\


which is sourced from:

Rapid GUI Programming with Python and Qt
The Definitive Guide to PyQt Programming
by Mark Summerfield


ISBN-10: 0132354187  – ISBN-13: 978-0132354189
http://www.qtrac.eu/pyqtbook.html


An interesting departure from the convention of Lorem Ipsum.
http://www.lipsum.com/


How did I stumble across this? I searched for "birth" (which turns up the Universal Declaration of Human Rights) because I was trying to find the source implementation of the aging, birth and death models to see how they have well...been implemented.

Sunday, December 5, 2010

How many languages are needed to understand OPUS?


Looks like 6 or so key languages from sources such as this image of the internal ecosystem from \opus\src\opus_core\docs\images\Opus internal ecosystem.png and further study of the OPUS User Guide:

  • Python 2.6.2 - Main source language at this time
  • Tekoa - A custom domain-specific programming language for writing OPUS variable expressions, e.g.
        ln(urbansim.gridcell.population)
    computes the log of an existing variable, population, which is in the urbansim package and applies to the gridcell dataset.
    See the Chapter 13 of the OPUS User Guide for more.
  • C/C++ - Many of the external libraries used (at least originally - much has probably changed over 5 years, e.g. I think the visualisations are now on GraphViz and Imagemagick though I could be wrong)
  • R - The statistical language.
  • SQL - Because much data is persisted in relational databases, the open-source MySQL, PostGreSQL and commercial Microsoft SQL Server are often used.
  • XML - e.g. \opus\src\psrc_parcel\configs\psrc_parcel.xml contains 500 lines of configuration for simple things like the project name, as well as more complex things like a matrix_variable_map dictionary containing banks of strings which appear to represent quantities - e.g. am_pk_period_drive_alone_vehicle_trips or logsum_hbw_am_income_3. Some of this is in the GUI, for example the Scenario XML:
Click to enlarge, XML on the left, OPUS GUI on the right.

I mentioned GraphViz, it has it's own format and syntax. A simple example:

graph G {
1 -- 5;
4 -- 1;
4 -- 2;
2 -- 3;
4 -- 5;
5 -- 2;
}


Here's an example output from an assignment I completed earlier this year, this represented a highly-connected graph of approximately 1,000 vertices and 250,000 edges, which for the instance of our problem it was discovered could be covered with just 6 "Wireless Station Relays" represented by individual colours (most solutions found the equivalent of 8 or 9 easily (around 2700 in Test 7).

And of course many more GraphViz examples are on show at:

So for OPUS, that's a fairly standard assembly of languages, most web projects for example have 5 or so between:
  • PHP (or Python, Perl, Java, C#, Lisp, Erlang, etc)
  • HTML
  • CSS
  • Javascript
  • SQL (or GQL, HQL, or other persistence data languages)
What's different is clearly the libraries and frameworks built on top of these languages. The image of the internal ecosystem is probably one of the best to explain the state 5 years ago - and as I've alluded to much has been built since then!

In any case I think I'll be at home once I figure out a few more of these model semantics and how to combine them effectively. The only languages I have no other experience in are R and Tekoa (which looks very straightforward - as it was designed to make OPUS easier to configure).

Saturday, December 4, 2010

More Semantics Please

As I suspected, while I know much of the Python syntax from using the 2.5/2.6/2.7 versions with a major project and several assignments now, there's likely to be a lot of semantic learning and discovery on my part.

For example, OPUS provides Gridcell, Parcel and Zone based models in the 4.3.0 Windows release. My understanding so far is this means in at least one context (based on Chapter 13 of the monster 300-page OPUS User Guide and informal discussions with the NSW Bureau of Transport Statistics):
  • Gridcell - arbitrary grid squares/rectangles chosen, no direct/intuitive mapping to most real-world data sets.
  • Zone - Typically an aggregation of parcels, often used in Transport Models.
  • Parcel - An aggregation of buildings (which are aggregations of households), i.e. much more direct/intuitive mapping to real-world household locations.

Of course, OPUS is not limited to just this. It appears that further arbitrary (but I'm sure well-intentioned) model constructs such as neighbourhoods, regions and "faz" (most likely an acronym for some other kind of land group or classification from the source code in \opus\src\psrc\faz ) also exist. Indeed from Chapter 17.1.3 of the OPUS User Guide,
"For example, an application in Paris used Communes, or
administrative areas roughly equivalent to traffic analysis zones in number (approximately 1300)."

What does that tell me? If nothing else, OPUS is extensible so the questions are more likely to become purely semantic and thus limited by our collective understanding of the world:
what's the best known way to model this concept or idea given the current limits of computing and our ability as human beings to bridge the syntactic and semantic gaps?

rather than something like:
how do I get my city's data into OPUS format?

Of course, there's a long way to go yet. These concepts apart from the "household" or "building" level may have no real-world analogue.

Literally - if you needed to split a city up into parcels, zones or neighbourhoods, how would you do it?

Perhaps more importantly how would you figure out how Australian concepts (not sure how applicable they are worldwide) like suburbs, postcodes, electorates and regions (just to take a few possibilities) map onto these OPUS constructs?

Having worked in government I could see questions from a minister like, how is the land use in my electorate going to change over the next 30 years? What kind of projects should my urban planners be pursing today? What options should we be considering to achieve the best short and long term outcomes for my community given known budget constraints?

And to begin to answer such kinds of questions, I need more semantics. Study ho!

Exploring, Discovery, Good stuff!

Just the introductory post that I'll be blogging stuff here as part of my collective memory, and with any luck it will make a thesis easier to write.