RClimate Script Introduction

Would you like to be able to generate a GISS temperature anomaly trend chart on your PC with just 1 line of R script? What about downloading the R script to your PC so that you can edit the script to fit your needs?

In this post I present my first RClimate Script so that users with just a little R experience who have R and 2 R libraries up and running on their PC  can  retrieve the latest NASA file on monthly GISS temperature anomalies, generate a trend chart and calculate the anomaly trend rate in 1-2 minutes.

Getting Climate Data in Users Hands

There are many high quality on-line climate data files like NASA’s GISS file, however, file formats are often difficult to work with, users may need to merge multiple files to get the proper data coverage and the date time intervals may need to be aggregated from daily to monthly or annual averages. Trying to download, manipulate, adjust, average and merge large data files with tools like Excel can be downright difficult.

Many climate observers who read posts on  Open Mind, Blackboard, Climate Observations would like to make additional iterations of the original, however,  in many cases this is just to time consuming. If we give the readers access to the post data set and analysis, the readers can  then reproduce /adjust the charts/analysis as they see fit.

My goal is to make it easy for interested climate observers to get their hands on the actual climate data behind climate trend posts. I hope to make it really easy for R beginners to reproduce my climate charts and data analysis.

My First RClimate Script

Here’s a trend chart of NASA’s GISS Land and Sea Temperature Anomaly for the period 1880-2009 which  includes a trend line for the period 1990 – 2009.

Let’s take a quick look at the source data file (link) to see the raw data behind the chart.

I wrote an R script program, giss_mo_anom_r.doc, to generate this trend chart from the  NASA file. Here’s what it does:

  1. Downloads and reads the on-line NASA data
  2. Converts values to degrees C (divide by 100)
  3. Converts the 18 column per year array to a 1 column per year-month time series
  4. Subset the full data set and generates a liner regression for a user specified time period, 1990-2009 in our example.
  5. Generates trend chart with trend line and trend rate

A user with R and 2 libraries  (plyr, reshape) installed on his/her PC and an internet connection can copy/paste the following 1 line of R script into an R Console and  automatically generate this chart.

 source("http://chartsgraphs.files.wordpress.com/2010/01/giss_mo_anom_r.doc")

source()  lets you run an existing R script, in this case it is stored on my WordPress account. Experienced R users will notice that the R script file type is doc not the traditional R.  I had to use the doc type because WordPress’ security features would not accept an R file type.

This single line of R  script reads my GISS R script program on my WordPress account,   runs it on your PC and  generate the chart.

Pretty easy! You can find out more about R’s source capabilities by typing ?source on your R console.

How Can I Change the Trend Period?

I used the 1990 to most recent month to calculate the trend line and rate. You have another idea, you’d like to look at the 2000 – to present or some other period!

To do this, you need 3 lines of R script so that you can download and save the R script on to your R working directory , use file.edit() to bring it into your R editor so that you can edit it to your heart’s content.

link <- "http://chartsgraphs.files.wordpress.com/2010/01/giss_mo_anom_r.doc"
download.file(link, "GISS_mo_anom.R")
file.edit("GISS_mo_anom.R")

To change the trend line period, look for r_xmin and r_xmax in the script and set them to whatever values you want. Once you have finished editing the script, save it and rerun it to try out your new chart.

If you like your revised version of my R script,  you can save it to rerun next month  and get the latest NASA GISS update with your trendline settings without doing anything extra. Any  NASA adjustments to their historic data set will be included because my R script program reads the most current version of NASA’s file.

So try my 3 line script. Let me know what you come up with.

About these ads

17 responses to “RClimate Script Introduction

  1. Pingback: Atmospheric Temperature Structure : 2 – Stratospheric Cooling | Climate Charts & Graphs

  2. Pingback: Climate Time Series In a Single CSV File | Climate Charts & Graphs

  3. Pingback: Using RClimate To Retrieve Climate Series Data | Climate Charts & Graphs

  4. Pingback: Climate Charts, Data and RClimate Scripts | Climate Charts & Graphs

  5. Pingback: Plotting Atmospheric Temperature Structure and Lapse Rate | Climate Charts & Graphs

  6. if you have the code for various tasks laying around, why not make a package?

    • Patrick

      I’m glad you asked. I have a few reasons:

      The source data file links have a tendency to change, raising concerns about lag between link change and package update

      It’s too early to make a package, I’m still working through what I want to do

      I’m still on my learning curve, the scripts work, however, they are not necessarily efficient and are definitely not “best practice”

      Right now I’m more interested in learning about climate data than figuring out how to make a package.

  7. Pingback: RClimate Tools for Do It Yourself Climate Trend Analysis – Nov, 2010 Update | Climate Charts & Graphs

  8. Pingback: RClimate Script: Pacific Decadal Oscillation Trend « Climate Charts & Graphs

  9. Pingback: Meteorologist Misreads Arctic Sea Ice Extent Trends « Climate Charts & Graphs

  10. Pingback: RClimate Script: Global Mean Sea Level Trend by Month « Climate Charts & Graphs

  11. Pingback: RClimate Script: Arctic Sea Ice Extent Trend By Month « Climate Charts & Graphs

  12. Pingback: RClimate Script: NINO 3.4 SST Anomaly Trends « Climate Charts & Graphs

  13. Pingback: RClimate Script: Polar Amplification – 2000 to 2009 « Climate Charts & Graphs

  14. Pingback: RCimate Script: Recent Total Solar Irradiance (TSI) Trends « Climate Charts & Graphs

  15. Pingback: RClimate Script: CO2 Trends « Climate Charts & Graphs

  16. Thanks a lot for the nice script! A month ago, I went mad while reading this NASA GISS data file into R and capitulated.

    If anybody want to calculate the significance (p-value) of the linear trend line using the signal-to-noise ratio, add only the following to the end of this script:
    snr <- (y2 – y1) / sd(GISS_sub$GISS_anom)
    p <- dnorm(snr)
    names(p) <- "p-value"
    p

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s