Moshtemp4.0

[This article was first published on Steven Mosher's Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Now that SST has been processed with raster we can return to the land processing and put that on the same footing. To get there I’ll rebuild from scratch making some minor adjustments along the way. As we go foward the amount of code we have to write should become less and less because we are letting raster do things for us.

As much as I hate to trash old code I wrote putting everything into raster will be the right thing to do. In the end the vast majority of the code we have will be basic bookkeeping code and project organizing code. So, I spent sometime looking at new R packages ( project template) and spent time trying to bullet proof the installation and the file handling. As a result, the code will now check for installed packages and install them only of they are not installed. The other problem that remains is the “uncompress” issue with .Z files. Following Ron Broberg, SteveMc has a nifty little solution for this problem. First, what’s the problem:

Many of the files we deal with are tar and/or .Z files. .Z is a old Unix compression standard. many folks have moved on from this. But there  are some who still use the format. Ron’s solution and Steve’s after him was to put the uncompress exe in on the system path and then invoke an R system() call, calling the uncompress with  the file as a parameter. Pretty slick!  I tried to use the R package “uncompress” but I get failures as did SteveMc. I prefer the R package approach. So, I’m trying to contact the maintainer to update his package. The source is available, so any c programmer should be able to figure it out. When Time permits I’ll look at his source and see if I can find the bug. It’s a unexpected EOF type error. I’m suspecting that he only tested on Linux since he’s a linux guy and that the tests Cran runs are not sufficient. SteveMc runs windows and I use MAC. Wonder if Ron Broberg had any luck on linux.

We will start by rebaselining. Moshtemp4 Zip will go up at the drop and in the box on this page.

Unzip it. Make it your working directory and run Downloadall.R That script will take a while. It will download all the assets you need. The files, masks, inventories, and CRU results which we will eventually calibrate against.  you will then have to manually uncompress v2.mean.Z. On the Mac thats just a click and on linux uncompressed should also be built it.

next run SetUpData.R.  That script will create

1. V2Mean.Rdata: this is a processed version of v2mean with all duplicates averaged

2. V2Anomalies.Rdata: this is giant matrix of all stations. StationID is in the column. Every row is a month of anomaly in C ( not tenths) from 1900 to 2009.

3. SST.Rdata: a brick of SST anomalies from 1900 to 2009

After SetUpData completes, you can test it by doing this:

plot(V2Anomalies[,150])

You could even loop thru all 5072 stations and plot every one [ see the routine, plotAnomalySeries() ] You can also check out the calibration data:

Y<-read.HadResults(CruResults)

names(Y)
[1] “Years”   “Annual”  ”Monthly” “Percent”
then Y$Monthly or Y$Annual to check out the numbers
Y<-read.HadResults(HadCrutResults)
Finally, Robert has sped up some features in raster (stackApply) and he’s got some new code that will help me build a raster brick directly from my matrix of V2Anomalies. So in one line we will take that V2Anomaly object and ‘grid’ it, average stations within a grid, and build a brick where every layer is a month. I end up throwing away some of the final bits of the code I wrote. So, while he and I test that stuff have at Moshtemp4.

To leave a comment for the author, please follow the link and comment on their blog: Steven Mosher's Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)