[R] HIRHAM netcdf files

Ana rrasterr at gmail.com
Fri Jul 29 17:34:28 CEST 2011


Hi! Thank you all. I finally understood the way to solve the problem
from Barry's mail.

>From the file created with coordinates(Lat,Long) using fan, everything
looks ok (wgs84). I will now try Bryan's approach in R.

Ana


On Fri, Jul 29, 2011 at 4:22 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
>>        float lat(rlat, rlon) ;
>>                lat:standard_name = "latitude" ;
>>                lat:long_name = "latitude" ;
>>                lat:units = "degrees_north" ;
>>        float lon(rlat, rlon) ;
>>                lon:standard_name = "longitude" ;
>>                lon:long_name = "longitude" ;
>>                lon:units = "degrees_east" ;
>
>  These two previous variables are grids of lat-lon values that
> correspond to the data. I nabbed a .ncdf file of runoff values from a
> site:
>
> library(ncdf)
> r = open.ncdf("runoff.SMHI.MPIB2.nc")
>  dim(get.var.ncdf(r,"lat"))
> [1] 90 86
>  dim(get.var.ncdf(r,"lon"))
> [1] 90 86
>
>  so when you get the 90x86 grids of runoff values, the lat-long
> coordinates are the corresponding ones in the "lat" and "lon"
> variables.
>
> lon = get.var.ncdf(r,"lon")
> lat = get.var.ncdf(r,"lat")
> # get data for t = 1:
> t1 = get.var.ncdf(r,"runoff",start=c(1,1,1),count=c(90,86,1))
>
>  now you have three 90x86 matrices. To get (x,y,runoff) matrix, we
> just put them together, something like:
>
> library(sp)
> xyr = data.frame(cbind(as.vector(lat),as.vector(lon),as.vector(t1)))
>
>  names(xyr)=c("lat","lon","runoff")
>  coordinates(xyr)=~lon+lat
>  spplot(xyr,"runoff")
>
>  - shows how non-griddy the projection really is - it should look like
> a fan since now we are showing the data on true lat-long points, not
> the transformed rlat rlong points.
>
>  The rlat and rlon variables are the grid coordinate system, which
> appears to be some non-standard conical projection. Climate
> scientists!
>
> Details: http://prudence.dmi.dk/public/DDC/areas.html
>
> Barry
>



More information about the R-help mailing list