Tuesday, 15 July 2014

r - extract from NetCDF files using X, Y coordinates -



r - extract from NetCDF files using X, Y coordinates -

i new r. had netcdf file has 3 dimenstions viz time,x,y , has got 6 variables viz rain,tair,swin,lwin,rh , wind. want extract time series info of each variable according time dimenstion , export them csv format. have used next sets of codes couldnt single point. want extract info @ 2 points (30000000,810000) , (3100000,820000)

setwd("c:/users/a/desktop/pd/1/") f<-open.ncdf("merra.rfe.90m.200208.nc") t<-get.var.ncdf(f,varid="time") b<-get.var.ncdf(f,varid="rain") c<-get.var.ncdf(f,varid="tair") write.table(t(rbind(a,b,c)),file="output.csv")

but dont know how inject these coordinates. have found codes lat , long format have x , y coordinates. quite generous of if 1 of stepout , help me problem.

i guess using ncdf package. improve utilize ncdf4 or raster packages.

i'm not sure understand asking. if post original file (trimmed downwards if big) better.

if understood mean, want on lines of this:

library(ncdf4) f <- nc_open("file.nc") t <- ncvar_get(f, "rain") point1_t <- t[30000000,810000,] #notice "," point2_t <- t[3100000,820000,] #etcetera

you didn't specify if 30000000,810000 x,y coordinates or in unit system. if x,y coordinates , file has correctly set x-y dimensions should go above.

if values expressed in units, not x-y pixel values (e.g. pixel [30,12]=(100000,400000)meters ), should have them stored in variables. if case:

x <- ncvar_get(f, "x") y <- ncvar_get(f, "y") which(x == 30000000 && y == 810000, arr.ind=t)

...will homecoming xy coordinates of pixels have x=30000000 , y=810000. 1 time know xy pixel coordinates it's easy plenty extract values done before. hope made myself clear, it's not easy missing input file.

r extract netcdf

No comments:

Post a Comment