[R-sig-Geo] Masking a raster changes its min and max values

Thiago Veloso thi_veloso at yahoo.com.br
Thu Aug 16 15:02:29 CEST 2012


  Dear colleagues,

  To mask this image (note max and min values):

> lai.cal
class       : RasterLayer 
dimensions  : 5568, 8289, 46153152  (nrow, ncol, ncell)
resolution  : 0.00898, 0.00898  (x, y)
extent      : -104.4326, -29.99736, -40.00064, 10  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
values      : /mnt/disco3/MODIS/original_images/temp/R_raster_tmp/thiago/raster_tmp_2012-08-16_081042_8103108.grd 
layer name  : layer 
min value   : 0 
max value   : 7 

  I am using raster's mask function. Here is the raster object I am using to mask (which is composed only of 0's and NA's):

> qc.cal
class       : RasterLayer 
dimensions  : 5568, 8289, 46153152  (nrow, ncol, ncell)
resolution  : 0.00898, 0.00898  (x, y)
extent      : -104.4326, -29.99736, -40.00064, 10  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
values      : /mnt/disco3/MODIS/original_images/temp/R_raster_tmp/thiago/raster_tmp_2012-08-16_080805_76515.grd 
layer name  : layer 
min value   : 1 
max value   : 1 


  However, please see the min and max values of the resulting raster:

> laiqc <- mask (lai.cal,qc.cal
> laiqc
class       : RasterLayer 
dimensions  : 5568, 8289, 46153152  (nrow, ncol, ncell)
resolution  : 0.00898, 0.00898  (x, y)
extent      : -104.4326, -29.99736, -40.00064, 10  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
values      : /mnt/disco3/MODIS/original_images/temp/R_raster_tmp/thiago/raster_tmp_2012-08-16_081343_910828.grd 
layer name  : layer 
min value   : 0.1 
max value   : 6.9 

  Does anyone know why this happens? How can I prevent this from happening?

  Latest R version running with updated packages. See below my session info:

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ncdf_1.6.6      raster_2.0-08   maptools_0.8-16 lattice_0.20-6  foreign_0.8-50  rgdal_0.7-12    sp_0.9-99      

loaded via a namespace (and not attached):
[1] grid_2.15.1  tools_2.15.1

  Thanks in advance,
  Thiago.




More information about the R-sig-Geo mailing list