pixelsize: The actual size of each grid cell with considerable...

pixelsizeR Documentation

The actual size of each grid cell with considerable distortion in area of map projection.

Description

This function helps to calculate size of pixels in the unit of area (squared km) for zonal statistics with taking into account distortion in area for classes of projections.

Usage

pixelsize(obj, verbose = FALSE)

Arguments

obj

Either ursaRaster object or ursaGrid object or NULL or missing.

verbose

Logical. Value TRUE may provide some additional information on console. Default is FALSE.

Details

pixelsize() is applied to coordinate reference system (grid) of ursaRaster object or to raster grid directly. If argument obj is missed, then session grid is used.

Currently, only Stereographic ("+stere" in PROJ.4 notation), Mercator ("+merc"), and Lambert Azimuthal Equal Area ("+laea") classes of map projections are implemented, though the last one (LAEA) has no distortion in area.

Value

Object of class ursaRaster, single-band. If size of cell is more than 10e5 square meters, then the unit is squared kilometers (band name is "Pixel Size (sq.km)") else squared meters (band name is "Pixel Size (sq.m)").

Author(s)

Nikita Platonov platonov@sevin.ru

Examples

session_grid(NULL)
pixelsize()

 ## internet connection is required; access was tested on 2018-06-04
invisible({
   dpath <- file.path("ftp://sidads.colorado.edu/pub/DATASETS"
                     ,"nsidc0081_nrt_nasateam_seaice/north")
   dst <- tempfile(fileext=".bin")
   isOK <- FALSE
   d3 <- Sys.Date()
   for (i in seq(5)) {
      src <- file.path(dpath,format(d3,"nt_%Y%m%d_f18_nrt_n.bin"))
      a <- try(download.file(src,dst,mode="wb"))
      if ((is.integer(a))&&(a==0)) {
         isOK <- TRUE
         break
      }
      d3 <- d3-1
   }
   if (isOK) {
      g1 <- regrid(bbox=c(-385,-535,375,585)*1e4,res=25*1e3
                  ,crs=paste("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45"
                            ,"+k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449"
                            ,"+units=m +no_defs"))
      session_grid(g1)
      b <- readBin(dst,integer(),size=1L,n=136492L,signed=FALSE)
      ice <- ursa_new(value=tail(b,-300))
      ice[ice>251] <- NA ## keep Pole
      ice[ice==251] <- 250 ## consider 100% ice at Pole
      ice <- ice/2.5 ## uncategorize
      ice[ice<15] <- 0 ## not ice, if less 15%
      ice[ice>0] <- 100
      extent1 <- band_sum(ice*1e-2*ursa(ice,"cell")^2*1e-6)*1e-6
      extent2 <- band_sum(ice*1e-2*pixelsize(ice))*1e-6
      message(paste("Near real-time Arctic sea ice extent (NASA Team algorithm, NSIDC)"))
      message(sprintf("   Direct area calculation:         %5.2f*1e6 km^2.",extent1))
      message(sprintf("   Distortion in area is corrected: %5.2f*1e6 km^2.",extent2))
   }
   else
      message("It is failed to get sea ice concentration data.")
})


ursa documentation built on Oct. 17, 2023, 5:11 p.m.