[R] netCDF to TIFF
Yasir Kaheil
kaheil at gmail.com
Wed Jul 9 20:54:19 CEST 2008
the function is there in grDevices
http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/png.html
type ? png
if tiff() is not listed, you need to update R to get the new base with new
grDevices.
thanks
y
Daniel Steinberg wrote:
>
> 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!
>
> -Dan
>
> --------------------------------------------------------------------------------------------------
> # Set working directory and load library
>
> setwd('C:/Users/steinber/Documents/DATA/ENSEMBLES/')
> library(ncdf)
> library(rgdal)
> library(chron)
> library(fields)
>
> # 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)
> image.plot(x,y,tg.data,col=tim.colors())
>
> 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.
>
>
-----
Yasir H. Kaheil
Columbia University
--
View this message in context: http://www.nabble.com/netCDF-to-TIFF-tp18360688p18368372.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list