First code for Common Climate Project

This guest post is written by Hannah Aizenman, one of our Google Summer of Code students, who is working on a web-based visualisation tool for reconstructions of late Holocene temperatures, for the Common Climate Project (CCP).

Since my last blog post my project has progressed enough that the code can actually be used to make graphs of some sort, mostly plots of GISTEMP anomalies. The code is separated into two distinct parts: code that handles the data and code that handles the graphs.

The data part is pretty straightforward; give the code the path to the data and it’ll try to unpack the data and pull all the metadata out of the file. This is achieved as follows:

file_path = '../data/fields/'
data_obj = unpack.CCPDataFromNetCDF(file_path, field = 'field')

Then the data can be pulled out of the file using:

im = data_obj.get_all_data()

Note: there is also a get_data() function for doing online calculations over multiple files.

Once the data is pulled out of the file, it’s up to the user to run it through whatever algorithm he or she chooses to and spit out data to be graphed. For this post, I just took the mean of all the observations:

missing = data_obj.missing_value
mask = [im == missing]
im_masked =, mask)
masked = im_masked.std(0)

Next it’s time to set up the graph, starting off with setting the attributes and creating the object:

graph_attrs = dict( projection = 'moll',
                          title = 'gistemp_sat_anom_2.5deg',
                          cmap = 'gist_heat_r',
                          xlabel = 'longitude',
                          ylabel = 'latitude',
                          cblabel = 'std dev of temp anomalies')
graph_obj = spatial.SpatialGraph(data_obj, **graph_attrs)

And to finish off and create the image:

graph_obj.ccpfig(masked, 'gistemp_demo')

This code is also available for download at:

Besides generating figure, this code also lays out the rough structure of the project at the moment. There are three main, and somewhat independent, parts to the library: handling the data, doing some number crunching, and making pretty pictures. The plan for the web interface, which is my current focus, is to glue this library to some javascript or similar, so that anybody can go on to the commonclimate website, pick their data, throw in some attributes, and generate their own figures.

This entry was posted in News and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *