[R-sig-Geo] SpatialGridDataFrame Help

dkod koday at processtrends.com
Thu Aug 26 03:34:05 CEST 2010


I am trying to develop simple tools to download and plot climate data based
on global grid of 2 degrees. Here's a link to the source image 
http://data.giss.nasa.gov/work/gistemp/NMAPS/tmp_GHCN_GISS_HR2SST_1200km_Anom07_2010_2010_1951_1980/GHCN_GISS_HR2SST_1200km_Anom07_2010_2010_1951_1980.gif
link 

NASA provides a 5 column text file for each image of monthly global
temperature anomalies. I have downloaded a sample data file that can be
viewed  http://processtrends.com/Files/global_lota_map_07_36.txt here .

I have been using Bivand et al's Applied Spatial Data Analysis With R to try
to speed up my learning curve, however, I am stumped and need some help.

Here's my script so far:

#################################################################
### Read GISS global temp anom for month by 2 degree grid
  library(fields);library(mapproj)
  library(sp); library(rgdal)

# Step 1: Read source data file
  link <- "http://processtrends.com/Files/global_lota_map_07_36.txt"
  rdf <- read.table(link, skip = 1, header=T)
  a_rdf <- data.frame(rdf[,c(1,2,5)])
  names(a_rdf) <- c("i", "j","anom")
  a_rdf$anom[a_rdf$anom==9999.0000] <- NA         # convert all 9999.0000 to
NA

## Step 2: Setup sp() classes for GridTopology & SpatialGrid 
  grd <- GridTopology(cellcentre.offset=c(-179,-89), cellsize=c(2,2), 
   cells.dim=c(180,90))
  gr_sp <- SpatialGrid(grid=grd, proj4string = CRS(as.character(NA)))
  a_rdf_sp <- SpatialGridDataFrame(grd, a_rdf)
 
## Step 4: Create SpatialGridDataFrame
  fullgrid(a_rdf_sp) <- T
  slot(a_rdf_sp, "grid")
 
## Step 5: Generate Plot
  image.plot(a_rdf_sp["anom"])
 
##############################################################

It runs without error mesages until the image.plot() command. here's the
error message I get

  > image.plot(a_rdf_sp["anom"])
     Error in if (del == 0 && to == 0) return(to) : 
     missing value where TRUE/FALSE needed
  > 

I'm not clear how to best establish a SpatialGridDataFrame for global data
series from 2 or 5 degree files. I'd like to be able to plot using mercator
or other projection.

I'd also like to be able to add land forms.

I'd appreciate any help in correcting/improving this script. My goal is a
clear, easy to follow R script that can be used by R users to download and
work with global climate data files from NASA, NOAA and other agencies.

D Kelly O'Day
http://chartsgraphs.wordpress.com
http://processtrends.com




-- 
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/SpatialGridDataFrame-Help-tp5463824p5463824.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list