[R] read a netcdf file _Fill_value=-32768

francoise orain francoise.orain at meteo.fr
Fri May 6 19:11:33 CEST 2011


Hello
I am a new user of R .
and I ve problem with R and netcdf .
I succed installation , I could use all examples .
But when I take my netcf it is different .

I want to do statistic on this kind of file .

1)
first calculate mean .
my data is like that
through ncdump -h test.nc

netcdf test {
dimensions:
        lat = 301 ;
        lon = 401 ;
        time = UNLIMITED ; // (80 currently)
variables:
        float lat(lat) ;
                lat:long_name = "latitude" ;
                lat:standard_name = "latitude" ;
                lat:units = "degrees_north" ;
                lat:valid_range = -60., 60. ;
        float lon(lon) ;
                lon:long_name = "longitude" ;
                lon:standard_name = "longitude" ;
                lon:units = "degrees_east" ;
                lon:valid_range = -100., 45. ;
        double sst(time, lat, lon) ;
                sst:long_name = "sea surface temperature" ;
                sst:standard_name = "sea_surface_temperature" ;
                sst:units = "K" ;
                sst:_FillValue = -32768. ;
        double time(time) ;
                time:long_name = "time" ;
                time:standard_name = "time" ;
                time:units = "seconds since 1981-01-01 00:00:00" ;
                time:ancillary_variables = "sst_data_processed_flag" ;

I succeed to read it with R, there is only one variable sst   80 days 
and lat = 301     lon = 401 (this file is already a concatenation with 
nco fonctions .

Here is what I do :

nc<-open.ncdf("test.nc")
summary (nc)
data<- get.var.ncdf(nc)
print (data)

answer extract :

[331,] -32768.00 -32768.00 -32768.00 -32768.00 -32768.00 -32768.00 -32768.00
[332,] -32768.00 -32768.00 -32768.00 -32768.00 -32768.00 -32768.00 -32768.00
          [,295]    [,296]    [,297]    [,298]    [,299]    [,300]    [,301]
  [1,]      0.10      0.10      0.12      0.15      0.15      0.14      0.15
  [2,]      0.12      0.12      0.13      0.15      0.15      0.14      0.15
  [3,]      0.13      0.13      0.13      0.16      0.14      0.14      0.14
  [4,]      0.15      0.13      0.11      0.16      0.15      0.15      0.15
  [5,]      0.17      0.16      0.15      0.15      0.16      0.17      0.15

#_fill_value is at  -32768.00

[ reached getOption("max.print") -- omitted 69 row(s) and 79 matrix 
slice(s) ] OK too long
 > mean(data, na.rm=TRUE)
[1] -20020.35
 > summary(data)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
-32770.00 -32770.00 -32770.00 -20020.00      0.42      6.59
 > q()


It is clear that the missing value_FillValue = -32768.  here , is used 
to calculate the mean , the Median etc .
But I don't  succed to avoid NA value in the sum ???


I've seen set.missval.ncdf but I don't succeed anymore to make R 
understand that -32768  is a  missing_value.

What  are my mistakes , has someone an example or a solution ?

2)
Then after I want to calculate correlation between this one and another 
one , so my time dimension is 80  (80 days) but my time variable is 
always the same (because of concatenation with nco ) how can I  
calculate cor(data1,data2)
and be sure that the correlation is not calculate between day1 and day50 
for instance .

Thanks

Françoise Orain

 .

 



More information about the R-help mailing list