Climate Pathways app enables everyone to investigate climate change

My first app for iPhone and iPad has been published in the App Store by my development partner Climate Interactive. I started with the idea of publishing an ebook with embedded simulations to explain the science behind global warming and climate change. The climate system is complex with many surprises in its behavior. I thought it would be interesting for people to find out for themselves how delays in the system mean we have to reduce greenhouse gases now, before the really bad impacts have become apparent.

I needed a climate model that would run fast enough on an iPhone. This led me to Climate Interactive and their C-ROADS model. They work with policymakers, helping them understand how various greenhouse gas emissions scenarios will play out. Their first outreach to the public, the Climate Scoreboard, was a big success, and they wanted to do more. They had just developed a simplified climate model in JavaScript that I could embed in an iOS app.

When Drew Jones at CI proposed an app that would deliver the key insights in a focused way, I ditched the ebook idea and worked with the CI team on realizing Drew’s proposal instead. The result is Climate Pathways.

There’s a thermometer on the left that shows the temperature rise at 2100. To use the app, you trace a greenhouse gas emissions curve from 2010 to 2050. The gray curve shows our current, disastrous path for reference. The app instantly calculates the temperature rise in 2100. Your task is to find a scenario that results in a temperature rise of 2ºC (3.6ºF) or less.

If you get stuck, you can try “auto mode” and sweep your finger around to find 2ºC pathways calculated by Lori Siegel at CI using the full C-ROADS model. The little info button gives you some background information on the climate system and our current situation.

The app page at CI features a demo video showing the app in action, narrated by Drew Jones of CI. This video shows how effective an interactive simulation can be for illustrating the behavior of a complex dynamical system.

Climate Pathways Demo

The Climate Interactive team took iPads to the UN climate conferences in Cancun and Durban. People there really liked how it gets the point across. Hopefully, we’ll be able to do a lot more with it soon.

Testing C-ROADS for iPhone at COP16

So if you have an iPad, iPhone, or iPod Touch, head on over the App Store to download your free copy of Climate Pathways today!

     

NSString UIKit additions provide vital Quartz text drawing enhancements

One of the distinctive features of Objective-C is categories. They allow you to add methods to a class without changing the original class’s source code (or deriving a subclass). I mostly use categories as a way to keep private methods out of the public interface of my own classes. But Apple has used them in the iOS SDK in the way they were originally intended.

I was struggling with drawing text in Quartz 2D when I stumbled on the NSString UIKit additions. There’s really no other good way to measure text before you draw it. You’ll need to do this to position text on a chart, for instance, as in my Climate Pathways app. The additions make Core Graphics much easier by allowing the use of UIKit objects. Now I use them everywhere to draw text.

They’re pretty straigtforward, but I got stuck when I tried to use them in CALayers. The additions assume they will be used in a view. They get the current graphics context for you by looking at the context pushed on the stack before drawRect: is called. If you are drawing dirctly in a layer, the context is not pushed on the stack. You have to do it yourself before calling the additions.

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)c {
	UIGraphicsPushContext(c);
	CGPoint textPos = CGPointMake(MESSAGE_MARGIN_HORZ, MESSAGE_MARGIN_VERT - 1);
	[messageColor setFill];
	[messageText drawAtPoint:textPos withFont:messageFont];
	UIGraphicsPopContext();
}

Note that the text coordinate system does not need to be flipped when drawing text this way.

LOG_EXPR makes NSLog debugging easy

I find interactive debuggers too tedious for most problems. Xcode is no exception: you have to dig through the object hierarchy to display the values you want to look at, and even then, Xcode may not display the value in a useful way.

Years of web application development got me in the habit of “printf” style debugging with a log file. This works great in Xcode using NSLog, but now there’s an even better way.

Vincent Gable’s LOG_EXPR macro automates the tedious work of writing labels for your debug values. Give it most any expression, and it will print the expression and its value. For example, writing:

LOG_EXPR(touchLocation);

in your code gives you the following console output:

touchLocation = {95, 413}

LOG_EXPR knows how to format most common C and iOS Framework types. You can format the values for your own types by overriding the - description method of NSObject in your class. This also comes in handy for ad hoc debugging with the gdb print object command.

By the way, when you still want to use NSLog, there’s a useful shortcut in Xcode. Simply type “log” and press Esc. You’ll get an autocompletion list, with a nicely formatted NSLog statement at the top. Just hit Return and fill in the placeholder.