HI Robert

Thank you for your reply, resampling the fpu worked out well.

But now I am getting another error on zonal:
precip <- stack ("cnrm_cm3_sresa2_precip_monthly_2001_2050.nc",
varname="Precip")*
z <- zonal(precip, fpu, stat = 'mean')

error:

Error in FUN(X[[1L]], ...) :
  2 arguments passed to 'length' which requires 1


But it is running perfectly for a single layer;

 z <- zonal(precip[[1]], fpu, stat = 'mean')


What might be going wrong here?
Thank you

Regards

Sajid

On Wed, Dec 7, 2011 at 10:55 PM, Robert J. Hijmans <r.hijmans@gmail.com>wrote:

>
> Sajid,
>
> I think that this cryptic error occurs because "fpu" has no values. As you
> change the number of columns of the object, the values are lost:
>
> dim(fpu) <- 360
>
> You are setting the number of rows of fpu to 360. Is that intended? If it
> is, you should probably use crop or expand (or both), or resample, to
> change the number of rows/columns (while keeping the cell values).
>
> This is also questionable: extent(fpu) <- extent(precip)  unless you are
> correcting for something like a rounding error.
>
> Robert
>
>
>  On Wed, Dec 7, 2011 at 3:46 AM, sajid pareeth <spareeth@gmail.com> wrote:
>
>> Hi
>>
>> I have downloaded netcdf files representing climate data with one variable
>> and time as dimension. It is monthly data for 50 years, hence 600 bands or
>> layers in one .nc file.
>>
>> Now I am trying to do zonal stat against another zonal raster layer I am
>> getting an error. I tried directly with nc file and also tried after
>> converting the nc into tif file.
>>
>> Below given is the code i am using;
>>
>> *library(raster)*
>> **
>> *setwd("D:///")*
>> *precip <- brick("cnrm_cm3_sresa2_precip_monthly_2001_2050.nc
>> ",varname="Precip")*
>> *fpu <- raster("fpu_raster") # zonal raster*
>> **
>> *extent(fpu) <- extent(precip)
>>
>> dim(fpu) <- c(360)
>> projection(fpu) <- "+proj=longlat +datum=WGS84 +ellps=WGS84
>> +towgs84=0,0,0"  # these three lines, to make the zonal dimensions match
>> with input nc file.*
>> **
>> *x <- data.frame(zonal(precip, fpu, stat = 'mean'))
>>
>> write.table(x, file = "output1.csv", sep = ",", col.names = NA,qmethod =
>> "double")*
>>
>>
>> I am expecting a csv file with 600 columns and zones as rows with mean
>> value calculated.
>>
>> But when I am running the zonal function line, I am getting the following
>> error.
>>
>>
>> " Error in aggregate.data.frame(alltab[, 2:ncol(alltab)], by =
>> list(alltab[,  :
>>  no rows to aggregate"
>>
>>
>>
>> Any idea what it could be?
>>
>> Also how to retrieve stats for all the 600 layers in one go?
>>
>> Really appreciate any help on this...
>>
>>
>>
>> Regards
>>
>> --
>> Sajid Pareeth
>>
>> IWMI, Colombo
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>


-- 
Sajid Pareeth

IWMI, Colombo

	[[alternative HTML version deleted]]

