[R-sig-Geo] Extract spatial mean of subset of netCDF.
Aseem Sharma
nature.aseem at gmail.com
Sat Dec 6 17:47:20 CET 2014
Hi,
I am new with raster work in R.
I am trying to get the spatial mean of a subset (define by the extent) of
larger domain netCDF data file using raster and ncdf packages
The netCDF data of Snow Water Equivalent(SWE) were obtained from
http://www.globsnow.info/swe/archive_v2.0/. The two files I have used are
nc1
<https://www.dropbox.com/s/tk388w67tjg704s/GlobSnow_SWE_L3A_19900101_v2.0.nc?dl=0>
and nc2
<https://www.dropbox.com/s/pft2dlio96n6ncw/GlobSnow_SWE_L3A_19900102_v2.0.nc?dl=0>
.
The codes I used are
library(raster)
library(ncdf)
nc1<-"C:\\Users\\bunug_000.BUNU\\Documents\\Dropbox\\Public\\
GlobSnow_SWE_L3A_19900101_v2.0.nc"
nc2<-"C:\\Users\\bunug_000.BUNU\\Documents\\Dropbox\\Public\\
GlobSnow_SWE_L3A_19900102_v2.0.nc"
about_nc<-open.ncdf(nc1)
print(about_nc)
nc_data<-stack(nc1,nc2,varname="SWE")
print(nc_data)
dim(nc_data)
nc_data1<-brick(nc_data)
plot(nc_data1)
subsetd<-extent(-78,-74,50,52)
subsetd
crop_data <- crop(nc_data1, subsetd)
dim(dt.ras.c)
dt.anm<-as.data.frame(cbind(unname(cellStats(dt.ras.c,
stat="mean")),seq(1:2))) # use unname to separate named numebr to just
numbers
str(dt.anm)
colnames(dt.anm)<-c("Mean_SWE","ID")
What is not right here so that I am not getting mean SWE. It should not be
-1.
Any suggestions will be highly appreciated.
Thank you.
------------------
"Namaste नमस्ते"
Aseem Sharma
Graduate Research Assistant
Northern Hydrometeorology Group(NHG)
Natural Resources and Environmental Studies Institute(NRESi)
University of Northern British Columbia
Prince George, BC, V2N 4Z9, Canada
Tel: 250-960-5427
Web: http://www.unbc.ca/
"All know the Way, but few actually walk it."
"सबैको कल्याण होस् ।"
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list