[R] netCDF to TIFF

From: Daniel Steinberg <d.c.steinberg_at_gmail.com>
Date: Wed, 09 Jul 2008 14:34:16 +0200

Greetings R users!

I am working with the ENSEMBLE climate data (10 min resolution daily temperatures images for all of Europe 1950-2006). The data comes packaged in a single netCDF file. I would like to read the data in and export a subset (2002-2006) as geotiffs (one image per day). So far, I can successfully read in the data and view the images within an R display window. However, I have yet to figure out how to export the images as tiffs or geotiffs. Does anyone out there have experience converting netCDF grids to TIFFs?

After reading the data into R, I have it stored in a dataframe with longitude values as the column names, latitude values as the row names, and temperatures as the actual values. Below is my code thus far that I adapted from an example on the UCAR website.

Thanks in advance!


# Set working directory and load library



# Read netCDF file

tg.ncdf = open.ncdf('tg_0.25deg_CRU_version1.0.nc') tg.ncdf

lonmat  = get.var.ncdf(nc=tg.ncdf,varid="longitude")   # reads entire matrix
latmat  = get.var.ncdf(nc=tg.ncdf,varid="latitude")    # ditto
timearr = get.var.ncdf(nc=tg.ncdf,varid="time")        # reads entire time array

targettime = julian(x=1, d=1, y=2002, origin=c(month = 1, day = 1, year = 1950))

inds       = (1:dim(timearr))
tind       = inds[targettime == timearr]

ndims = tg.ncdf$var[['data']]$ndims
varsize = tg.ncdf$var[['data']]$varsize         

start = c( 1, 1, tind)
count = c(varsize[1], varsize[2], 1)

# Read in data slice:

tg.data = get.var.ncdf(nc=tg.ncdf,varid="data",start,count)
tg.data[tg.data == -9999] = NA
tg.data = tg.data/100.0
x = 1:nrow(tg.data)   # R plots rows along X axis!
y = 1:ncol(tg.data)

test.data = data.frame(tg.data, row.names = lonmat) colnames(test.data) = latmat

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jul 2008 - 12:41:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jul 2008 - 20:33:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive