Monday, August 31, 2015

Python, DictReader, DictWriter

Because I can never, ever, remember exactly how to code these. Example of both, basic.

data_list = []

with open(input_file, 'rU') as f:
  data_file = csv.DictReader(f)
  for line in data_file:
    data_list.append(line) # gets you a list of dicts

the_header = ['h1', 'h2', 'etc'] # column headers, a list of text strings

with open(output_file, 'w') as f:
  file_writer = csv.DictWriter(f, fieldnames=the_header)
  for line in data_list:

16th Century Maps for 21st Century Data Science

Maps bother me. I love them, and I'm not a geospatial GIS coding specialist, but I do visualizations, and we keep using the wrong maps. Greenland is a lot smaller than all of Africa, ok?

This is the map in my office kitchen:

It's the typical Mercator projection (projection, since you have to "project" a sphere onto a flat surface, which doesn't work well). Mercator came up with this map view in 1569, according to Wikipedia. Yet we still use it for 21st century data science! Granted just because something is old doesn't mean it's not useful, but in this case the Mercator projection was created primarily for navigation, that is, sailing the seven seas. When you present geospatial data the only thing your viewers are navigating is your data. As such this is totally the wrong mapping projection to use. Totally. Don't do it. Data visualizations are about accuracy, and using the Mercator projection starts you off with a completely inaccurate mapping. Greenland and Africa? "Africa's area is 14 times greater" than Greenland according to that Wikipedia article! Fourteen!

So what to do instead?

Wikipedia has a page of many different projections, I'd vote for one of the equal-area ones, and am a fan of the Gall-Peters projection (which was the centerpiece of a great segment on The West Wing), but you'll need to decide what's best for your use.

So, I'm a little upset about the giant Mercator map in my office, but with good reason.

Sunday, August 2, 2015

Code for All Summit

Had a great time at the Code for All summit, held here at Civic Hall. Global meets local with a variety of civic tech people and a few government and NGO people thrown in. Code for All is the global offshoot of Code for America.

One nice thing to see was that yes, sometimes the best solution is SMS and not a fancy app.

That's me in the front row second from the left.

Monday, July 13, 2015

Music in an MMO!

Oh this is exciting, but I don't play each and every MMO (that would be insane) so didn't know about it.

Cheng, W. (2012). Role-Playing toward a Virtual Musical Democracy in The Lord of the Rings Online. Ethnomusicology, 56(1), 31-62.

There's no abstract, but here's an early paragraph:

In an attempt to honor the rich musical lore of Tolkien’s Middle-earth, Turbine implemented in LOTRO one of the most elaborate player-music systems in any MMORPG to date. This system allows a player to perform both live and pre-recorded tunes that can be heard by other nearby players in the gameworld. A player’s musical performance is visually simulated by avataric motions and strings of colorful notes that float out of a character’s equipped instrument (see Figure 2). Examples of such instruments—each of which sports a different synthesized timbre and a range of three chromatic octaves along the Western twelve-tone scale—include the bagpipes, clarinet, flute, horn, cowbell, drums, harp, lute, and theorbo.
The wiki page seems pretty informative, and there's a website repository for the ABC music notation files.

I love it when people make things and share things, and music is community-based, a form of communication, and is very old! The oldest instrument we've found, a bone flute, is about 40,000 years old and it certainly wasn't the first musical instrument, since flutes aren't that easy to make.

Sunday, June 14, 2015

Python, OSX, and Computer Name

Sounds thrilling! No not host name, but the name you give your computer -- so my multi-core beast is "NeXTcyl" (like a NeXT cube but a cylinder).

It was somewhat difficult to find, well, not the best way to do this in Python, but the only way I could find to do it in Python for OSX. Lots and lots of method for hostname: no no no Google, not that. You want to call out to scutil, a command line program.

import subprocess
this_computer = subprocess.check_output(["scutil", "--get", "ComputerName"])

Essentially, use the subprocess library to call a command line function, use the check_output component to get the output from it (important!), and the three parts of the command line command are all cut up into the different arguments you hand the call (also important!). I tried about four other approaches before this one, and then had to try about three different syntaxes to get it to work, since I couldn't find any good online help. Here you go. For OSX, not Windows or other *nixes. No idea what they will do (nothing bad, but maybe not what you want).

(Because I have a 3.6 GB file I don't want to put in DropBox, so I have a local copy on my desktop and on my laptop, but the files are in different paths on each, so I wanted a way to detect which machine the code was running on so as to call the right file path -- I could have just tried one path and if it failed use the other, but, I only just thought of that now.)

Monday, June 1, 2015

400,000 Years Ago

400,000 years -- we're only at 2,015 in the "common era". So roughly 398,000 BCE. The Great Pyramid of Giza is from around 2,560 BCE, and Stonehenge is from between 3,000 BCE and 2,000 BCE. The cave paintings at Lascaux are from approximately 15,000 BCE. The earliest musical instruments found, bone flutes (bone survives well in the archaeological record), are about 35,000 years old, that is, from 33,000 BCE (although there is some disagreement about some finds and dates).

200,000 years ago is when we think the first humans -- homo sapiens -- evolved.

400,000 years ago is when homo heidelbergensis, not us but our ancestors, existed. No humans.

And this is a chipped (napped) stone instrument they made, possibly to cut animals apart. And that's me holding it at the British Museum. HOW COOL IS THAT I'LL TELL YOU IT'S VERY COOL.

Ex Machina and Chappie

Contains spoilers, totally and completely. I mean, it's the internet.

I caught both recently on Virgin Atlantic. The screen was a little small and glossy so had lots of reflections, which did not do well by Ex Machina but Chappie does fine with it. (I think a better title for Chappie would have been Scout 22, since "chappie" makes little sense in American English.)

Both, by the way, are recent movies about AI, yet they are very different.

Ex Machina has a few characters, few speaking parts, and is sparsely beautiful (best watched on a big hi-def screen).

Chappie has lots of speaking parts, and is familiar to viewers of Blomkamp's film District 9 in terms of the visuals -- a rough, decaying world in South Africa with lots of little details, because when things fall apart or get blown up there are lots of little bits.

In this, they are opposites. They are also opposites in how they treat AI -- in Ex Machina, the AI is software and hardware (the cool glassy blue brain objects), and the objective is humanity -- they have human faces, bodies, and can make and read human facial expressions. In Chappie, the AI is in a somewhat clunky-looking (but adroit) robot body, and the AI is the software (it can survive in a USB dongle).

For Ex Machina, the point is for the AI (and its body) to become human.
In Chappie, human consciousness can be scanned and downloaded into the robots (no special brain neeeded, although the robots have good brains -- this is science fiction, after all).
So AI/robots becoming human, and humans becoming robots.

Yet they share the same approach to the creator, a male genius who is the solo creator, more or less of a loner (it varies in the two films).

In Ex Machina, the AI/robot seeks to hide in humanity and does not trust them (well not the initial human characters) and kills her creator (although the creator is horribly abusive and ego-maniacal), whereas in Chappie, we know they become known more widely to humanity and Chappie (the AI in the film) trusts the humans he comes to know and helps save one of them, the AI creator.

Ok I don't really have anything deep to say, but they are both pretty good. In Ex Machina I think the two main male characters aren't written as well as they should be, they are a little overdone and tedious at times, but in Chappie I really liked the characters, and Die Atwoord are great. Ex Machina would have benefitted from a better, bigger screen. I also thought the music in Chappie was really good. I also thought Alicia Vikander's performance was great as the main AI in Ex Machina.

Apparently I disagree with reviewers on all this.