<commit_before>#' Function to batch download gridded DAYMET data
#'
#' This function downloads DAYMET data 
#' @param lat1 : top left latitude (decimal degrees)
#' @param lon1 : top left longitude (decimal degrees)
#' @param lat2 : bottom right latitude (decimal degrees)
#' @param lon2 : bottom right longitude(decimal degrees)
#' @param start_yr : start of the range of years over which to download data
#' @param end_yr : end of the range of years over which to download data
#' @param param : climate variable you want to download vapour pressure (vp), 
#' minimum and maximum temperature (tmin,tmax), snow water equivalent (swe), 
#' solar radiation (srad), precipitation (prcp) , day length (dayl).
#' The default setting is ALL, this will download all the previously mentioned
#' climate variables.
#' @keywords DAYMET, climate data
#' @export
#' @examples
#' download.daymet.tiles(lat1=35.6737,
#'                       lon1=-86.3968,
#'                       start_yr=1980,
#'                       end_yr=1980,
#'                       param="ALL")

download.daymet.tiles = function(lat1=35.6737,
                                 lon1=-86.3968,
                                 lat2=NA,
                                 lon2=NA,
                                 start_yr=1980,
                                 end_yr=1980,
                                 param="ALL"){
  
  # determine system
  OS = Sys.info()[['sysname']]
  
  # load DAYMET grid associated with the package
  # (this is an imported shapefile)
  # I do not store any additional data in the .rdata
  # file to keep the code transparent.
  #data("DAYMET_grid")
  
  # grab the projection string. This is a LCC projection.
  projection = sp::CRS(sp::proj4string(tile_outlines))
  
  # extract tile IDs (vector shape) and the DAYMET IDs associated
  # with them
  tile_nrs = tile_outlines@data[,1]
  
  # if argument 3 or 4 are the default grab only the tile
  # of the first coordinate set, if 4 arguments are given
  # extract all tile numbers within this region of interest
  if ( is.na(lat2) | is.na(lon2)){
    
        # create coordinate pairs, with original coordinate  system
        location = sp::SpatialPoints(cbind(lon1,lat1), projection)
        
        # extract tile for this location
        tiles = sp::over(location,tile_outlines)$TileID
        
        # do not continue if outside range<commit_msg>loading data<commit_after>#' Function to batch download gridded DAYMET data
#'
#' This function downloads DAYMET data 
#' @param lat1 : top left latitude (decimal degrees)
#' @param lon1 : top left longitude (decimal degrees)
#' @param lat2 : bottom right latitude (decimal degrees)
#' @param lon2 : bottom right longitude(decimal degrees)
#' @param start_yr : start of the range of years over which to download data
#' @param end_yr : end of the range of years over which to download data
#' @param param : climate variable you want to download vapour pressure (vp), 
#' minimum and maximum temperature (tmin,tmax), snow water equivalent (swe), 
#' solar radiation (srad), precipitation (prcp) , day length (dayl).
#' The default setting is ALL, this will download all the previously mentioned
#' climate variables.
#' @keywords DAYMET, climate data
#' @export
#' @examples
#' download.daymet.tiles(lat1=35.6737,
#'                       lon1=-86.3968,
#'                       start_yr=1980,
#'                       end_yr=1980,
#'                       param="ALL")

download.daymet.tiles = function(lat1=35.6737,
                                 lon1=-86.3968,
                                 lat2=NA,
                                 lon2=NA,
                                 start_yr=1980,
                                 end_yr=1980,
                                 param="ALL"){
  
  # determine system
  OS = Sys.info()[['sysname']]
  
  # load DAYMET grid associated with the package
  # (this is an imported shapefile)
  # I do not store any additional data in the .rdata
  # file to keep the code transparent.
  data("DAYMET_grid")
  
  # grab the projection string. This is a LCC projection.
  projection = sp::CRS(sp::proj4string(tile_outlines))
  
  # extract tile IDs (vector shape) and the DAYMET IDs associated
  # with them
  tile_nrs = tile_outlines@data[,1]
  
  # if argument 3 or 4 are the default grab only the tile
  # of the first coordinate set, if 4 arguments are given
  # extract all tile numbers within this region of interest
  if ( is.na(lat2) | is.na(lon2)){
    
        # create coordinate pairs, with original coordinate  system
        location = sp::SpatialPoints(cbind(lon1,lat1), projection)
        
        # extract tile for this location
        tiles = sp::over(location,tile_outlines)$TileID
        
        # do not continue if outside range
{'fraction_non_alphanumeric': 0.0895615866388309, 'fraction_numerical': 0.024634655532359082, 'mean_word_length': 2.3597475455820476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5491854', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1286, 'n_words': 484}