R/readGridParams.R

Defines functions readGridParams

Documented in readGridParams

#' @title Reads the parameters of the grid.
#'
#' @description Reads the parameters of the grid overlapped on the geographical 
#'  of interest  from a .csv file.
#'
#'
#' @param gridFileName The name of the file with the grid parameters. This file 
#' could be the one generated by the simulation software or can be created with 
#' any text editor. The grid file generated by the simulation software has the 
#' following columns: \code{Origin X, Origin Y, X Tile Dim, Y Tile Dim, No Tiles X, No Tiles Y}. 
#' We are interested only in the number of rows and columns and the tile size on 
#' OX and OY axes. Therefore, the file provided as input to this
#' function should have at least the following 4 columns: 
#' \code{No Tiles X , No Tiles Y, X Tile Dim, Y Tile Dim}.
#'
#'
#' @return Returns a list with the following items: \code{nrow} - the number of 
#' rows, i.e. the number of tiles in a column of the grid, \code{ncol} - the 
#' number of columns, i.e. the number of tiles in a row of the grid, 
#' \code{tileX} - the dimension of a tile on OX axis, \code{tileY} - the 
#' dimension of a tile on OY axis.
#'
#'
#' @import data.table
#' @export
readGridParams <- function(gridFileName) {
  if (!file.exists(gridFileName))
    stop(paste0(gridFileName, " does not exists!"))
  
  gridParam <- fread(
    gridFileName,
    sep = ',',
    header = TRUE,
    stringsAsFactors = FALSE
  )
  nrows_grid  <- gridParam[['No Tiles Y']]
  ncols_grid  <- gridParam[['No Tiles X']]
  tile_sizeX <- gridParam[['X Tile Dim']]
  tile_sizeY <- gridParam[['Y Tile Dim']]
  return (list(
    nrow = nrows_grid,
    ncol = ncols_grid,
    tileX = tile_sizeX,
    tileY = tile_sizeY
  ))
}
bogdanoancea/deduplication documentation built on Dec. 2, 2020, 11:22 p.m.