├── .Rbuildignore ├── .gitignore ├── CONTRIBUTIONS.md ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── .Rapp.history ├── agronomic-crops.R ├── agronomic-norms.R ├── agronomic-values.R ├── checkDataReturn.R ├── checkStatusCodeOfReturn.R ├── checkValidParamsFns.R ├── cleanupAPIReturns.R ├── create-awhere-grid.R ├── create-shapewkt.R ├── create.R ├── delete.R ├── forecasts.R ├── get-token.R ├── get.R ├── grid-functions.R ├── models.R ├── plan_APICalls.R ├── soils.R ├── update.R ├── utility.R ├── verify-api-calls.R ├── weather-daily.R └── weather-norms.R ├── README.md ├── documentation └── complete-documentation.md ├── man ├── agronomic_norms_area.Rd ├── agronomic_norms_fields.Rd ├── agronomic_norms_latlng.Rd ├── agronomic_values_area.Rd ├── agronomic_values_fields.Rd ├── agronomic_values_latlng.Rd ├── checkAccumulationStartDate.Rd ├── checkAccumulationStartDateNorms.Rd ├── checkCredentials.Rd ├── checkDataReturn_daily.Rd ├── checkDataReturn_forecasts.Rd ├── checkDataReturn_norms.Rd ├── checkForecastParams.Rd ├── checkForecastSources.Rd ├── checkGDDParams.Rd ├── checkNormsStartEndDates.Rd ├── checkNormsYearsToRequest.Rd ├── checkPropertiesEndpoint.Rd ├── checkStatusCode.Rd ├── checkValidField.Rd ├── checkValidLatLong.Rd ├── checkValidStartEndDates.Rd ├── checkValidStartEndDatesAgronomics.Rd ├── checkValidStartEndDatesForecast.Rd ├── check_JSON.Rd ├── create_awhere_grid.Rd ├── create_field.Rd ├── create_planting.Rd ├── create_shapewkt.Rd ├── custom_fortify.Rd ├── daily_observed_area.Rd ├── daily_observed_fields.Rd ├── daily_observed_latlng.Rd ├── delete_field.Rd ├── delete_planting.Rd ├── forecasts_area.Rd ├── forecasts_fields.Rd ├── forecasts_latlng.Rd ├── getGridX.Rd ├── getGridY.Rd ├── get_crops.Rd ├── get_fields.Rd ├── get_model_details.Rd ├── get_model_results.Rd ├── get_models.Rd ├── get_planting.Rd ├── get_token.Rd ├── load_credentials.Rd ├── plan_APICalls.Rd ├── recalculateAccumulations.Rd ├── removeUnnecessaryColumns.Rd ├── soils_area.Rd ├── soils_fields.Rd ├── soils_latlng.Rd ├── update_field.Rd ├── update_planting.Rd ├── verify_api_calls.Rd ├── weather_norms_area.Rd ├── weather_norms_fields.Rd └── weather_norms_latlng.Rd ├── previousVignettes ├── Documentation.Rmd ├── aWhereAPI.R ├── aWhereAPI.Rmd └── aWhereAPI_vignette.htm ├── tests ├── testthat.R └── testthat │ ├── credential.txt │ ├── test-agronomics.R │ ├── test-create-delete-update.R │ ├── test-forecast.R │ ├── test-get-token.R │ ├── test-get.R │ └── test-weather.R └── vignettes ├── .build.timestamp ├── Area_Analysis.R ├── Area_Analysis.Rmd ├── Installing_the_aWhere_API_Package.Rmd ├── Using_the_API.Rmd └── credentials_trial.txt /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Meta 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | .Rbuidignore 6 | .Ruserdata 7 | *.rds 8 | /doc 9 | aWhere-R-Library_github.Rproj 10 | *.Rproj 11 | aWhereRLibrary_Github.RData 12 | -------------------------------------------------------------------------------- /CONTRIBUTIONS.md: -------------------------------------------------------------------------------- 1 | # Contributing Code to aWhere Repositories 2 | 3 | We welcome contributions to our code samples, libraries, SDKs, widgets, sample applications, and other code resources hosted through GitHub. Please feel free to fork, edit, add, and then send us your changes through a pull request. Someone from our team will review your code, work with you to make any adjustments, and then merge it into our public repo. 4 | 5 | Contributed code or edits will become part of the main repository offered by aWhere, Inc., and governed by the license designated in the GitHub repository (usually the MIT License). By contributing code or edits to code, you are agreeing to release any claim of copyright, royalty, or exclusivity for the use of the code. You also grant aWhere a universal and irrevocable right to publish, edit, use the code in our products (free or commercial), publish the code on our Developers Portal (developer.awhere.com), and other reasonable purposes. You're also allowing for other developers, both independent and commercial, to use your contributed code in their projects. 6 | 7 | Contributed code will be attributed to you with your name and/or github username, plus website or email address if desired. Edits to your contributed code may bring additional attributions, but your name will not be removed. Attributions may be made in an ancillary file provided with the repo. 8 | 9 | We cannot guarantee that all contributed code will be merged into the repository, and we may choose to unpublish or delete any code or repository at any time. 10 | 11 | Please send questions to api@awhere.com. 12 | 13 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: aWhereAPI 2 | Title: API calls for aWhere API 3 | Version: 0.7.5 4 | Authors@R: 5 | c(person("Technical", "Support", ,"technicalsupport@awhere.com", role = c("aut","cre","ctb"))) 6 | Description: 7 | R package to work with aWhere APIs. Provide functions to allow creating, 8 | deleting, updating fields, planting and batch jobs. Pulling daily observed 9 | weather, long term normal weather, daily agronomic, long term agronomic 10 | and forecast data. 11 | License: MIT, Copyright 2016 aWhere 12 | LazyData: true 13 | RoxygenNote: 7.1.1 14 | Depends: 15 | R (>= 3.3.2) 16 | Imports: 17 | base64enc, 18 | curl(>= 3.2), 19 | data.table, 20 | foreach, 21 | httr (>= 0.6.1), 22 | jsonlite, 23 | lubridate, 24 | lutz, 25 | raster, 26 | rgeos, 27 | sp, 28 | doParallel, 29 | magrittr, 30 | tidyr (>= 1.0.0) 31 | Suggests: 32 | testthat, 33 | knitr, 34 | rmarkdown 35 | VignetteBuilder: 36 | knitr 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 aWhere APIs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(agronomic_norms_area) 4 | export(agronomic_norms_fields) 5 | export(agronomic_norms_latlng) 6 | export(agronomic_values_area) 7 | export(agronomic_values_fields) 8 | export(agronomic_values_latlng) 9 | export(create_field) 10 | export(create_planting) 11 | export(create_shapewkt) 12 | export(custom_fortify) 13 | export(daily_observed_area) 14 | export(daily_observed_fields) 15 | export(daily_observed_latlng) 16 | export(delete_field) 17 | export(delete_planting) 18 | export(forecasts_area) 19 | export(forecasts_fields) 20 | export(forecasts_latlng) 21 | export(get_crops) 22 | export(get_fields) 23 | export(get_model_details) 24 | export(get_model_results) 25 | export(get_models) 26 | export(get_planting) 27 | export(get_token) 28 | export(load_credentials) 29 | export(soils_area) 30 | export(soils_fields) 31 | export(soils_latlng) 32 | export(update_field) 33 | export(update_planting) 34 | export(weather_norms_area) 35 | export(weather_norms_fields) 36 | export(weather_norms_latlng) 37 | import(data.table) 38 | import(doParallel) 39 | import(foreach) 40 | import(httr) 41 | import(jsonlite) 42 | import(lubridate) 43 | import(lutz) 44 | import(magrittr) 45 | import(raster) 46 | import(rgeos) 47 | import(sp) 48 | import(tidyr) 49 | importFrom(lubridate,ymd) 50 | -------------------------------------------------------------------------------- /R/.Rapp.history: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aWhereAPI/aWhere-R-Library/452e9c6b3b254d8163df09dd0f0adf87f44f5e13/R/.Rapp.history -------------------------------------------------------------------------------- /R/agronomic-crops.R: -------------------------------------------------------------------------------- 1 | #' @title Get Crops 2 | #' 3 | #' @description 4 | #' \code{get_crops} Calls Crops endpoint of API 5 | #' 6 | #' @details 7 | #' Models are designed for specific crops, and often specific types or varieties of crops. 8 | #' This API provides the list of available crops. When creating a planting record, you're encouraged 9 | #' to specify the crop that is planted in the field using these records. 10 | #' 11 | #' Within each category of crop (organized by name), there is a default crop. When creating a planting, 12 | #' you may not know or care about the specific variety, and can simply specify the crop name as 13 | #' what is planted there. When you do this, the system will use the default crop for that category. 14 | #' You'll know which crop record is the default by referencing the isDefaultForCrop property, described below. 15 | #' 16 | #' @references https://developer.awhere.com/api/reference/crops 17 | #' 18 | #' @param crop_id Either a crop id to retrieve information for that specific crop 19 | #' or an empty string to retrieve information on all crops associated 20 | #' with the user's aWhere API account (string - optional) 21 | #' @param keyToUse aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional) 22 | #' @param secretToUse aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional) 23 | #' @param tokenToUse aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional) 24 | #' @param apiAddressToUse Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 25 | #' 26 | #' @import httr 27 | #' 28 | #' @return - data.frame containing information about requested crop(s) 29 | #' 30 | #' @examples 31 | #' \dontrun{get_crops('barley-generic') 32 | #' get_crops() 33 | #' } 34 | 35 | #' @export 36 | 37 | get_crops <- function(crop_id = '' 38 | ,keyToUse = awhereEnv75247$uid 39 | ,secretToUse = awhereEnv75247$secret 40 | ,tokenToUse = awhereEnv75247$token 41 | ,apiAddressToUse = awhereEnv75247$apiAddress) { 42 | 43 | checkCredentials(keyToUse,secretToUse,tokenToUse) 44 | 45 | ## Create Request 46 | url <- paste0(apiAddressToUse, "/agronomics/crops/") 47 | 48 | if(crop_id != "") { 49 | url <- paste0(url, crop_id) 50 | } 51 | 52 | doWeatherGet <- TRUE 53 | tryCount <- 0 54 | while (doWeatherGet == TRUE) { 55 | tryCount <- tryCount + 1 56 | 57 | request <- httr::GET(url, 58 | httr::content_type('application/json'), 59 | httr::add_headers(Authorization = 60 | paste0("Bearer ", tokenToUse))) 61 | 62 | a <- suppressMessages(httr::content(request)) 63 | 64 | temp <- check_JSON(a 65 | ,request 66 | ,tryCount 67 | ,keyToUse 68 | ,secretToUse 69 | ,tokenToUse) 70 | 71 | doWeatherGet <- temp[[1]] 72 | 73 | #if the token was updated, this will cause it to be used through function 74 | tokenToUse <- temp[[3]] 75 | } 76 | 77 | ## Create & fill data frame 78 | if(crop_id == "") { 79 | data <- as.data.frame(do.call(rbind, lapply(a$crops, rbind)))[, c(1:5)] 80 | colnames(data) <- c("cropId", "name", "type", "variety", "isDefaultForCrop") 81 | rownames(data) <- c(1:nrow(data)) 82 | 83 | data <- data.frame(lapply(data, as.character), stringsAsFactors=FALSE) 84 | 85 | data <- as.matrix(data) 86 | data[sapply(data, is.null)] <- NA 87 | data <- as.data.frame(data) 88 | 89 | } else { 90 | data <- as.data.frame(rbind(a))[,c(1:5)] 91 | colnames(data) <- c("cropId", "name", "type", "variety", "isDefaultForCrop") 92 | rownames(data) <- c(1:nrow(data)) 93 | } 94 | 95 | data <- dplyr::mutate_if(data, is.factor, as.character) 96 | 97 | if(nrow(data) == 0) { 98 | stop(a$simpleMessage) 99 | } else { 100 | return(as.data.frame(data)) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /R/checkDataReturn.R: -------------------------------------------------------------------------------- 1 | #' @title checkDataReturn_daily 2 | #' 3 | #' @description 4 | #' \code{checkDataReturn_daily} Checks to see if data return is complete from API endpoints with daily data 5 | #' 6 | #' @param dataset the data.frame to check 7 | #' @param day_start character string of the first day for which data was retrieved, in the form: YYYY-MM-DD 8 | #' @param day_end character string of the last day for which data was retrieved, in the form: YYYY-MM-DD 9 | 10 | checkDataReturn_daily <- function(dataset,day_start,day_end) { 11 | if (nrow(dataset) != round(difftime(day_end,day_start,units = 'days') +1L)) { 12 | warning('Incorrect number of rows returned from API call; check returned data to determine issue',immediate. = TRUE) 13 | } 14 | 15 | columnNames <- colnames(dataset) 16 | rowsComplete <- complete.cases(dataset) 17 | 18 | if(all(rowsComplete == TRUE) == FALSE) { 19 | warning(paste0('Missing data from rows ',paste0(which(rowsComplete == FALSE),collapse = ', '),'; check data before continuing'),immediate. = TRUE) 20 | } 21 | } 22 | 23 | #' @title checkDataReturn_norms 24 | #' 25 | #' @description 26 | #' \code{checkDataReturn_norms} Checks to see if data return is complete from norms API 27 | #' 28 | #' @param dataset the data.frame to check 29 | #' @param monthday_start character string of the first month and day for which you want to retrieve data, 30 | #' in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) 31 | #' @param monthday_end character string of the last month and day for which you want to retrieve data, 32 | #' in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) 33 | #' @param year_start character string of the starting year (inclusive) of the range of years for which 34 | #' you're calculating norms, in the form YYYY. e.g., 2008 35 | #' @param year_end character string of the last year (inclusive) of the range of years for which 36 | #' you're calculating norms, in the form YYYY. e.g., 2015 37 | #' @param exclude_year Year or years which you'd like to exclude from 38 | #' your range of years on which to calculate norms. To exclude 39 | #' multiple years, provide a vector of years. You must include 40 | #' at least three years of data with which to calculate the norms. 41 | #' @param includeFeb29thData Whether to keep data from Feb 29th on leap years. 42 | 43 | checkDataReturn_norms <- function(dataset,monthday_start,monthday_end,year_start,year_end,exclude_year,includeFeb29thData) { 44 | yearsToTest <- seq(year_start,year_end,1) 45 | 46 | if(!is.null(exclude_year)) { 47 | yearsToTest <- yearsToTest[!(yearsToTest %in% exclude_year)] 48 | } 49 | 50 | maxNumDays <- 0 51 | 52 | for (x in 1:length(yearsToTest)) { 53 | currentYear <- yearsToTest[x] 54 | currentMonthDay_start <- paste0(currentYear,'-',monthday_start) 55 | currentMonthDay_end <- paste0(currentYear,'-',monthday_end) 56 | 57 | currentNumDays <- tryCatch({round(difftime(currentMonthDay_end 58 | ,currentMonthDay_start 59 | ,units = 'days') +1L) 60 | 61 | 62 | }, error = function(e) { 63 | return(e) 64 | }) 65 | 66 | if (any(class(currentNumDays) == 'simpleError')) { 67 | next 68 | } 69 | 70 | if (includeFeb29thData == FALSE) { 71 | if (is.leapyear(currentYear) == TRUE) { 72 | if (currentMonthDay_start <= paste0(currentYear,'-02-29')) { 73 | if (currentMonthDay_end >= paste0(currentYear,'-02-29')) { 74 | currentNumDays <- currentNumDays - 1L 75 | } 76 | } 77 | } 78 | } 79 | 80 | if (currentNumDays > maxNumDays) { 81 | maxNumDays <- currentNumDays 82 | } 83 | } 84 | 85 | if (nrow(dataset) != maxNumDays) { 86 | warning('Incorrect number of rows returned from API call; check returned data to determine issue',immediate. = TRUE) 87 | } 88 | 89 | columnNames <- colnames(dataset) 90 | rowsComplete <- complete.cases(dataset) 91 | 92 | if(all(rowsComplete == TRUE) == FALSE) { 93 | warning(paste0('Missing data from rows ',paste0(which(rowsComplete == FALSE),collapse = ', '),'; check data before continuing'),immediate. = TRUE) 94 | } 95 | } 96 | 97 | #' @title checkDataReturn_forecasts 98 | #' 99 | #' @description 100 | #' \code{checkDataReturn_forecasts} Checks to see if data return is complete from forecasts API endpoint 101 | #' 102 | #' @param dataset the data.frame to check 103 | #' @param day_start character string of the first day for which data was retrieved, in the form: YYYY-MM-DD 104 | #' @param day_end character string of the last day for which data was retrieved, in the form: YYYY-MM-DD 105 | #' @param block_size Integer value that corresponds to the number of hours to include in each time block. 106 | #' Defaults to a 1 hour block. This value must divide evenly into 24. 107 | 108 | checkDataReturn_forecasts <- function(dataset,day_start,day_end,block_size) { 109 | if (day_end != '') { 110 | if (nrow(dataset) != round((difftime(day_end,day_start,units = 'days') +1L)) * (24 / block_size)) { 111 | warning('Incorrect number of rows returned from API call; check returned data to determine issue',immediate. = TRUE) 112 | } 113 | } else { 114 | if (nrow(dataset) != round((difftime(day_start,day_start,units = 'days') +1L)) * (24 / block_size)) { 115 | warning('Incorrect number of rows returned from API call; check returned data to determine issue',immediate. = TRUE) 116 | } 117 | } 118 | varNames <- colnames(dataset) 119 | #The API will always return NA for these columns 120 | if (block_size == 1) { 121 | varNames <- grep('relativeHumidity.m',varNames,value = TRUE,invert = TRUE) 122 | varNames <- grep('wind.m',varNames,value = TRUE,invert = TRUE) 123 | } 124 | rowsComplete <- complete.cases(dataset[,varNames,with = FALSE]) 125 | if(all(rowsComplete == TRUE) == FALSE) { 126 | warning(paste0('Missing data from rows ',paste0(which(rowsComplete == FALSE),collapse = ', '),'; check data before continuing'),immediate. = TRUE) 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /R/checkStatusCodeOfReturn.R: -------------------------------------------------------------------------------- 1 | #' @title Check Status Code of Return 2 | #' 3 | #' @description 4 | #' \code{checkStatusCode} Checks to see if valid aWhere API credentials are loaded 5 | #' 6 | #' @param request object returned from HTTR 7 | 8 | 9 | checkStatusCode<- function(request 10 | ,tryCount) { 11 | 12 | #Pause thread if rate exceeded for random interval or if user out of API calls 13 | if (request$status_code %in% c(429)) { 14 | 15 | if (tryCount > 5) { 16 | a <- suppressMessages(httr::content(request, as = "parsed")) 17 | 18 | stop(paste0('\nstatusName: ',a$statusName 19 | ,'\nstatusCode: ',request$status_code 20 | ,'\n',a$detailedMessage 21 | ,'\nErrorID: ',a$errorId)) 22 | } 23 | 24 | cat('Pausing thread due to Rate Limit Exceeded\n') 25 | 26 | Sys.sleep(runif(n = 1 27 | ,min = 15 28 | ,max = 45)) 29 | } 30 | 31 | if (request$status_code %in% c(500,502,503)) { #Status Code = 500 are problems from API 32 | cat('Unexpected Error Received from API... Retrying Query after Short Pause\n') 33 | 34 | Sys.sleep(runif(n = 1 35 | ,min = 30 36 | ,max = 60)) 37 | } 38 | 39 | if (!(request$status_code %in% c(200,201,204,429,500,502,503))) { # status code = 200's means that the query worked 40 | 41 | a <- suppressMessages(httr::content(request, as = "parsed")) 42 | 43 | stop(paste0('\nstatusName: ',a$statusName 44 | ,'\nstatusCode: ',request$status_code 45 | ,'\n',a$detailedMessage 46 | ,'\nErrorID: ',a$errorId)) 47 | } 48 | 49 | return(request$status_code) 50 | } 51 | -------------------------------------------------------------------------------- /R/cleanupAPIReturns.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Removes unnecessary columns from API Return 3 | #' 4 | #' @description 5 | #' \code{removeUnnecessaryColumns} Removes unnecessary columns from API Return 6 | #' 7 | #' @param data data.table to have columns removed from 8 | #' 9 | #' @import tidyr 10 | #' @import data.table 11 | #' @import magrittr 12 | 13 | removeUnnecessaryColumns <- function(data, returnOnlySoilVars = FALSE) { 14 | 15 | varNames <- colnames(data) 16 | 17 | #This removes the non-data info returned with the JSON object 18 | suppressWarnings(data[,grep('_links',varNames) := NULL]) 19 | suppressWarnings(data[,grep('.units',varNames) := NULL]) 20 | suppressWarnings(data[,grep('latitude',varNames) := NULL]) 21 | suppressWarnings(data[,grep('longitude',varNames) := NULL]) 22 | suppressWarnings(data[,grep('fieldId',varNames) := NULL]) 23 | 24 | if (returnOnlySoilVars == FALSE) { 25 | suppressWarnings(data[,c('soilTemperatures','soilMoisture') := NULL]) 26 | } else{ 27 | columnsToRemove <- colnames(data) 28 | columnsToRemove <- 29 | columnsToRemove[!(columnsToRemove %in% c('startTime' 30 | ,'endTime' 31 | ,'soilTemperatures' 32 | ,'soilMoisture'))] 33 | 34 | data[,(columnsToRemove) := NULL] 35 | 36 | data <- 37 | tidyr::unnest(data,col = c('soilTemperatures','soilMoisture'),names_sep = '_') %>% 38 | as.data.table(.) 39 | 40 | data[,c('soilMoisture_depth','soilTemperatures_units') := NULL] 41 | setnames(data,'soilTemperatures_depth','soilDepth') 42 | } 43 | 44 | return(data) 45 | } 46 | 47 | 48 | 49 | #' @title Removes unnecessary columns from API Return 50 | #' 51 | #' @description 52 | #' \code{recalculateAccumulations} manually recalculate accumulations over API calls 53 | #' 54 | #' @param dataList list of data.table to have accumulations corrected 55 | 56 | recalculateAccumulations <- function(dataList) { 57 | accumulatedColumns <- grep(pattern = 'accumulated' 58 | ,x = unique(unlist(lapply(dataList,colnames))) 59 | ,value = TRUE 60 | ,fixed = TRUE) 61 | 62 | accumulatedColumns <- grep(pattern = '.units' 63 | ,x = accumulatedColumns 64 | ,invert = TRUE 65 | ,value = TRUE 66 | ,fixed = TRUE) 67 | #it is possible for certain columns to be returned from API because of all NULLs. Need to remove those 68 | columnsToRemove <- c('accumulatedPet' 69 | ,'accumulatedPrecipitation' 70 | ,'pet') 71 | 72 | accumulatedColumns <- setdiff(accumulatedColumns 73 | ,columnsToRemove) 74 | 75 | if (length(accumulatedColumns) > 0) { 76 | for (x in 1:length(dataList)) { 77 | #Remove those unneccesary columns 78 | suppressWarnings(dataList[[x]][,(columnsToRemove) := NULL]) 79 | 80 | #if any accumulated columns should be present that aren't add them 81 | suppressWarnings(dataList[[x]][,(setdiff(accumulatedColumns 82 | ,colnames(dataList[[x]]))) := NA,]) 83 | } 84 | 85 | for (x in 1:length(dataList)) { 86 | if (x > 1) { 87 | for (y in 1:length(accumulatedColumns)) { 88 | eval(parse(text = paste0('dataList[[x]][,',accumulatedColumns[y],' := ',accumulatedColumns[y],' + lastValue.accumulatedColumns$',accumulatedColumns[y],']'))) 89 | #eval(parse(text = paste0('dataList[[x]][,',accumulatedColumns[y],' := sum(',accumulatedColumns[y],',lastValue.accumulatedColumns$',accumulatedColumns[y],')]'))) 90 | } 91 | } 92 | 93 | lastValue.accumulatedColumns <- dataList[[x]][.N,accumulatedColumns,with = FALSE] 94 | 95 | #keep NA's from propagating 96 | #lastValue.accumulatedColumns[is.na(lastValue.accumulatedColumns)] <- 0 97 | } 98 | } 99 | 100 | return(dataList) 101 | } 102 | -------------------------------------------------------------------------------- /R/create-awhere-grid.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Create aWhere Grid 3 | #' 4 | #' @description 5 | #' \code{create_awhere_grid} based on a SpatialPolygon, creates a data frame based on aWhere's grid system 6 | #' 7 | #' @details 8 | #' Creates a grid of lat/lon points within given polygon. 9 | #' The aWhere grid is spaced at .08333 decimal degrees resolution (or 5 arc-minutes), 10 | #' so spacing a new grid at every .08 degrees should guarantee 11 | #' a grid point in each aWhere grid cell. 12 | #' 13 | #' @import rgeos 14 | #' @import raster 15 | #' @import sp 16 | #' 17 | #' @param - polygon: either a SpatialPolygons data type object or a character string of valid WKT 18 | 19 | create_awhere_grid <- function(polygon) { 20 | 21 | ## If polygon is WKT, convert to SpatialPolygons class 22 | if(class(polygon) == "character") { 23 | tryCatch({polygon <- rgeos::readWKT(polygon)}, error = function(e) { 24 | stop(e) 25 | }) 26 | } else if (class(polygon) == 'Extent') { 27 | polygon <- as(polygon, 'SpatialPolygons') 28 | } 29 | 30 | ## Buffer polygon by 0.5 degrees to make sure we capture all valid grid cells 31 | grid <- suppressWarnings(sp::makegrid(raster::buffer(polygon, .5), cellsize = .08)) 32 | ## Create SpatialPoints data frame from calculated grid 33 | grid <- sp::SpatialPoints(grid, proj4string = sp::CRS(sp::proj4string(polygon))) 34 | ## Only keep grid points that fall within the polygon 35 | grid <- grid[polygon,] 36 | 37 | ## Keep only the lat/lon columns 38 | grid <- as.data.frame(grid@coords) 39 | 40 | colnames(grid) <- c("lon", "lat") 41 | 42 | ## Calculate GridX and GridY for each calculated grid point 43 | grid$gridx <- getGridX(grid$lon) 44 | grid$gridy <- getGridY(grid$lat) 45 | 46 | ## Keep only unique GridX/GridY pairings 47 | grid <- unique(grid[,c("gridx", "gridy")]) 48 | 49 | ## Calculate centroid lat and lon for each GridX/GridY 50 | grid$lon <- getLongitude(grid$gridx) 51 | grid$lat <- getLatitude(grid$gridy) 52 | 53 | return(grid) 54 | } 55 | -------------------------------------------------------------------------------- /R/create-shapewkt.R: -------------------------------------------------------------------------------- 1 | #' @title create_shapewkt 2 | #' 3 | #' @description 4 | #' \code{create_shapewkt} writes the WKT for a grid cell, based on a centroid coordinate 5 | #' 6 | #' @param longitude longitude coordinate for centroid 7 | #' @param latitude latitude coordinate for centroid 8 | #' 9 | #' @export 10 | create_shapewkt <- function(longitude, latitude) { 11 | 12 | upperLeft <- c(longitude - (5/60), latitude + (5/60)) 13 | lowerLeft <- c(longitude - (5/60), latitude - (5/60)) 14 | lowerRight <- c(longitude + (5/60), latitude - (5/60)) 15 | upperRight <- c(longitude + (5/60), latitude + (5/60)) 16 | 17 | coordstring <- paste(paste(upperLeft, collapse = " "), paste(lowerLeft, collapse = " "), 18 | paste(lowerRight, collapse = " "), paste(upperRight, collapse = " "), 19 | paste(upperLeft, collapse = " "), sep = ",") 20 | 21 | 22 | shapewkt <- paste0("POLYGON((", coordstring, "))") 23 | 24 | return(shapewkt) 25 | } 26 | 27 | 28 | #' @title custom_fortify 29 | #' 30 | #' @description 31 | #' \code{custom_fortify} breaks up a shapewkt string into a numeric vector containing the points in the WKT 32 | #' 33 | #' @param shapewkt a well-known text string for a grid cell polygon 34 | #' 35 | #' @export 36 | custom_fortify <- function(shapewkt) { 37 | shapewkt <- gsub("POLYGON\\(\\(|\\)\\)", "", shapewkt) 38 | shapewkt <- gsub(", ", ",", shapewkt) 39 | return(as.numeric(unlist(strsplit(unlist(strsplit(shapewkt, ",")), " ")))) 40 | } 41 | -------------------------------------------------------------------------------- /R/delete.R: -------------------------------------------------------------------------------- 1 | #' @title Delete Field 2 | #' 3 | #' @description 4 | #' \code{delete_field} deletes a field_id for a location in the aWhere platform for which you can request weather 5 | #' 6 | #' @details 7 | #' This script deletes a field location in the aWhere platform. 8 | #' This API is a "hard delete" - the field record should actually be deleted from the system. 9 | #' The delete should cascade, if there are associated records to a field, they are deleted as well. 10 | #' This applies when we design/implement "Plantings" API. 11 | #' 12 | #' @param field_id an ID of your choosing (string) 13 | #' @param keyToUse aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional) 14 | #' @param secretToUse aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional) 15 | #' @param tokenToUse aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional) 16 | #' @param apiAddressToUse Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 17 | #' 18 | #' @return - a print text that informs if the query succeded or not 19 | #' 20 | #' @references https://docs.awhere.com/knowledge-base-docs/delete-a-field/ 21 | #' 22 | #' @import httr 23 | #' 24 | #' @examples 25 | #' \dontrun{delete_field("field123")} 26 | #' @export 27 | 28 | delete_field <- function(field_id 29 | ,verbose = TRUE 30 | ,keyToUse = awhereEnv75247$uid 31 | ,secretToUse = awhereEnv75247$secret 32 | ,tokenToUse = awhereEnv75247$token 33 | ,apiAddressToUse = awhereEnv75247$apiAddress) { 34 | 35 | checkCredentials(keyToUse,secretToUse,tokenToUse) 36 | checkValidField(field_id,keyToUse,secretToUse,tokenToUse) 37 | 38 | url <- paste0(apiAddressToUse, "/fields/", field_id) 39 | 40 | postbody <- paste0('{', field_id, '}'); 41 | 42 | doWeatherGet = TRUE 43 | tryCount <- 0 44 | while (doWeatherGet == TRUE) { 45 | tryCount <- tryCount + 1 46 | ## Get data 47 | 48 | request <- httr::DELETE(url, body=postbody, httr::content_type('application/json'), 49 | httr::add_headers(Authorization = paste0("Bearer ", tokenToUse))) 50 | 51 | a <- suppressMessages(httr::content(request, as = "text")) 52 | 53 | temp <- check_JSON(a 54 | ,request 55 | ,tryCount 56 | ,keyToUse 57 | ,secretToUse 58 | ,tokenToUse) 59 | 60 | doWeatherGet <- temp[[1]] 61 | 62 | #if the token was updated, this will cause it to be used through function 63 | tokenToUse <- temp[[3]] 64 | } 65 | 66 | if (verbose == TRUE) { 67 | cat(paste0('Operation Complete')) 68 | } 69 | } 70 | 71 | #' @title Delete Planting 72 | #' 73 | #' @description 74 | #' \code{delete_planting} deletes a planting associated with a specific field_id in the aWhere platform 75 | #' 76 | #' @details 77 | #' The aWhere API only references the most recent planting when calculating agronomics and running 78 | #' models, but if you want to keep your planting records clean for reporting and historical tracking 79 | #' purposes you can delete errant or incorrect plantings. 80 | #' 81 | #' @param field_id the ID of the field for which you want to delete an associated planting (string) 82 | #' @param planting_id The planting Id that you want to delete. You can also use "current" to delete the most recent planting (string) 83 | #' @param keyToUse aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional) 84 | #' @param secretToUse aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional) 85 | #' @param tokenToUse aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional) 86 | #' @param apiAddressToUse Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 87 | #' 88 | #' @return - a print text that informs if the query succeded or not 89 | #' 90 | #' @references https://docs.awhere.com/knowledge-base-docs/delete-a-planting/ 91 | #' 92 | #' @import httr 93 | #' 94 | #' @examples 95 | #' \dontrun{delete_planting("field123",'133972')} 96 | 97 | #' @export 98 | 99 | delete_planting <- function(field_id 100 | ,planting_id 101 | ,verbose = TRUE 102 | ,keyToUse = awhereEnv75247$uid 103 | ,secretToUse = awhereEnv75247$secret 104 | ,tokenToUse = awhereEnv75247$token 105 | ,apiAddressToUse = awhereEnv75247$apiAddress) { 106 | 107 | checkCredentials(keyToUse,secretToUse,tokenToUse) 108 | checkValidField(field_id,keyToUse,secretToUse,tokenToUse) 109 | 110 | url <- paste0(apiAddressToUse, "/agronomics/fields/", field_id,'/plantings/',planting_id) 111 | 112 | doWeatherGet = TRUE 113 | tryCount <- 0 114 | while (doWeatherGet == TRUE) { 115 | tryCount <- tryCount + 1 116 | ## Get data 117 | request <- httr::DELETE(url, httr::add_headers(Authorization = paste0("Bearer ", tokenToUse))) 118 | 119 | a <- suppressMessages(httr::content(request, as = "text")) 120 | 121 | temp <- check_JSON(a 122 | ,request 123 | ,tryCount 124 | ,keyToUse 125 | ,secretToUse 126 | ,tokenToUse) 127 | 128 | doWeatherGet <- temp[[1]] 129 | 130 | #if the token was updated, this will cause it to be used through function 131 | tokenToUse <- temp[[3]] 132 | } 133 | 134 | if (verbose == TRUE) { 135 | cat(paste0('Operation Complete')) 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /R/get-token.R: -------------------------------------------------------------------------------- 1 | #' @title Get Access Token 2 | #' 3 | #' @description 4 | #' \code{get_token} gets Access Token for V2 aWhere API 5 | #' 6 | #' @details 7 | #' This script provides an aWhere access token for the current session of the API. Information for the key and secret in this 8 | #' function can be found on a user's account at developer.awhere.com, under the apps. 9 | #' 10 | #' @param uid Consumer key associated with the user's aWhere API account 11 | #' @param secret Consumer secret associated the user's aWhere API account 12 | #' @param use_enviroment Optional logical value, determines whether API access 13 | #' token will be saved in a local locked environment in addition to being returned 14 | #' by the function. Defaults to \code{TRUE} to avoid breaking existing code. 15 | #' @param apiAddress Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 16 | #' 17 | #' @return List with three elements:#' 18 | #' error: logical indicating whether there was an error 19 | #' error_message: \code{NULL} if error is \code{FALSE}, a character error message otherwise 20 | #' token: aWhere API access token value 21 | #' 22 | #' @examples 23 | #' \dontrun{get_token("uid", "secret")} 24 | #' \dontrun{token_response <- get_token('uid', 'secret', use_environment = FALSE)} 25 | #' @export 26 | 27 | get_token <- function(uid, secret, use_environment = TRUE, apiAddress = "api.awhere.com") { 28 | 29 | url <- paste0("https://", apiAddress, "/oauth/token") 30 | 31 | authen_char <- charToRaw(paste0(uid,':',secret)) 32 | 33 | request <- httr::POST(url, body='grant_type=client_credentials', 34 | httr::content_type('application/x-www-form-urlencoded'), 35 | httr::add_headers(Authorization = paste0('Basic ', base64enc::base64encode(authen_char)))) 36 | 37 | a <- suppressMessages(httr::content(request, as = "text")) 38 | 39 | if (request$status_code != 200) { 40 | error <- TRUE 41 | error_message <- 'The UID/Secret combination is incorrect.' 42 | token <- NULL 43 | 44 | cat(paste(error_message, '\n')) 45 | } else { 46 | error <- FALSE 47 | error_message <- NULL 48 | 49 | parsedResponse <- jsonlite::fromJSON(a, simplifyDataFrame = FALSE) 50 | 51 | token <- parsedResponse$access_token 52 | apiAddress <- paste0("https://", apiAddress, "/v2") 53 | 54 | # Keeping environment approach for backward compatibility, 55 | # but adding an optional argument to skip it. 56 | if (use_environment) { 57 | if (exists('awhereEnv75247') == FALSE) { 58 | awhereEnv75247 <- new.env() 59 | assign('awhereEnv75247',awhereEnv75247,envir = .GlobalEnv) 60 | rm(awhereEnv75247) 61 | } 62 | 63 | if (exists('uid',envir = awhereEnv75247,inherits = FALSE) == TRUE) { 64 | if (bindingIsLocked('uid',awhereEnv75247) == TRUE) { 65 | unlockBinding('uid',awhereEnv75247) 66 | } 67 | } 68 | if (exists('secret',where = awhereEnv75247,inherits = FALSE) == TRUE) { 69 | if (bindingIsLocked('secret',awhereEnv75247) == TRUE) { 70 | unlockBinding('secret',awhereEnv75247) 71 | } 72 | } 73 | if (exists('token',where = awhereEnv75247,inherits = FALSE) == TRUE) { 74 | if (bindingIsLocked('token',awhereEnv75247) == TRUE) { 75 | unlockBinding('token',awhereEnv75247) 76 | } 77 | } 78 | if (exists('apiAddress',where = awhereEnv75247,inherits = FALSE) == TRUE) { 79 | if (bindingIsLocked('apiAddress',awhereEnv75247) == TRUE) { 80 | unlockBinding('apiAddress',awhereEnv75247) 81 | } 82 | } 83 | 84 | awhereEnv75247$uid <- uid 85 | awhereEnv75247$secret <- secret 86 | awhereEnv75247$token <- token 87 | awhereEnv75247$apiAddress <- apiAddress 88 | 89 | lockBinding('uid', awhereEnv75247) 90 | lockBinding('secret', awhereEnv75247) 91 | lockBinding('token', awhereEnv75247) 92 | lockBinding('apiAddress', awhereEnv75247) 93 | 94 | rm(awhereEnv75247) 95 | } 96 | } 97 | 98 | return(list(error = error 99 | ,error_message = error_message 100 | ,token = token 101 | ,apiAddress = apiAddress)) 102 | } 103 | 104 | #' @title Load Credentials. 105 | #' 106 | #' @description 107 | #' \code{load_credentials} loads credential information from text file to use in 108 | #' calls to aWhere API 109 | #' 110 | #' @details 111 | #' This script creates loads a valid aWhere API token into memory to be used in making API calls. 112 | #' Instead of typing in the password and username manually and calling the get_token(uid,secret) function, 113 | #' you can store this information in a txt file in some arbitrary directory. 114 | #' The first line of the text file should be the provided uid/username, the 115 | #' second line should be the associated secret. A blank 3rd line should be inserted to prevent 116 | #' an error from being returned by R 117 | #' 118 | #' @param path_to_credentials absolute or relative path to the text file 119 | #' @param apiAddress Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 120 | 121 | #' @return vector with uid and secret in positions 1, 2 122 | #' 123 | #' @examples 124 | #' \dontrun{load_credentials("C:/aWhere/credentials/credentials.txt")} 125 | #' 126 | #' @export 127 | 128 | load_credentials <- function(path_to_credentials,apiAddress = "api.awhere.com") { 129 | credentials <- readLines(path_to_credentials) 130 | 131 | uid <- credentials[1] 132 | secret <- credentials[2] 133 | 134 | get_token(uid = uid 135 | ,secret = secret 136 | ,apiAddress = apiAddress) 137 | } 138 | 139 | #' @title Check JSON Object 140 | #' 141 | #' @description 142 | #' \code{check_JSON} Checks to make sure JSON object isn't an error 143 | #' 144 | #' @details 145 | #' Checks that aWhere API didn't return an error code and that the token used in query hasn't expired 146 | # 147 | #' @param JSON object returned from aWhere API 148 | #' @param keyToUse aWhere API key to use. 149 | #' @param request the returned request code 150 | #' @param secretToUse aWhere API secret to use. 151 | #' @param tokenToUse aWhere API token to use. 152 | #' 153 | #' @return boolean for whether another query should be made 154 | 155 | check_JSON <- function(jsonObject 156 | ,request 157 | ,tryCount 158 | ,keyToUse 159 | ,secretToUse 160 | ,tokenToUse) { 161 | 162 | #Parses JSON to see if tells us we made too large of a request 163 | if (any(grepl('The maximum value for the limit parameter is',jsonObject))) { 164 | 165 | #Non enterprise accounts are allowed to return 10 days of data at a time 166 | #FALSE is returned because the logic of the API call will need to be 167 | #adjusted due to the changed limit paramater 168 | return(list(FALSE,10,tokenToUse)) 169 | } 170 | 171 | #Parses JSON to see if it tells us that we need a new token 172 | if (any(grepl('API Access Expired',jsonObject))) { 173 | if(exists("awhereEnv75247")) { 174 | if(tokenToUse == awhereEnv75247$token) { 175 | cat('The current token has expired, requesting new token to proceed with request\n') 176 | 177 | get_token(uid = keyToUse 178 | ,secret = secretToUse 179 | ,apiAddress = gsub(pattern = 'https://|/v2' 180 | ,replacement = '' 181 | ,x = awhereEnv75247$apiAddress)) 182 | tokenToUse <- awhereEnv75247$token 183 | 184 | #This boolean will cause the API request to be repeated 185 | return(list(TRUE,NA,tokenToUse)) 186 | } else { 187 | stop("The token you passed in has expired. Please request a new one and retry your function call with the new token\n") 188 | } 189 | } else { 190 | stop("The token you passed in has expired. Please request a new one and retry your function call with the new token\n") 191 | } 192 | } 193 | 194 | #Finally check to see if there was a different problem with the query and if so return the message 195 | statusCode <- checkStatusCode(request 196 | ,tryCount) 197 | 198 | #We need to repeat the query if 429 code encountered, above fxn will have paused the thread 199 | if (statusCode %in% c(429,500,502,503)) { 200 | return(list(TRUE,NA,tokenToUse)) 201 | } else { 202 | return(list(FALSE,NA,tokenToUse)) 203 | } 204 | } 205 | 206 | -------------------------------------------------------------------------------- /R/grid-functions.R: -------------------------------------------------------------------------------- 1 | #' Get aWhere GridX from longitude coordinate(s) 2 | #' 3 | #' 4 | #' @param longitude one more more longitude coordinates 5 | #' 6 | #' @return A vector of GridX values 7 | #' 8 | #' @examples getGridX(-90) 9 | #' 10 | getGridX <- function(longitude) { 11 | 12 | MaxLon <- 180 13 | MinLon <- -180 14 | 15 | MaxGridX <- 2160 16 | MinGridX <- -2160 17 | 18 | gridX <- (longitude / ((MaxLon - MinLon) / 2)) * ((MaxGridX - MinGridX) / 2) 19 | 20 | gridX[which(gridX > 0)] <- ceiling(gridX[which(gridX > 0)]) 21 | gridX[which(gridX < 0)] <- floor(gridX[which(gridX < 0)]) 22 | 23 | return (gridX) 24 | } 25 | 26 | 27 | #' Get aWhere GridY from latitude coordinate(s) 28 | #' 29 | #' 30 | #' @param latitude one or more latitudes coordinates 31 | #' 32 | #' @return A vector of GridY values 33 | #' 34 | #' @examples getGridY(-90) 35 | #' 36 | getGridY <- function(latitude) { 37 | 38 | MaxLat <- 90 39 | MinLat <- -90 40 | 41 | MaxGridY <- 1080 42 | MinGridY <- -1080 43 | 44 | gridY <- (latitude / ((MaxLat - MinLat) / 2)) * ((MaxGridY - MinGridY) / 2) 45 | 46 | gridY[which(gridY > 0)] <- ceiling(gridY[which(gridY > 0)]) 47 | gridY[which(gridY < 0)] <- floor(gridY[which(gridY < 0)]) 48 | 49 | return (gridY) 50 | } 51 | 52 | getLongitude <- function(gridX) { 53 | 54 | MaxLon = 180 55 | MinLon = -180 56 | 57 | MaxGridX = 2160 58 | MinGridX = -2160 59 | 60 | differenceLon <- (MaxLon - MinLon)/2 61 | 62 | gridX[which(gridX < 0)] <- ((differenceLon/MaxGridX) * gridX[which(gridX < 0)]) + (differenceLon/(MaxGridX*2)) 63 | 64 | gridX[which(gridX > 0)] <- ((differenceLon/MaxGridX) * gridX[which(gridX > 0)]) - (differenceLon/(MaxGridX*2)) 65 | 66 | return (gridX) 67 | } 68 | 69 | getLatitude <- function(gridY) { 70 | 71 | MaxLat = 90 72 | MinLat = -90 73 | 74 | MaxGridY = 1080 75 | MinGridY = -1080 76 | 77 | differenceLat <- (MaxLat - MinLat)/2 78 | 79 | gridY[which(gridY < 0)] <- ((differenceLat/MaxGridY) * gridY[which(gridY < 0)]) + (differenceLat/(MaxGridY*2)) 80 | 81 | gridY[which(gridY > 0)] <- ((differenceLat/MaxGridY) * gridY[which(gridY > 0)]) - (differenceLat/(MaxGridY*2)) 82 | 83 | return (gridY) 84 | } 85 | -------------------------------------------------------------------------------- /R/plan_APICalls.R: -------------------------------------------------------------------------------- 1 | #' @title Plan Logic of API Calls 2 | #' 3 | #' @description 4 | #' \code{plan_APICalls} Calculate logic of API calls 5 | #' 6 | #' @details 7 | #' Calculate logic of API calls based on the number of days that can be returned 8 | #' with each call as well as start and end dates 9 | #' 10 | #' @return list(allDates,loops) 11 | 12 | plan_APICalls <- function(day_start 13 | ,day_end 14 | ,numObsReturned 15 | ,includesLeapYear = TRUE) { 16 | 17 | 18 | #We need to make sure Feb 29th is included if appropriate 19 | if (day_end < day_start) { 20 | if (includesLeapYear == TRUE & lubridate::yday(day_start) > 60) { 21 | day_start <- ymd(day_start) - 366 #gets to same dayOfYear 1 year later 22 | } else if (includesLeapYear == TRUE & lubridate::yday(day_start) <= 60) { 23 | day_end <- ymd(day_end) + 366 #gets to same dayOfYear 1 year later 24 | } 25 | } 26 | 27 | numOfDays <- as.numeric(difftime(lubridate::ymd(day_end) 28 | ,lubridate::ymd(day_start) 29 | , units = 'days')) 30 | allDates <- seq(as.Date(lubridate::ymd(day_start)) 31 | ,as.Date(lubridate::ymd(day_end)) 32 | , by="days") 33 | 34 | loops <- ((length(allDates))) %/% numObsReturned 35 | remainder <- ((length(allDates))) %% numObsReturned 36 | 37 | 38 | if(remainder > 0) { 39 | loops <- loops + 1 40 | } 41 | 42 | 43 | return(list(allDates,loops)) 44 | } 45 | -------------------------------------------------------------------------------- /R/update.R: -------------------------------------------------------------------------------- 1 | #' @title Update Field 2 | #' 3 | #' @description 4 | #' \code{update_field} To update details (Farm ID or FieldName) of a particular location in the aWhere API. 5 | #' 6 | #' @details 7 | #' Fields are the easiest way to manage locations in the aWhere APIs, providing an easy reference 8 | #' for tracking weather, agronomics, models, and progress over growing seasons. Once a field is 9 | #' registered, plantings can also be registered for that field with specific information about the 10 | #' crop planted at that location, the date of planting, and other optional information. 11 | #' 12 | #' Occasionally, you may need to update the details of your field. At this time, only the farm ID, 13 | #' field Name, and number of acres can be updated using this function. Field details can only be 14 | #' updated one variable at a time, for one field at a time. If you need to update multiple fields or 15 | #' multiple variables associated with a field, please pass commands sequentially. 16 | #' 17 | #' @param field_id the unique field ID for the field you want to update (character string) (required) 18 | #' @param variable_update the variable that needs to be updated, either "farmId", "name", or "acres" 19 | #' (character string) (required) 20 | #' @param value_update the new value for variable_update, to replace the existing value. The existing 21 | #' value can be found using get_fields("field_id") (character string) (required) 22 | #' @param keyToUse aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional) 23 | #' @param secretToUse aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional) 24 | #' @param tokenToUse aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional) 25 | #' @param apiAddressToUse Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 26 | #' 27 | #' @return - A message confirming the changes have been made 28 | #' 29 | #' @references https://docs.awhere.com/knowledge-base-docs/update-a-field-location/ 30 | #' 31 | #' @import httr 32 | #' 33 | #' @examples 34 | #' \dontrun{update_field(field_id = 'field_test',variable_update = 'farmId', value_update = 'This is my territory')} 35 | 36 | #' @export 37 | 38 | update_field <- function(field_id 39 | ,variable_update 40 | ,value_update 41 | ,keyToUse = awhereEnv75247$uid 42 | ,secretToUse = awhereEnv75247$secret 43 | ,tokenToUse = awhereEnv75247$token 44 | ,apiAddressToUse = awhereEnv75247$apiAddress) { 45 | 46 | checkCredentials(keyToUse,secretToUse,tokenToUse) 47 | checkValidField(field_id,keyToUse,secretToUse,tokenToUse) 48 | 49 | ## Creating the request 50 | url <- paste0(apiAddressToUse, "/fields/",field_id) 51 | 52 | postbody <- paste0('[{"op":"replace","path":"/', variable_update, '","value":"', value_update, '"}]') 53 | 54 | doWeatherGet <- TRUE 55 | tryCount <- 0 56 | while (doWeatherGet == TRUE) { 57 | tryCount <- tryCount + 1 58 | 59 | request <- httr::PATCH(url, body = postbody, httr::content_type('application/json'), 60 | httr:: add_headers(Authorization = paste0("Bearer ", tokenToUse))) 61 | 62 | # Re formating the response recieved from API 63 | a <- suppressMessages(httr::content(request, as = "text")) 64 | 65 | temp <- check_JSON(a 66 | ,request 67 | ,tryCount 68 | ,keyToUse 69 | ,secretToUse 70 | ,tokenToUse) 71 | 72 | doWeatherGet <- temp[[1]] 73 | 74 | #if the token was updated, this will cause it to be used through function 75 | tokenToUse <- temp[[3]] 76 | } 77 | 78 | cat(paste0('Operation Complete')) 79 | } 80 | 81 | #' @title Update Planting 82 | #' 83 | #' @description 84 | #' \code{update_planting} To update details of a particular planting 85 | #' 86 | #' @details 87 | #' Occasionally you will need to update a planting, changing the projections 88 | #' or recording the end-of-season information for historical tracking and model tuning. 89 | #' This API supports both partial and complete updates of plantings. When updating an 90 | #' entire planting, the whole object is replaced in the database. Any properties that 91 | #' were previously set, and now are not, will be null'd. The required properties must 92 | #' also be set even if they are changed. 93 | #' 94 | #' @param planting_id ID of planting to update 95 | #' @param field_id ID of field to search for plantings within 96 | #' @param planting_date new date to update as planting's plant date 97 | #' @param proj_yield_amount new amount to update as planting's projected yield amount 98 | #' @param proj_yield_units new units to update as planting's projected yield units 99 | #' @param proj_harvest_date new projected harvest date to update as planting's projected harvest date 100 | #' @param yield_amount new amount to update as planting's yield amount 101 | #' @param yield_units new units to update as planting's yield units 102 | #' @param harvest_date new actual harvest date to update as planting's harvest date 103 | #' @param keyToUse aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional) 104 | #' @param secretToUse aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional) 105 | #' @param tokenToUse aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional) 106 | #' @param apiAddressToUse Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional) 107 | #' 108 | #' @return - A message confirming the changes have been made 109 | #' 110 | #' @references https://docs.awhere.com/knowledge-base-docs/update-all-or-part-of-a-planting-in-a-field/ 111 | #' 112 | #' @import httr 113 | #' 114 | #' @examples 115 | #' \dontrun{update_planting("field_test", "156036", harvest_date = "2016-02-01", yield_amount = "60", yield_units = "Bushels")} 116 | #' 117 | #' @export 118 | 119 | update_planting <- function(field_id 120 | ,planting_id 121 | ,planting_date = "" 122 | ,proj_yield_amount = "" 123 | ,proj_yield_units = "" 124 | ,proj_harvest_date = "" 125 | ,yield_amount = "" 126 | ,yield_units = "" 127 | ,harvest_date = "" 128 | ,keyToUse = awhereEnv75247$uid 129 | ,secretToUse = awhereEnv75247$secret 130 | ,tokenToUse = awhereEnv75247$token 131 | ,apiAddressToUse = awhereEnv75247$apiAddress) { 132 | 133 | checkCredentials(keyToUse,secretToUse,tokenToUse) 134 | checkValidField(field_id,keyToUse,secretToUse,tokenToUse) 135 | 136 | ## Error checking 137 | 138 | if(field_id == "") { 139 | stop("Field ID is required") 140 | } 141 | 142 | if(proj_yield_amount != "" & is.na(as.double(proj_yield_amount))) { 143 | stop("Yield amounts must be numeric") 144 | } 145 | 146 | if(yield_amount != "" & is.na(as.double(yield_amount))) { 147 | stop("Yield amounts must be numeric") 148 | } 149 | 150 | if(planting_date != "" & !is.Date(ymd(planting_date))){ 151 | stop("Dates must be in 'YYYY-MM-DD' format") 152 | } 153 | 154 | if(proj_harvest_date != "" & !is.Date(ymd(proj_harvest_date))){ 155 | stop("Dates must be in 'YYYY-MM-DD' format") 156 | } 157 | 158 | if(harvest_date != "" & !is.Date(ymd(harvest_date))){ 159 | stop("Dates must be in 'YYYY-MM-DD' format") 160 | } 161 | 162 | 163 | ## Create postbody 164 | postbody <- c() 165 | 166 | i = 0 167 | 168 | if(planting_date != "") { 169 | i = i + 1 170 | postbody[i] <- paste0('{"op":"replace","path":"/plantingDate","value":"', planting_date, '"}') 171 | } 172 | if(proj_yield_amount != "") { 173 | i = i + 1 174 | postbody[i] <- paste0('{"op":"replace","path":"/projections/yield/amount","value":', proj_yield_amount, '}') 175 | } 176 | if(proj_yield_units != "") { 177 | i = i + 1 178 | postbody[i] <- paste0('{"op":"replace","path":"/projections/yield/units","value":"', proj_yield_units, '"}') 179 | } 180 | if(proj_harvest_date != "") { 181 | i = i + 1 182 | postbody[i] <- paste0('{"op":"replace","path":"/projections/harvestDate","value":"', proj_harvest_date, '"}') 183 | } 184 | if(yield_amount != "") { 185 | i = i + 1 186 | postbody[i] <- paste0('{"op":"replace","path":"/yield/amount","value":', yield_amount, '}') 187 | } 188 | if(yield_units != "") { 189 | i = i + 1 190 | postbody[i] <- paste0('{"op":"replace","path":"/yield/units","value":"', yield_units, '"}') 191 | } 192 | if(harvest_date != "") { 193 | i = i + 1 194 | postbody[i] <- paste0('{"op":"replace","path":"/harvestDate","value":"', harvest_date, '"}') 195 | } 196 | 197 | if(i == 0) { 198 | stop("Must pass in a value to update") 199 | } 200 | 201 | body <- paste0("[", postbody[1]) 202 | if(length(postbody) > 1) { 203 | for(i in 2:length(postbody)) { 204 | body <- paste0(body, ",", postbody[i]) 205 | } 206 | } 207 | body <- paste0(body, "]") 208 | 209 | ## Creating the request 210 | url <- paste0(apiAddressToUse, "/agronomics/fields/", field_id, "/plantings/") 211 | 212 | if(planting_id == "") { 213 | url <- paste0(url, "current") 214 | } else { 215 | url <- paste0(url, planting_id) 216 | } 217 | 218 | doWeatherGet <- TRUE 219 | tryCount <- 0 220 | while (doWeatherGet == TRUE) { 221 | tryCount <- tryCount + 1 222 | 223 | ##Send request 224 | request <- httr::PATCH(url, body = body, httr::content_type('application/json'), 225 | httr::add_headers(Authorization = paste0("Bearer ", tokenToUse))) 226 | 227 | a <- suppressMessages(httr::content(request, as = "text")) 228 | 229 | temp <- check_JSON(a 230 | ,request 231 | ,tryCount 232 | ,keyToUse 233 | ,secretToUse 234 | ,tokenToUse) 235 | 236 | doWeatherGet <- temp[[1]] 237 | 238 | #if the token was updated, this will cause it to be used through function 239 | tokenToUse <- temp[[3]] 240 | } 241 | 242 | cat(paste0('Operation Complete')) 243 | } 244 | -------------------------------------------------------------------------------- /R/utility.R: -------------------------------------------------------------------------------- 1 | `:=` <- data.table::`:=` 2 | #' @importFrom lubridate ymd 3 | ymd <- lubridate::ymd 4 | 5 | 6 | is.leapyear = function(year){ 7 | #http://en.wikipedia.org/wiki/Leap_year 8 | return(((year %% 4 == 0) & (year %% 100 != 0)) | (year %% 400 == 0)) 9 | } -------------------------------------------------------------------------------- /R/verify-api-calls.R: -------------------------------------------------------------------------------- 1 | 2 | #' @title Verify User Wants Make API Calls 3 | #' 4 | #' @description 5 | #' \code{verify_api_calls} Tells user how many api calls will be made to pull the data requested 6 | #' 7 | #' @param grid data frame returned from create_awhere_grid 8 | 9 | verify_api_calls <- function(grid,bypassNumCallCheck) { 10 | 11 | if(nrow(grid) == 0) { 12 | stop('Polygon is not large enough to contain the centroid of any aWhere Grid cell. Please enlarge and try again\n') 13 | } 14 | 15 | if (bypassNumCallCheck == FALSE) { 16 | cat(paste0('This query will require data from ',nrow(grid),' locations \n')) 17 | makeAPICalls <- readline("Do you wish to proceed? Type yes to begin API calls: ") 18 | 19 | if (tolower(makeAPICalls) != 'yes') { 20 | stop('User Input indicated they did not want to proceed with making API Calls \n') 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aWhere API R Package 2 | 3 | For customers that use R in their statistical modeling work, this R package helps get you up and running with our APIs with minimal integration effort. There is a function for each of our most regularly used APIs. 4 | 5 | _Note: These functions will only return metric units_ 6 | 7 | 8 | ## Installation 9 | 10 | **Note:** Prior to installation you will need a working installation of R. 11 | 12 | **Note:** You will need to have the devtools library installed in R. Consult documentation if necessary. 13 | 14 | ### Automatically Install 15 | 16 | This package can be installed directly from GitHub with the following command: 17 | 18 | devtools::install_github("aWhereAPI/aWhere-R-Library") 19 | 20 | #### If you have problems, try 21 | On Windows 22 | install.packages(c('chron', 'magrittr', 'btcops', 'DBI', 'assertthat', 'Rcpp', 'tibble')) 23 | 24 | On CentOS 7 25 | yum install openssl-devel libcurl-devel -y 26 | Rscript --slave --no-save --no-restore-history -e "install.packages('devtools', repos='http://cran.rstudio.com/')" 27 | Rscript --slave --no-save --no-restore-history -e "devtools::install_github('aWhereAPI/aWhere-R-Library')" 28 | 29 | ### Manually Install 30 | 31 | 1. Download this Github repo and keep the `aWhere-R-Library-master` folder somewhere useful on your computer, such as your Desktop or My Documents. 32 | 33 | 2. Set the Working Path in R to the location that contains the `aWhere-R-Library-master` folder. If you placed it on your Desktop the working directory would be something like `C:\Users\USERNAME\Desktop`. In R, this command is: 34 | * `setwd("C:\Users\USERNAME\Desktop")` 35 | 36 | 3. Run the following set of commands to install and add the library to your environment: 37 | * `library(devtools)` 38 | * `install("aWhere-R-Library-master")` 39 | * `library(aWhereAPI)` 40 | 41 | 42 | 43 | ## Documentation 44 | 45 | Because customers using R have many different use cases, we've organized the documentation accordingly in order to present only the most useful set of functions for your work. You will find all the documentation in the `documentation` folder. 46 | 47 | [complete-documentation.md](https://github.com/aWhereAPI/aWhere-R-Library/blob/master/documentation/complete-documentation.md) 48 | * This file includes every function. 49 | 50 | [geolocation-usage.md](https://github.com/aWhereAPI/aWhere-R-Library/blob/master/documentation/geolocation-usage.md) 51 | * Some customers will prefer to use latitude and longitude for selecting weather data. This is generally only appropriate and allowed when doing large regional work or for discrete point-by-point data needs. 52 | * This approach is *not* appropriate when tracking data for a field or if not explicitly allowed by your agreement with aWhere. 53 | 54 | [field-based-usage.md](https://github.com/aWhereAPI/aWhere-R-Library/blob/master/documentation/field-based-usage.md) 55 | * This is the primary method for accessing the aWhere platform, and with this approach you register Field Locations with the platform and can add planting data to each field to more easily monitor agronomics and track models. 56 | * If your work is aware of specific field locations and tracking specific growing seasons, this is the appropriate approach to use. 57 | -------------------------------------------------------------------------------- /man/agronomic_norms_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-norms.R 3 | \name{agronomic_norms_area} 4 | \alias{agronomic_norms_area} 5 | \title{agronomic_norms_area} 6 | \usage{ 7 | agronomic_norms_area( 8 | polygon, 9 | month_day_start, 10 | month_day_end, 11 | year_start, 12 | year_end, 13 | propertiesToInclude = "", 14 | exclude_years = NULL, 15 | accumulation_start_date = "", 16 | gdd_method = "standard", 17 | gdd_base_temp = 10, 18 | gdd_min_boundary = 10, 19 | gdd_max_boundary = 30, 20 | includeFeb29thData = TRUE, 21 | numcores = 2, 22 | returnSpatialData = FALSE, 23 | bypassNumCallCheck = FALSE, 24 | verbose = TRUE, 25 | maxTryCount = 3, 26 | keyToUse = awhereEnv75247$uid, 27 | secretToUse = awhereEnv75247$secret, 28 | tokenToUse = awhereEnv75247$token, 29 | apiAddressToUse = awhereEnv75247$apiAddress 30 | ) 31 | } 32 | \arguments{ 33 | \item{polygon}{either a data.frame with column names lat/lon, SpatialPolygons object, 34 | well-known text string, or extent from raster package. If the object contains 35 | multiple polygons, the union of them is used. Information from each individal 36 | polygon can be retrieved by returning spatial data and using 37 | the over function from the sp package} 38 | 39 | \item{month_day_start}{character string of the first month and day for which you want to retrieve data, 40 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) (required)} 41 | 42 | \item{month_day_end}{character string of the last month and day for which you want to retrieve data, 43 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) (required)} 44 | 45 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 46 | you're calculating norms, in the form YYYY. e.g., 2008 (required)} 47 | 48 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 49 | you're calculating norms, in the form YYYY. e.g., 2015 (required)} 50 | 51 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are accumulations, gdd, pet, ppet, accumulatedGdd, accumulatedPrecipitation, accumulatedPet, accumulatedPpet (optional)} 52 | 53 | \item{accumulation_start_date}{Allows the user to start counting accumulations from 54 | before the specified start date (or before the 55 | planting date if using the most recent planting). 56 | Use this parameter to specify the date from which 57 | you wish to start counting, in the form: YYYY-MM-DD. 58 | The daily values object 59 | will still only return the days between the start 60 | and end date. This date must come before the start date. (optional)} 61 | 62 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 63 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 64 | See the API documentation for a description of each method. The standard 65 | method will be used if none is specified. (character - optional)} 66 | 67 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 68 | be used if none is specified. (optional)} 69 | 70 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 71 | The behavior of this value is different depending on the equation you're using 72 | The default value of 10 will be used if none is specified. (optional)} 73 | 74 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 75 | behavior of this value is different depending on the equation you're using. 76 | The default value of 30 will be used if none is specified. (optional)} 77 | 78 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years. Because weather/agronomics 79 | summary statistics are calculated via the calendar date and 3 years are required 80 | to generate a value, data from this date is more likely to be NA. ALlows user 81 | to drop this data to avoid later problems (defaults to TRUE)} 82 | 83 | \item{numcores}{number of cores to use in parallel loop. To check number of available cores: parallel::detectCores(). 84 | If you receive an error regarding the speed you are making calls, reduce this number} 85 | 86 | \item{returnSpatialData}{returns the data as a SpatialPixels object. Can be convered to raster with the command raster::stack 87 | NOTE: if multiple days worth of data is returned, it is necessary to subset to specific day for working with 88 | as spatial data (sp package: optional)} 89 | 90 | \item{bypassNumCallCheck}{set to TRUE to avoid prompting the user to confirm that they want to begin making API calls} 91 | 92 | \item{verbose}{Set to TRUE tp print messages to console about state of parallization call. Typically only visible if run from console and not GUI} 93 | 94 | \item{maxTryCount}{maximum number of times a call is repeated if the the API returns an error. Random pause between each call} 95 | 96 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 97 | 98 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 99 | 100 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 101 | 102 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 103 | 104 | \item{exclude_year}{Year or years which you'd like to exclude from 105 | your range of years on which to calculate norms. To exclude 106 | multiple years, provide a vector of years. You must include 107 | at least three years of data with which to calculate the norms. (numeric, optional)} 108 | } 109 | \value{ 110 | data.frame of requested data for dates requested 111 | } 112 | \description{ 113 | \code{agronomic_norms_area} pulls long term norm weather data from aWhere's API based on a data.frame of lat/lon, polygon or extent 114 | } 115 | \details{ 116 | This function allows you to calculate the averages for agronomic attributes 117 | across any range of years for which data are available. The data pulled includes norms for 118 | growing degree days (GDDs), potential evapotranspiration (PET), Precipitation over 119 | potential evapotranspiration (P/PET), accumulated GDDs, accumulated precipitation, 120 | accumulated PET, and accumulated P/PET, along with the standard deviations 121 | for these variables. The data pulled is for the polygon or extent. The polygon should be either 122 | a SpatialPolygons object or a well-known text character string or an extent. 123 | Default units are returned by the API. 124 | 125 | The data returned in this function 126 | allow you to compare this year or previous years to the long-term normals, calculated as 127 | the average of those agronomic conditions on that day in that location over the years specified. 128 | 129 | Note about dates: The system does not adjust for any difference in dates between the location of the user 130 | and where data is being requested from. It is the responsibility of the user to ensure a valid 131 | date range is specified given any differences in timezone. These differences can have implications 132 | for whether a given date should be requested from the daily_observed functions or the forecast functions. 133 | Furthermore, because this function can take as input locations that may be in different timezones, it is 134 | the responsibility of the user to either ensure that the date range specified is valid for all relevant 135 | locations or to break the query into pieces. 136 | } 137 | \examples{ 138 | \dontrun{agronomic_norms_area(polygon = raster::getData('GADM', country = "Gambia", level = 0, download = T) 139 | ,month_day_start = '02-01' 140 | ,month_day_end = '03-10' 141 | ,year_start = 2008 142 | ,year_end = 2015 143 | ,exclude_years = c(2010,2011) 144 | ,accumulation_start_date = '' 145 | ,gdd_method = 'standard' 146 | ,gdd_base_temp = 10 147 | ,gdd_min_boundary = 10 148 | ,gdd_max_boundary = 30 149 | ,numcores = 2)} 150 | 151 | } 152 | \references{ 153 | https://docs.awhere.com/knowledge-base-docs/historical-agronomic-norms-by-geolocation/ 154 | } 155 | -------------------------------------------------------------------------------- /man/agronomic_norms_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-norms.R 3 | \name{agronomic_norms_fields} 4 | \alias{agronomic_norms_fields} 5 | \title{agronomic_norms_fields} 6 | \usage{ 7 | agronomic_norms_fields( 8 | field_id, 9 | month_day_start, 10 | month_day_end, 11 | year_start, 12 | year_end, 13 | propertiesToInclude = "", 14 | exclude_years = NULL, 15 | accumulation_start_date = "", 16 | gdd_method = "standard", 17 | gdd_base_temp = 10, 18 | gdd_min_boundary = 10, 19 | gdd_max_boundary = 30, 20 | includeFeb29thData = TRUE, 21 | keyToUse = awhereEnv75247$uid, 22 | secretToUse = awhereEnv75247$secret, 23 | tokenToUse = awhereEnv75247$token, 24 | apiAddressToUse = awhereEnv75247$apiAddress 25 | ) 26 | } 27 | \arguments{ 28 | \item{field_id}{the field_id associated with the location for which you want to pull data. 29 | Field IDs are created using the create_field function. (string)} 30 | 31 | \item{month_day_start}{character string of the first month and day for which you want to retrieve data, 32 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) (required)} 33 | 34 | \item{month_day_end}{character string of the last month and day for which you want to retrieve data, 35 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) (required)} 36 | 37 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 38 | you're calculating norms, in the form YYYY. e.g., 2008 (required)} 39 | 40 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 41 | you're calculating norms, in the form YYYY. e.g., 2015 (required)} 42 | 43 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are accumulations, gdd, pet, ppet, accumulatedGdd, accumulatedPrecipitation, accumulatedPet, accumulatedPpet (optional)} 44 | 45 | \item{accumulation_start_date}{Allows the user to start counting accumulations from 46 | before the specified start date (or before the 47 | planting date if using the most recent planting). 48 | Use this parameter to specify the date from which 49 | you wish to start counting, in the form: YYYY-MM-DD. 50 | The daily values object 51 | will still only return the days between the start 52 | and end date. This date must come before the start date. (optional)} 53 | 54 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 55 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 56 | See the API documentation for a description of each method. The standard 57 | method will be used if none is specified. (character - optional)} 58 | 59 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 60 | be used if none is specified. (optional)} 61 | 62 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 63 | The behavior of this value is different depending on the equation you're using 64 | The default value of 10 will be used if none is specified. (optional)} 65 | 66 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 67 | behavior of this value is different depending on the equation you're using. 68 | The default value of 30 will be used if none is specified. (optional)} 69 | 70 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years. Because weather/agronomics 71 | summary statistics are calculated via the calendar date and 3 years are required 72 | to generate a value, data from this date is more likely to be NA. ALlows user 73 | to drop this data to avoid later problems (defaults to TRUE)} 74 | 75 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 76 | 77 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 78 | 79 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 80 | 81 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 82 | 83 | \item{exclude_year}{Year or years which you'd like to exclude from 84 | your range of years on which to calculate norms. To exclude 85 | multiple years, provide a vector of years. You must include 86 | at least three years of data with which to calculate the norms. (numeric, optional)} 87 | } 88 | \value{ 89 | dataframe of requested data for dates requested 90 | } 91 | \description{ 92 | \code{agronomic_norms_fields} pulls agronomic norm data from aWhere's API based on field id 93 | } 94 | \details{ 95 | This function allows you to calculate the averages for agronomic attributes 96 | across any range of years for which data are available. The data pulled includes norms for 97 | growing degree days (GDDs), potential evapotranspiration (PET), Precipitation over 98 | potential evapotranspiration (P/PET), accumulated GDDs, accumulated precipitation, 99 | accumulated PET, and accumulated P/PET, along with the standard deviations 100 | for these variables. The data pulled is for the field id identified. 101 | Default units are returned by the API. 102 | 103 | The data returned in this function 104 | allow you to compare this year or previous years to the long-term normals, calculated as 105 | the average of those agronomic conditions on that day in that location over the years specified. 106 | 107 | Note about dates: The system does not adjust for any difference in dates between the location of the user 108 | and where data is being requested from. It is the responsibility of the user to ensure a valid 109 | date range is specified given any differences in timezone. These differences can have implications 110 | for whether a given date should be requested from the daily_observed functions or the forecast functions 111 | } 112 | \examples{ 113 | \dontrun{agronomic_norms_fields(field_id = 'field_test' 114 | ,month_day_start = '07-01' 115 | ,month_day_end = '07-10' 116 | ,year_start = 2008 117 | ,year_end = 2016 118 | ,exclude_years = "2010" 119 | ,accumulation_start_date = '' 120 | ,gdd_method = 'standard' 121 | ,gdd_base_temp = 10 122 | ,gdd_min_boundary = 10 123 | ,gdd_max_boundary = 30)} 124 | } 125 | \references{ 126 | https://docs.awhere.com/knowledge-base-docs/historical-agronomic-norms/ 127 | } 128 | -------------------------------------------------------------------------------- /man/agronomic_norms_latlng.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-norms.R 3 | \name{agronomic_norms_latlng} 4 | \alias{agronomic_norms_latlng} 5 | \title{agronomic_norms_latlng} 6 | \usage{ 7 | agronomic_norms_latlng( 8 | latitude, 9 | longitude, 10 | month_day_start, 11 | month_day_end, 12 | year_start, 13 | year_end, 14 | propertiesToInclude = "", 15 | exclude_years = NULL, 16 | accumulation_start_date = "", 17 | gdd_method = "standard", 18 | gdd_base_temp = 10, 19 | gdd_min_boundary = 10, 20 | gdd_max_boundary = 30, 21 | includeFeb29thData = TRUE, 22 | keyToUse = awhereEnv75247$uid, 23 | secretToUse = awhereEnv75247$secret, 24 | tokenToUse = awhereEnv75247$token, 25 | apiAddressToUse = awhereEnv75247$apiAddress 26 | ) 27 | } 28 | \arguments{ 29 | \item{latitude}{the latitude of the requested location (double, required)} 30 | 31 | \item{longitude}{the longitude of the requested locations (double, required)} 32 | 33 | \item{month_day_start}{character string of the first month and day for which you want to retrieve data, 34 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) (required)} 35 | 36 | \item{month_day_end}{character string of the last month and day for which you want to retrieve data, 37 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) (required)} 38 | 39 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 40 | you're calculating norms, in the form YYYY. e.g., 2008 (required)} 41 | 42 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 43 | you're calculating norms, in the form YYYY. e.g., 2015 (required)} 44 | 45 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are accumulations, gdd, pet, ppet, accumulatedGdd, accumulatedPrecipitation, accumulatedPet, accumulatedPpet (optional)} 46 | 47 | \item{accumulation_start_date}{Allows the user to start counting accumulations from 48 | before the specified start date (or before the 49 | planting date if using the most recent planting). 50 | Use this parameter to specify the date from which 51 | you wish to start counting, in the form: YYYY-MM-DD. 52 | The daily values object 53 | will still only return the days between the start 54 | and end date. This date must come before the start date. (optional)} 55 | 56 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 57 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 58 | See the API documentation for a description of each method. The standard 59 | method will be used if none is specified. (character - optional)} 60 | 61 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 62 | be used if none is specified. (optional)} 63 | 64 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 65 | The behavior of this value is different depending on the equation you're using 66 | The default value of 10 will be used if none is specified. (optional)} 67 | 68 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 69 | behavior of this value is different depending on the equation you're using. 70 | The default value of 30 will be used if none is specified. (optional)} 71 | 72 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years. Because weather/agronomics 73 | summary statistics are calculated via the calendar date and 3 years are required 74 | to generate a value, data from this date is more likely to be NA. ALlows user 75 | to drop this data to avoid later problems (defaults to TRUE)} 76 | 77 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 78 | 79 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 80 | 81 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 82 | 83 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 84 | 85 | \item{exclude_year}{Year or years which you'd like to exclude from 86 | your range of years on which to calculate norms. To exclude 87 | multiple years, provide a vector of years. You must include 88 | at least three years of data with which to calculate the norms. (numeric, optional)} 89 | } 90 | \value{ 91 | dataframe of requested data for dates requested 92 | } 93 | \description{ 94 | \code{agronomic_norms_latlng} pulls agronomic norm data from aWhere's API based on latitude & longitude 95 | } 96 | \details{ 97 | This function allows you to calculate the averages for agronomic attributes 98 | across any range of years for which data are available. The data pulled includes norms for 99 | growing degree days (GDDs), potential evapotranspiration (PET), Precipitation over 100 | potential evapotranspiration (P/PET), accumulated GDDs, accumulated precipitation, 101 | accumulated PET, and accumulated P/PET, along with the standard deviations 102 | for these variables. The data pulled is for the latitude and longitude identified. 103 | Default units are returned by the API. 104 | 105 | The data returned in this function 106 | allow you to compare this year or previous years to the long-term normals, calculated as 107 | the average of those agronomic conditions on that day in that location over the years specified. 108 | 109 | Note about dates: The system does not adjust for any difference in dates between the location of the user 110 | and where data is being requested from. It is the responsibility of the user to ensure a valid 111 | date range is specified given any differences in timezone. These differences can have implications 112 | for whether a given date should be requested from the daily_observed functions or the forecast functions 113 | } 114 | \examples{ 115 | 116 | \dontrun{agronomic_norms_latlng(latitude = 39.8282 117 | ,longitude = -98.5795 118 | ,month_day_start = '02-01' 119 | ,month_day_end = '03-10' 120 | ,year_start = 2008 121 | ,year_end = 2015 122 | ,exclude_years = c(2010,2011) 123 | ,accumulation_start_date = '' 124 | ,gdd_method = 'standard' 125 | ,gdd_base_temp = 10 126 | ,gdd_min_boundary = 10 127 | ,gdd_max_boundary = 30)} 128 | 129 | } 130 | \references{ 131 | https://docs.awhere.com/knowledge-base-docs/historical-agronomic-norms-by-geolocation/ 132 | } 133 | -------------------------------------------------------------------------------- /man/agronomic_values_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-values.R 3 | \name{agronomic_values_area} 4 | \alias{agronomic_values_area} 5 | \title{agronomic_values_area} 6 | \usage{ 7 | agronomic_values_area( 8 | polygon, 9 | day_start, 10 | day_end, 11 | propertiesToInclude = "", 12 | accumulation_start_date = "", 13 | gdd_method = "standard", 14 | gdd_base_temp = 10, 15 | gdd_min_boundary = 10, 16 | gdd_max_boundary = 30, 17 | numcores = 2, 18 | bypassNumCallCheck = FALSE, 19 | returnSpatialData = FALSE, 20 | verbose = TRUE, 21 | maxTryCount = 3, 22 | keyToUse = awhereEnv75247$uid, 23 | secretToUse = awhereEnv75247$secret, 24 | tokenToUse = awhereEnv75247$token, 25 | apiAddressToUse = awhereEnv75247$apiAddress 26 | ) 27 | } 28 | \arguments{ 29 | \item{polygon}{either a data.frame with column names lat/lon, SpatialPolygons object, 30 | well-known text string, or extent from raster package. If the object contains 31 | multiple polygons, the union of them is used. Information from each individal 32 | polygon can be retrieved by returning spatial data and using 33 | the over function from the sp package} 34 | 35 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 36 | 37 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 38 | 39 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are accumulations, gdd, pet, ppet, accumulatedGdd, accumulatedPrecipitation, accumulatedPet, accumulatedPpet (optional)} 40 | 41 | \item{accumulation_start_date}{Allows the user to start counting accumulations from 42 | before the specified start date (or before the 43 | planting date if using the most recent planting). 44 | Use this parameter to specify the date from which 45 | you wish to start counting, in the form: YYYY-MM-DD. 46 | The daily values object 47 | will still only return the days between the start 48 | and end date. This date must come before the start date. (optional)} 49 | 50 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 51 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 52 | See the API documentation for a description of each method. The standard 53 | method will be used if none is specified. (character - optional)} 54 | 55 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 56 | be used if none is specified. (optional)} 57 | 58 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 59 | The behavior of this value is different depending on the equation you're using 60 | The default value of 10 will be used if none is specified. (optional)} 61 | 62 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 63 | behavior of this value is different depending on the equation you're using. 64 | The default value of 30 will be used if none is specified. (optional)} 65 | 66 | \item{numcores}{number of cores to use in parallel loop. To check number of available cores: parallel::detectCores() 67 | If you receive an error regarding the speed you are making calls, reduce this number} 68 | 69 | \item{bypassNumCallCheck}{set to TRUE to avoid prompting the user to confirm that they want to begin making API calls} 70 | 71 | \item{returnSpatialData}{returns the data as a SpatialPixels object. Can be convered to raster with the command raster::stack 72 | NOTE: if multiple days worth of data is returned, it is necessary to subset to specific day for working with 73 | as spatial data (sp package: optional)} 74 | 75 | \item{verbose}{Set to TRUE tp print messages to console about state of parallization call. Typically only visible if run from console and not GUI} 76 | 77 | \item{maxTryCount}{maximum number of times a call is repeated if the the API returns an error. Random pause between each call} 78 | 79 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 80 | 81 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 82 | 83 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 84 | 85 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 86 | } 87 | \value{ 88 | data.frame of requested data for dates requested 89 | } 90 | \description{ 91 | \code{agronomic_values_area} pulls agronomic data from aWhere's API based on a data.frame of lat/lon, polygon or extent 92 | } 93 | \details{ 94 | This function returns agronomic data on GDDs, potential evapotranspiration (PET), Precipitation over 95 | potential evapotranspiration (P/PET), accumulated GDDs, accumulated precipitation, accumulated PET, and 96 | accumulated P/PET. Default units are returned by the API. 97 | 98 | Agronomic Values are calculated numbers that can be used to show the agronomic status of a field or crop. 99 | These figures can be used, for example, to track and predict plant growth or identify water stress. 100 | Accumulated values allow growers to easily identify how the weather has been over the season. 101 | Both sets of data are commonly used on small and large farms alike. This is a very flexible API 102 | that supports a wide variety of configurations to get exactly the data you want as efficiently as 103 | possible. 104 | 105 | The polygon should be either a SpatialPolygons object or a well-known text character string or an extent. 106 | 107 | Note about dates: The system does not adjust for any difference in dates between the location of the user 108 | and where data is being requested from. It is the responsibility of the user to ensure a valid 109 | date range is specified given any differences in timezone. These differences can have implications 110 | for whether a given date should be requested from the daily_observed functions or the forecast functions. 111 | Furthermore, because this function can take as input locations that may be in different timezones, it is 112 | the responsibility of the user to either ensure that the date range specified is valid for all relevant 113 | locations or to break the query into pieces. 114 | } 115 | \examples{ 116 | \dontrun{agronomic_values_area(polygon = raster::getData('GADM', country = "Gambia", level = 0, download = T), 117 | ,day_start = '2018-04-28' 118 | ,day_end = '2018-05-01' 119 | ,numcores = 2)} 120 | } 121 | \references{ 122 | https://docs.awhere.com/knowledge-base-docs/agronomic-values-accumulations-by-geolocation/ 123 | } 124 | -------------------------------------------------------------------------------- /man/agronomic_values_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-values.R 3 | \name{agronomic_values_fields} 4 | \alias{agronomic_values_fields} 5 | \title{agronomic_values_fields} 6 | \usage{ 7 | agronomic_values_fields( 8 | field_id, 9 | day_start, 10 | day_end, 11 | propertiesToInclude = "", 12 | accumulation_start_date = "", 13 | gdd_method = "standard", 14 | gdd_base_temp = 10, 15 | gdd_min_boundary = 10, 16 | gdd_max_boundary = 30, 17 | keyToUse = awhereEnv75247$uid, 18 | secretToUse = awhereEnv75247$secret, 19 | tokenToUse = awhereEnv75247$token, 20 | apiAddressToUse = awhereEnv75247$apiAddress 21 | ) 22 | } 23 | \arguments{ 24 | \item{field_id}{the field_id associated with the location for which you want to pull data. 25 | Field IDs are created using the create_field function. (string)} 26 | 27 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 28 | 29 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 30 | 31 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are accumulations, gdd, pet, ppet, accumulatedGdd, accumulatedPrecipitation, accumulatedPet, accumulatedPpet (optional)} 32 | 33 | \item{accumulation_start_date}{Allows the user to start counting accumulations from 34 | before the specified start date (or before the 35 | planting date if using the most recent planting). 36 | Use this parameter to specify the date from which 37 | you wish to start counting, in the form: YYYY-MM-DD. 38 | The daily values object 39 | will still only return the days between the start 40 | and end date. This date must come before the start date. (optional)} 41 | 42 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 43 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 44 | See the API documentation for a description of each method. The standard 45 | method will be used if none is specified. (character - optional)} 46 | 47 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 48 | be used if none is specified. (optional)} 49 | 50 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 51 | The behavior of this value is different depending on the equation you're using 52 | The default value of 10 will be used if none is specified. (optional)} 53 | 54 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 55 | behavior of this value is different depending on the equation you're using. 56 | The default value of 30 will be used if none is specified. (optional)} 57 | 58 | \item{keyToUse}{aWhere API uid to use. For advanced use only. Most users will not need to use this parameter (optional)} 59 | 60 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 61 | 62 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 63 | 64 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 65 | } 66 | \value{ 67 | dataframe of requested data for dates requested 68 | } 69 | \description{ 70 | \code{agronomic_values_fields} pulls agronomic data from aWhere's API based on field id 71 | } 72 | \details{ 73 | This function returns agronomic data on growing degree days (GDDs), potential evapotranspiration (PET), Precipitation over 74 | potential evapotranspiration (P/PET), accumulated GDDs, accumulated precipitation, accumulated PET, and 75 | accumulated P/PET. Default units are returned by the API. 76 | 77 | Agronomic Values are calculated numbers that can be used to show the agronomic status of a field or crop. 78 | These figures can be used, for example, to track and predict plant growth or identify water stress. 79 | Accumulated values allow growers to easily identify how the weather has been over the season. 80 | Both sets of data are commonly used on small and large farms alike. This is a very flexible API 81 | that supports a wide variety of configurations to get exactly the data you want as efficiently as 82 | possible. It's also designed to work with the Fields and Plantings system to reduce the amount of input. 83 | While a planting is not required to use this API, creating a Planting for your Fields will allow you 84 | to get the most out of the aWhere platform. 85 | 86 | Note about dates: The system does not adjust for any difference in dates between the location of the user 87 | and where data is being requested from. It is the responsibility of the user to ensure a valid 88 | date range is specified given any differences in timezone. These differences can have implications 89 | for whether a given date should be requested from the daily_observed functions or the forecast functions 90 | } 91 | \examples{ 92 | \dontrun{agronomic_values_fields(field_id = "field_test" 93 | ,day_start = "2018-11-01" 94 | ,day_end = "2018-11-30" 95 | ,gdd_method = "modifiedstandard" 96 | ,gdd_base_temp = 10 97 | ,gdd_min_boundary = 10 98 | ,gdd_max_boundary = 30)} 99 | } 100 | \references{ 101 | https://docs.awhere.com/knowledge-base-docs/agronomic-values-accumulations/ 102 | } 103 | -------------------------------------------------------------------------------- /man/agronomic_values_latlng.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-values.R 3 | \name{agronomic_values_latlng} 4 | \alias{agronomic_values_latlng} 5 | \title{agronomic_values_latlng.} 6 | \usage{ 7 | agronomic_values_latlng( 8 | latitude, 9 | longitude, 10 | day_start, 11 | day_end, 12 | propertiesToInclude = "", 13 | accumulation_start_date = "", 14 | gdd_method = "standard", 15 | gdd_base_temp = 10, 16 | gdd_min_boundary = 10, 17 | gdd_max_boundary = 30, 18 | keyToUse = awhereEnv75247$uid, 19 | secretToUse = awhereEnv75247$secret, 20 | tokenToUse = awhereEnv75247$token, 21 | apiAddressToUse = awhereEnv75247$apiAddress 22 | ) 23 | } 24 | \arguments{ 25 | \item{latitude}{the latitude of the requested location (double)} 26 | 27 | \item{longitude}{the longitude of the requested locations (double)} 28 | 29 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 30 | 31 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 32 | 33 | \item{propertiesToInclude}{character vector of properties to retrieve from API. 34 | Valid values are accumulations, gdd, pet, ppet, accumulatedGdd, 35 | accumulatedPrecipitation, accumulatedPet, accumulatedPpet (optional)} 36 | 37 | \item{accumulation_start_date}{Allows the user to start counting accumulations from 38 | before the specified start date (or before the 39 | planting date if using the most recent planting). 40 | Use this parameter to specify the date from which 41 | you wish to start counting, in the form: YYYY-MM-DD. 42 | The daily values object 43 | will still only return the days between the start 44 | and end date. This date must come before the start date. (optional)} 45 | 46 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 47 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 48 | See the API documentation for a description of each method. The standard 49 | method will be used if none is specified. (character - optional)} 50 | 51 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 52 | be used if none is specified. (optional)} 53 | 54 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 55 | The behavior of this value is different depending on the equation you're using 56 | The default value of 10 will be used if none is specified. (optional)} 57 | 58 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 59 | behavior of this value is different depending on the equation you're using. 60 | The default value of 30 will be used if none is specified. (optional)} 61 | 62 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 63 | 64 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 65 | 66 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 67 | 68 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 69 | } 70 | \value{ 71 | data.frame of requested data for dates requested 72 | } 73 | \description{ 74 | \code{agronomic_values_latlng} pulls agronomic data from aWhere's API based on latitude & longitude 75 | } 76 | \details{ 77 | This function returns agronomic data on GDDs, potential evapotranspiration (PET), Precipitation over 78 | potential evapotranspiration (P/PET), accumulated GDDs, accumulated precipitation, accumulated PET, and 79 | accumulated P/PET. Default units are returned by the API. 80 | 81 | Agronomic Values are calculated numbers that can be used to show the agronomic status of a field or crop. 82 | These figures can be used, for example, to track and predict plant growth or identify water stress. 83 | Accumulated values allow growers to easily identify how the weather has been over the season. 84 | Both sets of data are commonly used on small and large farms alike. This is a very flexible API 85 | that supports a wide variety of configurations to get exactly the data you want as efficiently as 86 | possible. 87 | 88 | Note about dates: The system does not adjust for any difference in dates between the location of the user 89 | and where data is being requested from. It is the responsibility of the user to ensure a valid 90 | date range is specified given any differences in timezone. These differences can have implications 91 | for whether a given date should be requested from the daily_observed functions or the forecast functions 92 | } 93 | \examples{ 94 | \dontrun{agronomic_values_latlng(latitude = 39.8282 95 | ,longitude = -98.5795 96 | ,day_start = '2018-11-01' 97 | ,day_end = '2018-11-30')} 98 | } 99 | \references{ 100 | https://docs.awhere.com/knowledge-base-docs/agronomic-values-accumulations-by-geolocation/ 101 | } 102 | -------------------------------------------------------------------------------- /man/checkAccumulationStartDate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkAccumulationStartDate} 4 | \alias{checkAccumulationStartDate} 5 | \title{Check Accumulation Start Date} 6 | \usage{ 7 | checkAccumulationStartDate(accumulation_start_date, month_day_start) 8 | } 9 | \arguments{ 10 | \item{accumulation_start_date}{If you want to start counting accumulations from 11 | before the specified start date (or before the 12 | planting date if using the most recent Planting), 13 | use this parameter to specify the date from which 14 | you wish to start counting. The daily values object 15 | will still only return the days between the start 16 | and end date. This date must come before the start date.} 17 | 18 | \item{-}{month_day_start} 19 | } 20 | \description{ 21 | \code{checkAccumulationStartDate} Checks to see if the accumulation start date is valid 22 | } 23 | -------------------------------------------------------------------------------- /man/checkAccumulationStartDateNorms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkAccumulationStartDateNorms} 4 | \alias{checkAccumulationStartDateNorms} 5 | \title{Check Accumulation Start Date Norms} 6 | \usage{ 7 | checkAccumulationStartDateNorms(accumulation_start_date, month_day_start) 8 | } 9 | \arguments{ 10 | \item{accumulation_start_date}{If you want to start counting accumulations from 11 | before the specified start date (or before the 12 | planting date if using the most recent Planting), 13 | use this parameter to specify the date from which 14 | you wish to start counting. The daily values object 15 | will still only return the days between the start 16 | and end date. This date must come before the start date.} 17 | 18 | \item{-}{month_day_start} 19 | } 20 | \description{ 21 | \code{checkAccumulationStartDate} Checks to see if the accumulation start date is valid 22 | } 23 | -------------------------------------------------------------------------------- /man/checkCredentials.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkCredentials} 4 | \alias{checkCredentials} 5 | \title{Check Valid Credentials Loaded} 6 | \usage{ 7 | checkCredentials(keyToUse, secretToUse, tokenToUse) 8 | } 9 | \arguments{ 10 | \item{keyToUse}{aWhere API key to use} 11 | 12 | \item{secretToUse}{aWhere API secret to use} 13 | 14 | \item{tokenToUse}{aWhere API token to use} 15 | } 16 | \description{ 17 | \code{checkCredentials} Checks to see if valid aWhere API credentials are loaded 18 | } 19 | -------------------------------------------------------------------------------- /man/checkDataReturn_daily.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkDataReturn.R 3 | \name{checkDataReturn_daily} 4 | \alias{checkDataReturn_daily} 5 | \title{checkDataReturn_daily} 6 | \usage{ 7 | checkDataReturn_daily(dataset, day_start, day_end) 8 | } 9 | \arguments{ 10 | \item{dataset}{the data.frame to check} 11 | 12 | \item{day_start}{character string of the first day for which data was retrieved, in the form: YYYY-MM-DD} 13 | 14 | \item{day_end}{character string of the last day for which data was retrieved, in the form: YYYY-MM-DD} 15 | } 16 | \description{ 17 | \code{checkDataReturn_daily} Checks to see if data return is complete from API endpoints with daily data 18 | } 19 | -------------------------------------------------------------------------------- /man/checkDataReturn_forecasts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkDataReturn.R 3 | \name{checkDataReturn_forecasts} 4 | \alias{checkDataReturn_forecasts} 5 | \title{checkDataReturn_forecasts} 6 | \usage{ 7 | checkDataReturn_forecasts(dataset, day_start, day_end, block_size) 8 | } 9 | \arguments{ 10 | \item{dataset}{the data.frame to check} 11 | 12 | \item{day_start}{character string of the first day for which data was retrieved, in the form: YYYY-MM-DD} 13 | 14 | \item{day_end}{character string of the last day for which data was retrieved, in the form: YYYY-MM-DD} 15 | 16 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 17 | Defaults to a 1 hour block. This value must divide evenly into 24.} 18 | } 19 | \description{ 20 | \code{checkDataReturn_forecasts} Checks to see if data return is complete from forecasts API endpoint 21 | } 22 | -------------------------------------------------------------------------------- /man/checkDataReturn_norms.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkDataReturn.R 3 | \name{checkDataReturn_norms} 4 | \alias{checkDataReturn_norms} 5 | \title{checkDataReturn_norms} 6 | \usage{ 7 | checkDataReturn_norms( 8 | dataset, 9 | monthday_start, 10 | monthday_end, 11 | year_start, 12 | year_end, 13 | exclude_year, 14 | includeFeb29thData 15 | ) 16 | } 17 | \arguments{ 18 | \item{dataset}{the data.frame to check} 19 | 20 | \item{monthday_start}{character string of the first month and day for which you want to retrieve data, 21 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1)} 22 | 23 | \item{monthday_end}{character string of the last month and day for which you want to retrieve data, 24 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1)} 25 | 26 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 27 | you're calculating norms, in the form YYYY. e.g., 2008} 28 | 29 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 30 | you're calculating norms, in the form YYYY. e.g., 2015} 31 | 32 | \item{exclude_year}{Year or years which you'd like to exclude from 33 | your range of years on which to calculate norms. To exclude 34 | multiple years, provide a vector of years. You must include 35 | at least three years of data with which to calculate the norms.} 36 | 37 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years.} 38 | } 39 | \description{ 40 | \code{checkDataReturn_norms} Checks to see if data return is complete from norms API 41 | } 42 | -------------------------------------------------------------------------------- /man/checkForecastParams.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkForecastParams} 4 | \alias{checkForecastParams} 5 | \title{Check Forecast Parameters} 6 | \usage{ 7 | checkForecastParams(block_size) 8 | } 9 | \arguments{ 10 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block.} 11 | 12 | \item{day_start}{character string of start date in form: YYYY-MM-DD} 13 | } 14 | \description{ 15 | \code{checkForecastParams} Checks to see if Forecast Params are valid 16 | } 17 | -------------------------------------------------------------------------------- /man/checkForecastSources.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkForecastSources} 4 | \alias{checkForecastSources} 5 | \title{Check Forecast Sources} 6 | \usage{ 7 | checkForecastSources(sources) 8 | } 9 | \description{ 10 | \code{checkForecastSources} Checks that the requested Forecast source is valid 11 | } 12 | -------------------------------------------------------------------------------- /man/checkGDDParams.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkGDDParams} 4 | \alias{checkGDDParams} 5 | \title{Check Valid GDD Params} 6 | \usage{ 7 | checkGDDParams(gdd_method, gdd_base_temp, gdd_min_boundary, gdd_max_boundary) 8 | } 9 | \arguments{ 10 | \item{gdd_method}{There are variety of equations available for calculating growing degree-days. 11 | Valid entries are: 'standard', 'modifiedstandard', 'min-temp-cap', 'min-temp-constant' 12 | See the API documentation for a description of each method. The standard 13 | method will be used if none is specified} 14 | 15 | \item{gdd_base_temp}{The base temp to use for the any of the GDD equations. The default value of 10 will 16 | be used if none is specified} 17 | 18 | \item{gdd_min_boundary}{The minimum boundary to use in the selected GDD equation. 19 | The behavior of this value is different depending on the equation you're using 20 | The default value of 10 will be used if none is specified} 21 | 22 | \item{gdd_max_boundary}{The max boundary to use in the selected GDD equation. The 23 | behavior of this value is different depending on the equation you're using. 24 | The default value of 30 will be used if none is specified} 25 | } 26 | \description{ 27 | \code{checkGDDParams} Checks to see if GDD params are valid 28 | } 29 | -------------------------------------------------------------------------------- /man/checkNormsStartEndDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkNormsStartEndDates} 4 | \alias{checkNormsStartEndDates} 5 | \title{Checks Start/End Dates for Norms} 6 | \usage{ 7 | checkNormsStartEndDates(month_day_start, month_day_end) 8 | } 9 | \arguments{ 10 | \item{monthday_start}{character string of the month and day for the start 11 | of the range of days you are calculating norms for, e.g., '07-01' (July 1)} 12 | 13 | \item{monthday_end}{character string of the month and day for the end of the 14 | range of days you are calculating norms for, e.g., '07-10' (July 10)} 15 | } 16 | \description{ 17 | \code{checkNormsStartEndDates} Checks Start/End Dates for Norms endpoint are valid 18 | } 19 | -------------------------------------------------------------------------------- /man/checkNormsYearsToRequest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkNormsYearsToRequest} 4 | \alias{checkNormsYearsToRequest} 5 | \title{Check Years to Request for Norms} 6 | \usage{ 7 | checkNormsYearsToRequest( 8 | year_start, 9 | year_end, 10 | month_day_start, 11 | month_day_end, 12 | exclude_years 13 | ) 14 | } 15 | \arguments{ 16 | \item{year_start}{the starting year (inclusive) of the range of years for which 17 | you're calculating norms, e.g., 2008} 18 | 19 | \item{year_end}{the end year (inclusive) of the range of years for which you're 20 | calculating norms, e.g., 2015} 21 | 22 | \item{exclude_years}{You can opt to exclude one or more years from the range, and 23 | it's values will not be included in the averages. To exclude 24 | multiple years, provide a vector of years. Note: You must always have 25 | at least three years of data to average} 26 | } 27 | \description{ 28 | \code{checkNormsYearsToRequest} Check that the Years to be Requested for Norms is valid 29 | } 30 | -------------------------------------------------------------------------------- /man/checkPropertiesEndpoint.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkPropertiesEndpoint} 4 | \alias{checkPropertiesEndpoint} 5 | \title{Check Properties for Weather Endpoint} 6 | \usage{ 7 | checkPropertiesEndpoint(endpoint, propertiesToInclude) 8 | } 9 | \arguments{ 10 | \item{propertiesToInclude}{vector of properties requested from API} 11 | } 12 | \description{ 13 | \code{checkPropertiesWeather} Check that the Years to be Requested for Norms is valid 14 | } 15 | -------------------------------------------------------------------------------- /man/checkStatusCode.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkStatusCodeOfReturn.R 3 | \name{checkStatusCode} 4 | \alias{checkStatusCode} 5 | \title{Check Status Code of Return} 6 | \usage{ 7 | checkStatusCode(request) 8 | } 9 | \arguments{ 10 | \item{request}{object returned from HTTR} 11 | } 12 | \description{ 13 | \code{checkStatusCode} Checks to see if valid aWhere API credentials are loaded 14 | } 15 | -------------------------------------------------------------------------------- /man/checkValidField.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkValidField} 4 | \alias{checkValidField} 5 | \title{Check Valid Field ID} 6 | \usage{ 7 | checkValidField(field_id, keyToUse, secretToUse, tokenToUse) 8 | } 9 | \arguments{ 10 | \item{field_id}{the field_id having previously been created with the createField Function} 11 | 12 | \item{keyToUse}{aWhere API key to use} 13 | 14 | \item{secretToUse}{aWhere API secret to use} 15 | 16 | \item{tokenToUse}{aWhere API token to use} 17 | } 18 | \description{ 19 | \code{checkValidField} Checks to see if the Field ID is valid 20 | } 21 | -------------------------------------------------------------------------------- /man/checkValidLatLong.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkValidLatLong} 4 | \alias{checkValidLatLong} 5 | \title{Check Valid Lat/Long} 6 | \usage{ 7 | checkValidLatLong(latitude, longitude) 8 | } 9 | \arguments{ 10 | \item{latitude}{the latitude for the location for which you want data} 11 | 12 | \item{longitude}{the latitude for the location for which you want data} 13 | } 14 | \description{ 15 | \code{checkValidLatLong} Checks to see if Lat/Long coordinates are valid 16 | } 17 | -------------------------------------------------------------------------------- /man/checkValidStartEndDates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkValidStartEndDates} 4 | \alias{checkValidStartEndDates} 5 | \title{Check Valid Start End Dates} 6 | \usage{ 7 | checkValidStartEndDates(day_start, day_end) 8 | } 9 | \arguments{ 10 | \item{day_start}{character string of start date in form: YYYY-MM-DD} 11 | 12 | \item{day_end}{character string of end date in form: YYYY-MM-DD} 13 | } 14 | \description{ 15 | \code{checkValidStartEndDates} Checks to see if Start/End Dates passed are valid 16 | } 17 | -------------------------------------------------------------------------------- /man/checkValidStartEndDatesAgronomics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkValidStartEndDatesAgronomics} 4 | \alias{checkValidStartEndDatesAgronomics} 5 | \title{Check Valid Start End Dates for Agronomics Endpoint} 6 | \usage{ 7 | checkValidStartEndDatesAgronomics(day_start, day_end) 8 | } 9 | \arguments{ 10 | \item{day_start}{character string of start date in form: YYYY-MM-DD} 11 | 12 | \item{day_end}{character string of end date in form: YYYY-MM-DD} 13 | } 14 | \description{ 15 | \code{checkValidStartEndDates} Checks to see if Start/End Dates passed are valid 16 | } 17 | -------------------------------------------------------------------------------- /man/checkValidStartEndDatesForecast.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checkValidParamsFns.R 3 | \name{checkValidStartEndDatesForecast} 4 | \alias{checkValidStartEndDatesForecast} 5 | \title{Check Valid Start End Dates for Forecast} 6 | \usage{ 7 | checkValidStartEndDatesForecast(day_start, day_end) 8 | } 9 | \arguments{ 10 | \item{day_start}{character string of start date in form: YYYY-MM-DD} 11 | 12 | \item{day_end}{character string of end date in form: YYYY-MM-DD} 13 | } 14 | \description{ 15 | \code{checkValidStartEndDatesForecast} Checks to see if Start/End Dates passed are valid for Forecast 16 | } 17 | -------------------------------------------------------------------------------- /man/check_JSON.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get-token.R 3 | \name{check_JSON} 4 | \alias{check_JSON} 5 | \title{Check JSON Object} 6 | \usage{ 7 | check_JSON(jsonObject, request, keyToUse, secretToUse, tokenToUse) 8 | } 9 | \arguments{ 10 | \item{request}{the returned request code} 11 | 12 | \item{keyToUse}{aWhere API key to use.} 13 | 14 | \item{secretToUse}{aWhere API secret to use.} 15 | 16 | \item{tokenToUse}{aWhere API token to use.} 17 | 18 | \item{JSON}{object returned from aWhere API} 19 | } 20 | \value{ 21 | boolean for whether another query should be made 22 | } 23 | \description{ 24 | \code{check_JSON} Checks to make sure JSON object isn't an error 25 | } 26 | \details{ 27 | Checks that aWhere API didn't return an error code and that the token used in query hasn't expired 28 | } 29 | -------------------------------------------------------------------------------- /man/create_awhere_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create-awhere-grid.R 3 | \name{create_awhere_grid} 4 | \alias{create_awhere_grid} 5 | \title{Create aWhere Grid} 6 | \usage{ 7 | create_awhere_grid(polygon) 8 | } 9 | \arguments{ 10 | \item{-}{polygon: either a SpatialPolygons data type object or a character string of valid WKT} 11 | } 12 | \description{ 13 | \code{create_awhere_grid} based on a SpatialPolygon, creates a data frame based on aWhere's grid system 14 | } 15 | \details{ 16 | Creates a grid of lat/lon points within given polygon. 17 | The aWhere grid is spaced at .08333 decimal degrees resolution (or 5 arc-minutes), 18 | so spacing a new grid at every .08 degrees should guarantee 19 | a grid point in each aWhere grid cell. 20 | } 21 | -------------------------------------------------------------------------------- /man/create_field.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create.R 3 | \name{create_field} 4 | \alias{create_field} 5 | \title{Create Field} 6 | \usage{ 7 | create_field( 8 | field_id, 9 | latitude, 10 | longitude, 11 | farm_id, 12 | field_name = "", 13 | acres = "", 14 | verbose = TRUE, 15 | keyToUse = awhereEnv75247$uid, 16 | secretToUse = awhereEnv75247$secret, 17 | tokenToUse = awhereEnv75247$token, 18 | apiAddressToUse = awhereEnv75247$apiAddress 19 | ) 20 | } 21 | \arguments{ 22 | \item{field_id}{an ID of your choosing (string)} 23 | 24 | \item{latitude}{the latitude of the field location in decimal format (double)} 25 | 26 | \item{longitude}{the longitude of the field location in decimal format (double)} 27 | 28 | \item{field_name}{a name of the location (optional - string)} 29 | 30 | \item{acres}{the acres of the field (optional)} 31 | 32 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 33 | 34 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 35 | 36 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 37 | 38 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 39 | 40 | \item{farmid}{an ID of your choosing for the farm to which this field belongs (string)} 41 | } 42 | \value{ 43 | - printed text that informs if the query succeeded or not 44 | } 45 | \description{ 46 | \code{create_field} This function will generate a new field associated with the user's account in the aWhere API. 47 | This is a one-time operation for each field. 48 | } 49 | \details{ 50 | Fields are how you manage the locations for which you're tracking weather, agronomics, 51 | models, and progress over growing seasons in the aWhere API. By registering a field, you create a quick way 52 | to consistently reference locations across all of our APIs, and allow our modeling APIs 53 | to better operate and tune to the conditions and status of each specific field. 54 | 55 | Creating a field registers the location with the aWhere system, making it easier to reference 56 | and track your locations as well as run agronomics and models automatically. You 57 | only need to create a field once, after which you can reference the field by ID 58 | (you'll use this ID in most URI endpoints in the aWhere system). 59 | 60 | All spaces will be converted to underscores to conform with the requirements of the API. 61 | } 62 | \examples{ 63 | \dontrun{ 64 | create_field(field_id = "field123",latitude = 39.8282,longitude = -98.5795,farm_id = "farmA",field_name = "Some Field Location",acres = 100) 65 | create_field(field_id = "field_test", latitude = 39.971906, longitude = -105.088773, farm_id = "Office") 66 | } 67 | } 68 | \references{ 69 | https://docs.awhere.com/knowledge-base-docs/create-a-field-location/ 70 | } 71 | -------------------------------------------------------------------------------- /man/create_planting.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create.R 3 | \name{create_planting} 4 | \alias{create_planting} 5 | \title{Create Planting} 6 | \usage{ 7 | create_planting( 8 | field_id, 9 | crop, 10 | planting_date, 11 | proj_yield_amount = "", 12 | proj_yield_units = "", 13 | proj_harvest_date = "", 14 | yield_amount = "", 15 | yield_units = "", 16 | harvest_date = "", 17 | verbose = TRUE, 18 | keyToUse = awhereEnv75247$uid, 19 | secretToUse = awhereEnv75247$secret, 20 | tokenToUse = awhereEnv75247$token, 21 | apiAddressToUse = awhereEnv75247$apiAddress 22 | ) 23 | } 24 | \arguments{ 25 | \item{field_id}{an ID of your choosing (string)} 26 | 27 | \item{crop}{cropId or crop name (string)} 28 | 29 | \item{planting_date}{date crop was planted in the field. Format as YYYY-MM-DD (string)} 30 | 31 | \item{proj_yield_amount}{amount of projected yield from planting (string)} 32 | 33 | \item{proj_yield_units}{units of projected yield (string - optional)} 34 | 35 | \item{proj_harvest_date}{projected harvest date at the start of the season. Format as YYYY-MM-DD (string - optional)} 36 | 37 | \item{yield_amount}{actual yield (string - optional)} 38 | 39 | \item{yield_units}{units of actual yield (string - optional)} 40 | 41 | \item{harvest_date}{actual harvest date at end of season. Format as YYYY-MM-DD (string - optional)} 42 | 43 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 44 | 45 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 46 | 47 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 48 | 49 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 50 | } 51 | \value{ 52 | - system generated planting id along with a print text that informs if the query succeeded or not 53 | } 54 | \description{ 55 | \code{create_planting} creates a planting in a field location in the aWhere platform for which you can request weather 56 | } 57 | \details{ 58 | Fields are how you manage the locations for which you're tracking weather, agronomics, 59 | models, and progress over growing seasons. By registering a field, you create a quick way 60 | to consistently reference locations across all our APIs, and allow our modeling APIs 61 | to better operate and tune to the conditions and status of each specific field. A Planting 62 | is the record of a crop's season in a given field, and is where you tell the platform 63 | about what is planted there and when it was planted. 64 | 65 | Creating a planting will provide the aWhere platform the information needed to run models 66 | and more efficiently calculate agronomic values. You can also use these properties to record 67 | projections for the field, like yield or harvest date, to track the success of a field over 68 | the course of a growing season. Recording projected and actual yield and harvest date also helps 69 | aWhere tune the models for even greater accuracy. 70 | 71 | There can only be one active planting per field. You can create multiple plantings per field 72 | but only the most recent one will be considered the "current" one. Use this functionality to 73 | create historical records if you have them. 74 | 75 | When creating a planting, you must specify the crop and planting date. 76 | The crop must be an option from the Crops API; but there is also a short cut where if you don't 77 | know or want to use a specific crop ID, you can simply specify the crop name, such as "corn" or 78 | "wheat" and the the API will select the default for that category. 79 | 80 | This script creates a planting in a field location in the aWhere platform. By setting an Id you can retrieve the weather 81 | and agronomics for that location in all the other APIs. The planting ID corresponds to a planting within a field. 82 | } 83 | \examples{ 84 | \dontrun{create_planting(field_id='field_test',crop='corn', planting_date='2015-10-25', proj_yield_amount='100', 85 | proj_yield_units='Bushels', proj_harvest_date='2016-02-01', yield_amount='110', 86 | yield_units='Bushels', harvest_date='2016-02-01') 87 | } 88 | } 89 | \references{ 90 | https://docs.awhere.com/knowledge-base-docs/create-a-planting-in-a-field/ 91 | } 92 | -------------------------------------------------------------------------------- /man/create_shapewkt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create-shapewkt.R 3 | \name{create_shapewkt} 4 | \alias{create_shapewkt} 5 | \title{create_shapewkt} 6 | \usage{ 7 | create_shapewkt(longitude, latitude) 8 | } 9 | \arguments{ 10 | \item{longitude}{longitude coordinate for centroid} 11 | 12 | \item{latitude}{latitude coordinate for centroid} 13 | } 14 | \description{ 15 | \code{create_shapewkt} writes the WKT for a grid cell, based on a centroid coordinate 16 | } 17 | -------------------------------------------------------------------------------- /man/custom_fortify.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create-shapewkt.R 3 | \name{custom_fortify} 4 | \alias{custom_fortify} 5 | \title{custom_fortify} 6 | \usage{ 7 | custom_fortify(shapewkt) 8 | } 9 | \arguments{ 10 | \item{shapewkt}{a well-known text string for a grid cell polygon} 11 | } 12 | \description{ 13 | \code{custom_fortify} breaks up a shapewkt string into a numeric vector containing the points in the WKT 14 | } 15 | -------------------------------------------------------------------------------- /man/daily_observed_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weather-daily.R 3 | \name{daily_observed_area} 4 | \alias{daily_observed_area} 5 | \title{daily_observed_area} 6 | \usage{ 7 | daily_observed_area( 8 | polygon, 9 | day_start, 10 | day_end, 11 | propertiesToInclude = "", 12 | numcores = 2, 13 | bypassNumCallCheck = FALSE, 14 | returnSpatialData = FALSE, 15 | verbose = TRUE, 16 | maxTryCount = 3, 17 | keyToUse = awhereEnv75247$uid, 18 | secretToUse = awhereEnv75247$secret, 19 | tokenToUse = awhereEnv75247$token, 20 | apiAddressToUse = awhereEnv75247$apiAddress 21 | ) 22 | } 23 | \arguments{ 24 | \item{polygon}{either a data.frame with column names lat/lon, SpatialPolygons object, 25 | well-known text string, or extent from raster package. If the object contains 26 | multiple polygons, the union of them is used. Information from each individal 27 | polygon can be retrieved by returning spatial data and using 28 | the over function from the sp package} 29 | 30 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 31 | 32 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 33 | 34 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are temperatures, precipitation, solar, relativeHumidity, wind (optional)} 35 | 36 | \item{bypassNumCallCheck}{set to TRUE to avoid prompting the user to confirm that they want to begin making API calls} 37 | 38 | \item{returnSpatialData}{returns the data as a SpatialPixels object. Can be convered to raster with the command raster::stack 39 | NOTE: if multiple days worth of data is returned, it is necessary to subset to specific day for working with 40 | as spatial data (sp package: optional)} 41 | 42 | \item{verbose}{Set to TRUE tp print messages to console about state of parallization call. Typically only visible if run from console and not GUI} 43 | 44 | \item{maxTryCount}{maximum number of times a call is repeated if the the API returns an error. Random pause between each call} 45 | 46 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 47 | 48 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 49 | 50 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 51 | 52 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 53 | 54 | \item{numcores:}{number of cores to use in parallel loop. To check number of available cores: parallel::detectCores() 55 | If you receive an error regarding the speed you are making calls, reduce this number} 56 | } 57 | \value{ 58 | data.frame of requested data for dates requested 59 | } 60 | \description{ 61 | \code{daily_observed_area} pulls historical weather data from aWhere's API based on a data.frame of lat/lon, polygon or extent 62 | } 63 | \details{ 64 | This function returns weather data on Min/Max Temperature, Precipitation, 65 | Min/Max Humidity, Solar Radiation, and Maximum Wind Speed, 66 | Morning Max Windspeed, and Average Windspeed for the polygon passed to the function. 67 | Default units are returned by the API. The polygon should be either a SpatialPolygons object or 68 | a well-known text character string or an extent. 69 | 70 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 71 | and allows retrieval and integration of data across all different time ranges, long term normals, 72 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 73 | allowing you to customize the responses to return just the attributes you need. 74 | 75 | Understanding the recent and long-term daily weather is critical for making in-season decisions. 76 | This API opens the weather attributes that matter most to agriculture. 77 | 78 | Note about dates: The system does not adjust for any difference in dates between the location of the user 79 | and where data is being requested from. It is the responsibility of the user to ensure a valid 80 | date range is specified given any differences in timezone. These differences can have implications 81 | for whether a given date should be requested from the daily_observed functions or the forecast functions. 82 | Furthermore, because this function can take as input locations that may be in different timezones, it is 83 | the responsibility of the user to either ensure that the date range specified is valid for all relevant 84 | locations or to break the query into pieces. 85 | } 86 | \examples{ 87 | \dontrun{daily_observed_area(polygon = raster::getData('GADM', country = "Gambia", level = 0, download = T), 88 | ,day_start = '2018-04-28' 89 | ,day_end = '2018-05-01' 90 | ,numcores = 2)} 91 | 92 | } 93 | \references{ 94 | https://docs.awhere.com/knowledge-base-docs/daily-observed-weather-by-geolocation/ 95 | } 96 | -------------------------------------------------------------------------------- /man/daily_observed_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weather-daily.R 3 | \name{daily_observed_fields} 4 | \alias{daily_observed_fields} 5 | \title{daily_observed_fields} 6 | \usage{ 7 | daily_observed_fields( 8 | field_id, 9 | day_start, 10 | day_end, 11 | propertiesToInclude = "", 12 | keyToUse = awhereEnv75247$uid, 13 | secretToUse = awhereEnv75247$secret, 14 | tokenToUse = awhereEnv75247$token, 15 | apiAddressToUse = awhereEnv75247$apiAddress 16 | ) 17 | } 18 | \arguments{ 19 | \item{field_id}{the field_id associated with the location for which you want to pull data. 20 | Field IDs are created using the create_field function.(string)} 21 | 22 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD.} 23 | 24 | \item{day_end}{character string of the last day for which you want to retrieve data, in form: YYYY-MM-DD} 25 | 26 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are temperatures, precipitation, solar, relativeHumidity, wind (optional)} 27 | 28 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 29 | 30 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 31 | 32 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 33 | 34 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 35 | } 36 | \value{ 37 | data.frame of requested data for dates requested 38 | } 39 | \description{ 40 | \code{daily_observed_fields} pulls historical weather data from aWhere's API based on field id 41 | } 42 | \details{ 43 | This function returns weather data on Min/Max Temperature, Precipitation, 44 | Min/Max Humidity, Solar Radiation, and Maximum Wind Speed, 45 | Morning Max Windspeed, and Average Windspeed for the field id specified. 46 | Default units are returned by the API. 47 | 48 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 49 | and allows retrieval and integration of data across all different time ranges, long term normals, 50 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 51 | allowing you to customize the responses to return just the attributes you need. 52 | 53 | Understanding the recent and long-term daily weather is critical for making in-season decisions. 54 | This API opens the weather attributes that matter most to agriculture. 55 | 56 | Note about dates: The system does not adjust for any difference in dates between the location of the user 57 | and where data is being requested from. It is the responsibility of the user to ensure a valid 58 | date range is specified given any differences in timezone. These differences can have implications 59 | for whether a given date should be requested from the daily_observed functions or the forecast functions 60 | } 61 | \examples{ 62 | \dontrun{daily_observed_fields(field_id = 'field_test' 63 | ,day_start = '2018-10-28' 64 | ,day_end = '2018-12-01')} 65 | 66 | } 67 | \references{ 68 | https://docs.awhere.com/knowledge-base-docs/daily-observed-weather/ 69 | } 70 | -------------------------------------------------------------------------------- /man/daily_observed_latlng.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weather-daily.R 3 | \name{daily_observed_latlng} 4 | \alias{daily_observed_latlng} 5 | \title{daily_observed_latlng} 6 | \usage{ 7 | daily_observed_latlng( 8 | latitude, 9 | longitude, 10 | day_start, 11 | day_end, 12 | propertiesToInclude = "", 13 | keyToUse = awhereEnv75247$uid, 14 | secretToUse = awhereEnv75247$secret, 15 | tokenToUse = awhereEnv75247$token, 16 | apiAddressToUse = awhereEnv75247$apiAddress 17 | ) 18 | } 19 | \arguments{ 20 | \item{latitude}{the latitude of the requested location (double)} 21 | 22 | \item{longitude}{the longitude of the requested locations (double)} 23 | 24 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 25 | 26 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 27 | 28 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are temperatures, precipitation, solar, relativeHumidity, wind (optional)} 29 | 30 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 31 | 32 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 33 | 34 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 35 | 36 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 37 | } 38 | \value{ 39 | data.frame of requested data for dates requested 40 | } 41 | \description{ 42 | \code{daily_observed_latlng} pulls historical weather data from aWhere's API based on latitude & longitude 43 | } 44 | \details{ 45 | This function returns weather data on Min/Max Temperature, Precipitation, 46 | Min/Max Humidity, Solar Radiation, and Maximum Wind Speed, 47 | Morning Max Windspeed, and Average Windspeed for the location specified by latitude and longitude. 48 | Default units are returned by the API. Latitude and longitude must be in decimal degrees. 49 | 50 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 51 | and allows retrieval and integration of data across all different time ranges, long term normals, 52 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 53 | allowing you to customize the responses to return just the attributes you need. 54 | 55 | Understanding the recent and long-term daily weather is critical for making in-season decisions. 56 | This API opens the weather attributes that matter most to agriculture. 57 | 58 | Note about dates: The system does not adjust for any difference in dates between the location of the user 59 | and where data is being requested from. It is the responsibility of the user to ensure a valid 60 | date range is specified given any differences in timezone. These differences can have implications 61 | for whether a given date should be requested from the daily_observed functions or the forecast functions 62 | } 63 | \examples{ 64 | \dontrun{daily_observed_latlng(latitude = 39.8282 65 | ,longitude = -98.5795 66 | ,day_start = '2018-10-28' 67 | ,day_end = '2018-12-01')} 68 | } 69 | \references{ 70 | https://docs.awhere.com/knowledge-base-docs/daily-observed-weather-by-geolocation/ 71 | } 72 | -------------------------------------------------------------------------------- /man/delete_field.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/delete.R 3 | \name{delete_field} 4 | \alias{delete_field} 5 | \title{Delete Field} 6 | \usage{ 7 | delete_field( 8 | field_id, 9 | verbose = TRUE, 10 | keyToUse = awhereEnv75247$uid, 11 | secretToUse = awhereEnv75247$secret, 12 | tokenToUse = awhereEnv75247$token, 13 | apiAddressToUse = awhereEnv75247$apiAddress 14 | ) 15 | } 16 | \arguments{ 17 | \item{field_id}{an ID of your choosing (string)} 18 | 19 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 20 | 21 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 22 | 23 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 24 | 25 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 26 | } 27 | \value{ 28 | - a print text that informs if the query succeded or not 29 | } 30 | \description{ 31 | \code{delete_field} deletes a field_id for a location in the aWhere platform for which you can request weather 32 | } 33 | \details{ 34 | This script deletes a field location in the aWhere platform. 35 | This API is a "hard delete" - the field record should actually be deleted from the system. 36 | The delete should cascade, if there are associated records to a field, they are deleted as well. 37 | This applies when we design/implement "Plantings" API. 38 | } 39 | \examples{ 40 | \dontrun{delete_field("field123")} 41 | } 42 | \references{ 43 | https://docs.awhere.com/knowledge-base-docs/delete-a-field/ 44 | } 45 | -------------------------------------------------------------------------------- /man/delete_planting.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/delete.R 3 | \name{delete_planting} 4 | \alias{delete_planting} 5 | \title{Delete Planting} 6 | \usage{ 7 | delete_planting( 8 | field_id, 9 | planting_id, 10 | verbose = TRUE, 11 | keyToUse = awhereEnv75247$uid, 12 | secretToUse = awhereEnv75247$secret, 13 | tokenToUse = awhereEnv75247$token, 14 | apiAddressToUse = awhereEnv75247$apiAddress 15 | ) 16 | } 17 | \arguments{ 18 | \item{field_id}{the ID of the field for which you want to delete an associated planting (string)} 19 | 20 | \item{planting_id}{The planting Id that you want to delete. You can also use "current" to delete the most recent planting (string)} 21 | 22 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 23 | 24 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 25 | 26 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 27 | 28 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 29 | } 30 | \value{ 31 | - a print text that informs if the query succeded or not 32 | } 33 | \description{ 34 | \code{delete_planting} deletes a planting associated with a specific field_id in the aWhere platform 35 | } 36 | \details{ 37 | The aWhere API only references the most recent planting when calculating agronomics and running 38 | models, but if you want to keep your planting records clean for reporting and historical tracking 39 | purposes you can delete errant or incorrect plantings. 40 | } 41 | \examples{ 42 | \dontrun{delete_planting("field123",'133972')} 43 | } 44 | \references{ 45 | https://docs.awhere.com/knowledge-base-docs/delete-a-planting/ 46 | } 47 | -------------------------------------------------------------------------------- /man/forecasts_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/forecasts.R 3 | \name{forecasts_area} 4 | \alias{forecasts_area} 5 | \title{forecasts_area} 6 | \usage{ 7 | forecasts_area( 8 | polygon, 9 | day_start = as.character(Sys.Date()), 10 | day_end = "", 11 | block_size = 1, 12 | useLocalTime = TRUE, 13 | numcores = 2, 14 | bypassNumCallCheck = FALSE, 15 | returnSpatialData = FALSE, 16 | verbose = TRUE, 17 | maxTryCount = 3, 18 | returnOnlySoilVars = FALSE, 19 | keyToUse = awhereEnv75247$uid, 20 | secretToUse = awhereEnv75247$secret, 21 | tokenToUse = awhereEnv75247$token, 22 | apiAddressToUse = awhereEnv75247$apiAddress 23 | ) 24 | } 25 | \arguments{ 26 | \item{polygon}{either a data.frame with column names lat/lon, SpatialPolygons object, 27 | well-known text string, or extent from raster package. If the object contains 28 | multiple polygons, the union of them is used. Information from each individal 29 | polygon can be retrieved by returning spatial data and using 30 | the over function from the sp package} 31 | 32 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 33 | 34 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 35 | 36 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 37 | Defaults to a 1 hour block. This value must divide evenly into 24. (integer - optional)} 38 | 39 | \item{useLocalTime}{whether the data specified is the date specified at the location where data is 40 | being requested from or at UTC = 0. Default is TRUE} 41 | 42 | \item{numcores}{number of cores to use in parallel loop. To check number of available cores: parallel::detectCores() 43 | If you receive an error regarding the speed you are making calls, reduce this number} 44 | 45 | \item{bypassNumCallCheck}{set to TRUE to avoid prompting the user to confirm that they want to begin making API calls} 46 | 47 | \item{returnSpatialData}{returns the data as a SpatialPixels object. Can be convered to raster with the command raster::stack 48 | NOTE: if multiple days worth of data is returned, it is necessary to subset to specific day for working with 49 | as spatial data (sp package: optional)} 50 | 51 | \item{verbose}{Set to TRUE tp print messages to console about state of parallization call. Typically only visible if run from console and not GUI} 52 | 53 | \item{maxTryCount}{maximum number of times a call is repeated if the the API returns an error. Random pause between each call} 54 | 55 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 56 | 57 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 58 | 59 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 60 | 61 | \item{apiAddressToUse:}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 62 | } 63 | \value{ 64 | data.frame of requested data for dates requested 65 | } 66 | \description{ 67 | \code{forecasts_area} pulls forecasted weather data from aWhere's API based on a data.frame of lat/lon, polygon or extent 68 | } 69 | \details{ 70 | This function returns today's forecast plus the forecast for up to 15 more days. Forecasts are available 71 | in many sizes of hourly blocks, from hourly to daily. The data this function returns is 72 | Min/Max Temperature, Precipitation Amount, Chance of Precipitation, 73 | Max Humidity, Relative Humidity, Solar Radiation, Average Wind Speed, Max Windspeed, Percentage 74 | of Sky Covered by Clouds, and Percentage of Clear Sky for the location specified by latitude and longitude. 75 | Default units are returned by the API. Latitude and longitude must be in decimal degrees. 76 | 77 | Note that when block_size = 1 the fields min/max relative humidity and min/max wind will be NA 78 | 79 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 80 | and allows retrieval and integration of data across all different time ranges long term normals, 81 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 82 | allowing you to customize the responses to return just the attributes you need. 83 | 84 | Note about dates: The system does not adjust for any difference in dates between the location of the user 85 | and where data is being requested from. It is the responsibility of the user to ensure a valid 86 | date range is specified given any differences in timezone. These differences can have implications 87 | for whether a given date should be requested from the daily_observed functions or the forecast functions 88 | } 89 | \examples{ 90 | \dontrun{forecasts_area(polygon = raster::getData('GADM', country = "Gambia", level = 0, download = T), 91 | ,day_start = as.character(Sys.Date()) 92 | ,day_end = as.character(Sys.Date() + 5) 93 | ,block_size = 12) 94 | ,numcores = 2)} 95 | 96 | } 97 | \references{ 98 | https://docs.awhere.com/knowledge-base-docs/forecast-weather-by-geolocation/ 99 | } 100 | -------------------------------------------------------------------------------- /man/forecasts_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/forecasts.R 3 | \name{forecasts_fields} 4 | \alias{forecasts_fields} 5 | \title{forecasts_fields} 6 | \usage{ 7 | forecasts_fields( 8 | field_id, 9 | day_start = as.character(Sys.Date()), 10 | day_end = "", 11 | block_size = 1, 12 | useLocalTime = TRUE, 13 | returnOnlySoilVars = FALSE, 14 | keyToUse = awhereEnv75247$uid, 15 | secretToUse = awhereEnv75247$secret, 16 | tokenToUse = awhereEnv75247$token, 17 | apiAddressToUse = awhereEnv75247$apiAddress 18 | ) 19 | } 20 | \arguments{ 21 | \item{field_id}{the field_id associated with the location for which you want to pull data. 22 | Field IDs are created using the create_field function. (string)} 23 | 24 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD 25 | Defaults to system date if left blank. (optional)} 26 | 27 | \item{day_end}{character string of the last day for which you want to retrieve data, in form: YYYY-MM-DD 28 | Returns all available forecast if left blank. (optional)} 29 | 30 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 31 | Defaults to a 1 hour block. This value must divide evenly into 24. (integer - optional)} 32 | 33 | \item{useLocalTime}{whether the data specified is the date specified at the location where data is 34 | being requested from or at UTC = 0. Default is TRUE} 35 | 36 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 37 | 38 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 39 | 40 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 41 | 42 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 43 | } 44 | \value{ 45 | data.frame of requested data for dates requested 46 | } 47 | \description{ 48 | \code{forecasts_fields} pulls forecast weather data from aWhere's API based on field id 49 | } 50 | \details{ 51 | This function returns today's forecast plus the forecast for up to 7 more days. Forecasts are available 52 | in many sizes of time blocks, from hourly to daily. The data this function returns is 53 | Min/Max Temperature, Precipitation Amount, Chance of Precipitation, 54 | Max Humidity, Relative Humidity, Solar Radiation, Average Wind Speed, Max Windspeed, Percentage 55 | of Sky Covered by Clouds, and Percentage of Clear Sky for the field id specified. 56 | Default units are returned by the API. 57 | 58 | Note that when block_size = 1 the fields min/max relative humidity and min/max wind will be NA 59 | 60 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 61 | and allows retrieval and integration of data across all different time ranges long term normals, 62 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 63 | allowing you to customize the responses to return just the attributes you need. 64 | 65 | Note about dates: The system does not adjust for any difference in dates between the location of the user 66 | and where data is being requested from. It is the responsibility of the user to ensure a valid 67 | date range is specified given any differences in timezone. These differences can have implications 68 | for whether a given date should be requested from the daily_observed functions or the forecast functions 69 | } 70 | \examples{ 71 | \dontrun{forecasts_fields(field_id = 'field_test' 72 | ,day_start = as.character(Sys.Date()) 73 | , block_size = 12) 74 | forecasts_fields('field_test' 75 | ,day_start = as.character(Sys.Date()) 76 | ,day_end = as.character(Sys.Date() + 5))} 77 | } 78 | \references{ 79 | https://docs.awhere.com/knowledge-base-docs/forecast-weather/ 80 | } 81 | -------------------------------------------------------------------------------- /man/forecasts_latlng.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/forecasts.R 3 | \name{forecasts_latlng} 4 | \alias{forecasts_latlng} 5 | \title{forecasts_latlng} 6 | \usage{ 7 | forecasts_latlng( 8 | latitude, 9 | longitude, 10 | day_start = as.character(Sys.Date()), 11 | day_end = "", 12 | block_size = 1, 13 | useLocalTime = TRUE, 14 | returnOnlySoilVars = FALSE, 15 | keyToUse = awhereEnv75247$uid, 16 | secretToUse = awhereEnv75247$secret, 17 | tokenToUse = awhereEnv75247$token, 18 | apiAddressToUse = awhereEnv75247$apiAddress 19 | ) 20 | } 21 | \arguments{ 22 | \item{latitude}{the latitude of the requested location (double)} 23 | 24 | \item{longitude}{the longitude of the requested locations (double)} 25 | 26 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD 27 | Defaults to system date if left blank. (optional)} 28 | 29 | \item{day_end}{character string of the last day for which you want to retrieve data, in form: YYYY-MM-DD 30 | Returns all available forecast if left blank. (optional)} 31 | 32 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 33 | Defaults to a 1 hour block. This value must divide evenly into 24. (integer - optional)} 34 | 35 | \item{useLocalTime}{whether the data specified is the date specified at the location where data is 36 | being requested from or at UTC = 0. Default is TRUE} 37 | 38 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 39 | 40 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 41 | 42 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 43 | 44 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 45 | } 46 | \value{ 47 | data.frame of requested data for dates requested 48 | } 49 | \description{ 50 | \code{forecasts_latlng} pulls historical weather data from aWhere's API based on latitude & longitude 51 | } 52 | \details{ 53 | This function returns today's forecast plus the forecast for up to 7 more days. Forecasts are available 54 | in many sizes of hourly blocks, from hourly to daily. The data this function returns is 55 | Min/Max Temperature, Precipitation Amount, Chance of Precipitation, 56 | Max Humidity, Relative Humidity, Solar Radiation, Average Wind Speed, Max Windspeed, Percentage 57 | of Sky Covered by Clouds, and Percentage of Clear Sky for the location specified by latitude and longitude. 58 | Default units are returned by the API. Latitude and longitude must be in decimal degrees. 59 | 60 | Note that when block_size = 1 the fields min/max relative humidity and min/max wind will be NA 61 | 62 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 63 | and allows retrieval and integration of data across all different time ranges long term normals, 64 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 65 | allowing you to customize the responses to return just the attributes you need. 66 | 67 | Note about dates: The system does not adjust for any difference in dates between the location of the user 68 | and where data is being requested from. It is the responsibility of the user to ensure a valid 69 | date range is specified given any differences in timezone. These differences can have implications 70 | for whether a given date should be requested from the daily_observed functions or the forecast functions 71 | } 72 | \examples{ 73 | \dontrun{forecasts_latlng(latitude = 39.8282 74 | ,longitude = -98.5795 75 | ,day_start = as.character(Sys.Date()) 76 | ,day_end = as.character(Sys.Date() + 5) 77 | ,block_size = 12) 78 | forecasts_latlng(latitude = 19.328489 79 | ,longitude = -99.145681 80 | ,day_start = as.character(Sys.Date()) 81 | ,block_size = 4)} 82 | } 83 | \references{ 84 | https://docs.awhere.com/knowledge-base-docs/forecast-weather-by-geolocation/ 85 | } 86 | -------------------------------------------------------------------------------- /man/getGridX.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grid-functions.R 3 | \name{getGridX} 4 | \alias{getGridX} 5 | \title{Get aWhere GridX from longitude coordinate(s)} 6 | \usage{ 7 | getGridX(longitude) 8 | } 9 | \arguments{ 10 | \item{longitude}{one more more longitude coordinates} 11 | } 12 | \value{ 13 | A vector of GridX values 14 | } 15 | \description{ 16 | Get aWhere GridX from longitude coordinate(s) 17 | } 18 | \examples{ 19 | getGridX(-90) 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/getGridY.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grid-functions.R 3 | \name{getGridY} 4 | \alias{getGridY} 5 | \title{Get aWhere GridY from latitude coordinate(s)} 6 | \usage{ 7 | getGridY(latitude) 8 | } 9 | \arguments{ 10 | \item{latitude}{one or more latitudes coordinates} 11 | } 12 | \value{ 13 | A vector of GridY values 14 | } 15 | \description{ 16 | Get aWhere GridY from latitude coordinate(s) 17 | } 18 | \examples{ 19 | getGridY(-90) 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/get_crops.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/agronomic-crops.R 3 | \name{get_crops} 4 | \alias{get_crops} 5 | \title{Get Crops} 6 | \usage{ 7 | get_crops( 8 | crop_id = "", 9 | keyToUse = awhereEnv75247$uid, 10 | secretToUse = awhereEnv75247$secret, 11 | tokenToUse = awhereEnv75247$token, 12 | apiAddressToUse = awhereEnv75247$apiAddress 13 | ) 14 | } 15 | \arguments{ 16 | \item{crop_id}{Either a crop id to retrieve information for that specific crop 17 | or an empty string to retrieve information on all crops associated 18 | with the user's aWhere API account (string - optional)} 19 | 20 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 21 | 22 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 23 | 24 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 25 | 26 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 27 | } 28 | \value{ 29 | - data.frame containing information about requested crop(s) 30 | } 31 | \description{ 32 | \code{get_crops} Calls Crops endpoint of API 33 | } 34 | \details{ 35 | Models are designed for specific crops, and often specific types or varieties of crops. 36 | This API provides the list of available crops. When creating a planting record, you're encouraged 37 | to specify the crop that is planted in the field using these records. 38 | 39 | Within each category of crop (organized by name), there is a default crop. When creating a planting, 40 | you may not know or care about the specific variety, and can simply specify the crop name as 41 | what is planted there. When you do this, the system will use the default crop for that category. 42 | You'll know which crop record is the default by referencing the isDefaultForCrop property, described below. 43 | } 44 | \examples{ 45 | \dontrun{get_crops('barley-generic') 46 | get_crops() 47 | } 48 | } 49 | \references{ 50 | https://developer.awhere.com/api/reference/crops 51 | } 52 | -------------------------------------------------------------------------------- /man/get_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get.R 3 | \name{get_fields} 4 | \alias{get_fields} 5 | \title{Get Fields} 6 | \usage{ 7 | get_fields( 8 | field_id = "", 9 | offset = "", 10 | limit = 10, 11 | requestAllFields = TRUE, 12 | keyToUse = awhereEnv75247$uid, 13 | secretToUse = awhereEnv75247$secret, 14 | tokenToUse = awhereEnv75247$token, 15 | apiAddressToUse = awhereEnv75247$apiAddress 16 | ) 17 | } 18 | \arguments{ 19 | \item{field_id}{Either a field id to retrieve information for that specific field 20 | or an empty string to retrieve information on all fields associated 21 | with the user's aWhere API account (string - optional)} 22 | 23 | \item{offset}{The number of objects to skip before returning objects. Used in conjunction with offset to paginate. (optional)} 24 | 25 | \item{limit}{The number of results to include on each of page of listed fields. Used in conjunction with offset to paginate. (optional)} 26 | 27 | \item{requestAllFields}{Causes function to execute logic to return all of a users fields using the minimum number of API calls 28 | based on the limit parameter. If used, offset must be set to default value (optional)} 29 | 30 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 31 | 32 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 33 | 34 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 35 | 36 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 37 | } 38 | \value{ 39 | - data.frame containing information about requested field(s) 40 | } 41 | \description{ 42 | \code{get_fields} calls Get Field Locations Endpoint of API 43 | } 44 | \details{ 45 | Fields are how you manage the locations for which you're tracking weather, agronomics, 46 | models, and progress over growing seasons in the aWhere API. By registering a field, you create a quick way 47 | to consistently reference locations across all of our APIs, and allow our modeling APIs 48 | to better operate and tune to the conditions and status of each specific field. 49 | 50 | Before using aWhere's APIs you'll need to register the field locations. 51 | This is a one-time step. Every field has an ID that you define, plus a latitude and longitude. 52 | Fields are universal across all of our APIs, and as you provide information about a field, some APIs 53 | (such as agronomics and models) can leverage that detail internally to more easily and seamlessly 54 | calculate information for you. 55 | } 56 | \examples{ 57 | \dontrun{get_fields('field_test') 58 | get_fields() 59 | } 60 | } 61 | \references{ 62 | https://docs.awhere.com/knowledge-base-docs/get-field-locations/ 63 | } 64 | -------------------------------------------------------------------------------- /man/get_model_details.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/models.R 3 | \name{get_model_details} 4 | \alias{get_model_details} 5 | \title{Get Model Details} 6 | \usage{ 7 | get_model_details( 8 | model_id, 9 | keyToUse = awhereEnv75247$uid, 10 | secretToUse = awhereEnv75247$secret, 11 | tokenToUse = awhereEnv75247$token, 12 | apiAddressToUse = awhereEnv75247$apiAddress 13 | ) 14 | } 15 | \arguments{ 16 | \item{model_id}{A model id to retrieve details for that specific model} 17 | 18 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 19 | 20 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 21 | 22 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 23 | 24 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 25 | } 26 | \value{ 27 | - data.frame containing details about requested model 28 | } 29 | \description{ 30 | \code{get_model_details} Calls Model Details endpoint of API 31 | } 32 | \details{ 33 | Every model has its own parameters and criteria it uses to calculate the results. 34 | This API will return those details; for the growth stage models currently available 35 | this API returns information about the crop stages that the model may return. 36 | } 37 | \examples{ 38 | \dontrun{get_model_details('BarleyGenericMSU') 39 | } 40 | } 41 | \references{ 42 | https://developer.awhere.com/api/reference/models/details 43 | } 44 | -------------------------------------------------------------------------------- /man/get_model_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/models.R 3 | \name{get_model_results} 4 | \alias{get_model_results} 5 | \title{Get Model Results} 6 | \usage{ 7 | get_model_results( 8 | field_id, 9 | model_id, 10 | keyToUse = awhereEnv75247$uid, 11 | secretToUse = awhereEnv75247$secret, 12 | tokenToUse = awhereEnv75247$token, 13 | apiAddressToUse = awhereEnv75247$apiAddress 14 | ) 15 | } 16 | \arguments{ 17 | \item{model_id}{A model id to retrieve details for that specific model} 18 | 19 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 20 | 21 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 22 | 23 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 24 | 25 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 26 | } 27 | \value{ 28 | - 3 element named list containing information on previous growth stages 29 | that have completed (previousStages), the current growth stage (currentStage) 30 | and the next growth stage(nextStage) 31 | } 32 | \description{ 33 | \code{get_model_details} Calls Model Results endpoint of API 34 | } 35 | \details{ 36 | Running a model is as simple as requesting its current results. The aWhere platform 37 | will use the information previously provided about a field and planting to generate 38 | the relevant, field-specific information. For growth stage models, the results are 39 | the current stage as well as information about the most recent and next stage. 40 | 41 | Important: Models require the use of the Fields and Plantings APIs to store important 42 | information about a field and crop. When a Field is specified for this API, it will 43 | select the most recently created Planting record to retrieve the crop and planting date. 44 | } 45 | \examples{ 46 | \dontrun{get_model_results('Field1', 'BarleyGenericMSU') 47 | } 48 | } 49 | \references{ 50 | https://developer.awhere.com/api/reference/models/results 51 | } 52 | -------------------------------------------------------------------------------- /man/get_models.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/models.R 3 | \name{get_models} 4 | \alias{get_models} 5 | \title{Get Models} 6 | \usage{ 7 | get_models( 8 | model_id = "", 9 | keyToUse = awhereEnv75247$uid, 10 | secretToUse = awhereEnv75247$secret, 11 | tokenToUse = awhereEnv75247$token, 12 | apiAddressToUse = awhereEnv75247$apiAddress 13 | ) 14 | } 15 | \arguments{ 16 | \item{model_id}{Either a model id to retrieve information for that specific model 17 | or an empty string to retrieve information on all model associated 18 | with the user's aWhere API account (string - optional)} 19 | 20 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 21 | 22 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 23 | 24 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 25 | 26 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 27 | } 28 | \value{ 29 | - data.frame containing information about requested model(s) 30 | } 31 | \description{ 32 | \code{get_models} Calls Models endpoint of API 33 | } 34 | \details{ 35 | This API provides the list of available models in the aWhere platform. 36 | Today a variety of crop growth stage models are generally available, with many more on the way. 37 | 38 | Each models applies to particular crops from the Crops API, and after an initial 39 | review of the available models, you can often save the model ID and simply reference the details and results as needed. 40 | } 41 | \examples{ 42 | \dontrun{get_models('BarleyGenericMSU') 43 | get_models() 44 | } 45 | } 46 | \references{ 47 | https://developer.awhere.com/api/reference/models/get-models 48 | } 49 | -------------------------------------------------------------------------------- /man/get_planting.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get.R 3 | \name{get_planting} 4 | \alias{get_planting} 5 | \title{Get Planting} 6 | \usage{ 7 | get_planting( 8 | field_id = "", 9 | planting_id = "", 10 | current = FALSE, 11 | offset = "", 12 | limit = 10, 13 | requestAllPlantings = TRUE, 14 | keyToUse = awhereEnv75247$uid, 15 | secretToUse = awhereEnv75247$secret, 16 | tokenToUse = awhereEnv75247$token, 17 | apiAddressToUse = awhereEnv75247$apiAddress 18 | ) 19 | } 20 | \arguments{ 21 | \item{field_id}{a field ID to look within (string - optional)} 22 | 23 | \item{planting_id}{a planting ID to look for (string - optional)} 24 | 25 | \item{current}{whether to just get current plantings(T) or include historical plantings(F). 26 | To get most recent planting record for a field, set current to TRUE and do not pass in a planting_id (boolean - optional)} 27 | 28 | \item{offset}{The number of objects to skip before returning objects. Used in conjunction with offset to paginate. (optional)} 29 | 30 | \item{limit}{The number of results to include on each of page of listed fields. Used in conjunction with offset to paginate. (optional)} 31 | 32 | \item{requestAllPlantings}{Causes function to execute logic to return all of a users plantins using the minimum number of API calls 33 | based on the limit parameter and the value of current. If used, offset must be set to default value (optional)} 34 | 35 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 36 | 37 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 38 | 39 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 40 | 41 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 42 | } 43 | \value{ 44 | - data.frame containing information about requested field(s) 45 | } 46 | \description{ 47 | \code{get_planting} Gets a planting or list of plantings in the aWhere platform for which you can request weather 48 | } 49 | \details{ 50 | Fields are how you manage the locations for which you're tracking weather, agronomics, 51 | models, and progress over growing seasons. By registering a field, you create a quick way 52 | to consistently reference locations across all our APIs, and allow our modeling APIs 53 | to better operate and tune to the conditions and status of each specific field. A Planting 54 | is the record of a crop's season in a given field, and is where you tell the platform 55 | about what is planted there and when it was planted. 56 | 57 | Plantings are the way to manage crop and field activity in the aWhere API. Use this 58 | API to record the type of crop, planting date, projections, and actuals to get the 59 | most out of our more advanced APIs. Over time, this API also enables historical metrics 60 | for any given field in the platform. In this function by setting an Id you can retrieve the weather 61 | and agronomics for that location in all the other APIs. 62 | } 63 | \examples{ 64 | \dontrun{get_planting(field_id='field_test') 65 | get_planting(field_id = 'field_test', planting_id = '156035') 66 | get_planting('field_test', current = T) 67 | get_planting(field_id='field_test', offset = '0', limit = '5')} 68 | } 69 | \references{ 70 | https://docs.awhere.com/knowledge-base-docs/get-plantings/ 71 | } 72 | -------------------------------------------------------------------------------- /man/get_token.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get-token.R 3 | \name{get_token} 4 | \alias{get_token} 5 | \title{Get Access Token} 6 | \usage{ 7 | get_token(uid, secret, use_environment = TRUE, apiAddress = "api.awhere.com") 8 | } 9 | \arguments{ 10 | \item{uid}{Consumer key associated with the user's aWhere API account} 11 | 12 | \item{secret}{Consumer secret associated the user's aWhere API account} 13 | 14 | \item{apiAddress}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 15 | 16 | \item{use_enviroment}{Optional logical value, determines whether API access 17 | token will be saved in a local locked environment in addition to being returned 18 | by the function. Defaults to \code{TRUE} to avoid breaking existing code.} 19 | } 20 | \value{ 21 | List with three elements:#' 22 | error: logical indicating whether there was an error 23 | error_message: \code{NULL} if error is \code{FALSE}, a character error message otherwise 24 | token: aWhere API access token value 25 | } 26 | \description{ 27 | \code{get_token} gets Access Token for V2 aWhere API 28 | } 29 | \details{ 30 | This script provides an aWhere access token for the current session of the API. Information for the key and secret in this 31 | function can be found on a user's account at developer.awhere.com, under the apps. 32 | } 33 | \examples{ 34 | \dontrun{get_token("uid", "secret")} 35 | \dontrun{token_response <- get_token('uid', 'secret', use_environment = FALSE)} 36 | } 37 | -------------------------------------------------------------------------------- /man/load_credentials.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get-token.R 3 | \name{load_credentials} 4 | \alias{load_credentials} 5 | \title{Load Credentials.} 6 | \usage{ 7 | load_credentials(path_to_credentials, apiAddress = "api.awhere.com") 8 | } 9 | \arguments{ 10 | \item{path_to_credentials}{absolute or relative path to the text file} 11 | 12 | \item{apiAddress}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 13 | } 14 | \value{ 15 | vector with uid and secret in positions 1, 2 16 | } 17 | \description{ 18 | \code{load_credentials} loads credential information from text file to use in 19 | calls to aWhere API 20 | } 21 | \details{ 22 | This script creates loads a valid aWhere API token into memory to be used in making API calls. 23 | Instead of typing in the password and username manually and calling the get_token(uid,secret) function, 24 | you can store this information in a txt file in some arbitrary directory. 25 | The first line of the text file should be the provided uid/username, the 26 | second line should be the associated secret. A blank 3rd line should be inserted to prevent 27 | an error from being returned by R 28 | } 29 | \examples{ 30 | \dontrun{load_credentials("C:/aWhere/credentials/credentials.txt")} 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/plan_APICalls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plan_APICalls.R 3 | \name{plan_APICalls} 4 | \alias{plan_APICalls} 5 | \title{Plan Logic of API Calls} 6 | \usage{ 7 | plan_APICalls(day_start, day_end, numObsReturned, includesLeapYear = TRUE) 8 | } 9 | \value{ 10 | list(allDates,loops) 11 | } 12 | \description{ 13 | \code{plan_APICalls} Calculate logic of API calls 14 | } 15 | \details{ 16 | Calculate logic of API calls based on the number of days that can be returned 17 | with each call as well as start and end dates 18 | } 19 | -------------------------------------------------------------------------------- /man/recalculateAccumulations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cleanupAPIReturns.R 3 | \name{recalculateAccumulations} 4 | \alias{recalculateAccumulations} 5 | \title{Removes unnecessary columns from API Return} 6 | \usage{ 7 | recalculateAccumulations(dataList) 8 | } 9 | \arguments{ 10 | \item{dataList}{list of data.table to have accumulations corrected} 11 | } 12 | \description{ 13 | \code{recalculateAccumulations} manually recalculate accumulations over API calls 14 | } 15 | -------------------------------------------------------------------------------- /man/removeUnnecessaryColumns.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cleanupAPIReturns.R 3 | \name{removeUnnecessaryColumns} 4 | \alias{removeUnnecessaryColumns} 5 | \title{Removes unnecessary columns from API Return} 6 | \usage{ 7 | removeUnnecessaryColumns(data, returnOnlySoilVars = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{data.table to have columns removed from} 11 | } 12 | \description{ 13 | \code{removeUnnecessaryColumns} Removes unnecessary columns from API Return 14 | } 15 | -------------------------------------------------------------------------------- /man/soils_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/soils.R 3 | \name{soils_area} 4 | \alias{soils_area} 5 | \title{soils_area} 6 | \usage{ 7 | soils_area( 8 | polygon, 9 | day_start = as.character(Sys.Date()), 10 | day_end = "", 11 | block_size = 1, 12 | useLocalTime = TRUE, 13 | numcores = 2, 14 | bypassNumCallCheck = FALSE, 15 | returnSpatialData = FALSE, 16 | verbose = TRUE, 17 | keyToUse = awhereEnv75247$uid, 18 | secretToUse = awhereEnv75247$secret, 19 | tokenToUse = awhereEnv75247$token, 20 | apiAddressToUse = awhereEnv75247$apiAddress 21 | ) 22 | } 23 | \arguments{ 24 | \item{polygon}{either a data.frame with column names lat/lon, SpatialPolygons object, 25 | well-known text string, or extent from raster package. If the object contains 26 | multiple polygons, the union of them is used. Information from each individal 27 | polygon can be retrieved by returning spatial data and using 28 | the over function from the sp package} 29 | 30 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD} 31 | 32 | \item{day_end}{character string of the last day for which you want to retrieve data, in the form: YYYY-MM-DD} 33 | 34 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 35 | Defaults to a 1 hour block. This value must divide evenly into 24. (integer - optional)} 36 | 37 | \item{useLocalTime}{whether the data specified is the date specified at the location where data is 38 | being requested from or at UTC = 0. Default is TRUE} 39 | 40 | \item{numcores}{number of cores to use in parallel loop. To check number of available cores: parallel::detectCores() 41 | If you receive an error regarding the speed you are making calls, reduce this number} 42 | 43 | \item{bypassNumCallCheck}{set to TRUE to avoid prompting the user to confirm that they want to begin making API calls} 44 | 45 | \item{returnSpatialData}{returns the data as a SpatialPixels object. Can be convered to raster with the command raster::stack 46 | NOTE: if multiple days worth of data is returned, it is necessary to subset to specific day for working with 47 | as spatial data (sp package: optional)} 48 | 49 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 50 | 51 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 52 | 53 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 54 | 55 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 56 | } 57 | \value{ 58 | data.frame of requested data for dates requested 59 | } 60 | \description{ 61 | \code{soils_area} pulls forecasted soil temp/moisutre data from aWhere's API based on a data.frame of lat/lon, polygon or extent 62 | } 63 | \details{ 64 | This function returns today's soil forecast plus the forecast for up to 15 more days. Forecasts are available 65 | in many sizes of hourly blocks, from hourly to daily. The data this function returns is 66 | the soil's temperature and volumetric moisture content for the location specified by spatial information for multiple depths 67 | Default units are returned by the API. Latitude and longitude must be in decimal degrees. 68 | 69 | Note that when block_size = 1 the fields min/max will be NA 70 | 71 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 72 | and allows retrieval and integration of data across all different time ranges long term normals, 73 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 74 | allowing you to customize the responses to return just the attributes you need. 75 | 76 | Note about dates: The system does not adjust for any difference in dates between the location of the user 77 | and where data is being requested from. It is the responsibility of the user to ensure a valid 78 | date range is specified given any differences in timezone. These differences can have implications 79 | for whether a given date should be requested from the daily_observed functions or the forecast functions 80 | } 81 | \examples{ 82 | \dontrun{soils_area(polygon = raster::getData('GADM', country = "Gambia", level = 0, download = T), 83 | ,day_start = as.character(Sys.Date()) 84 | ,day_end = as.character(Sys.Date() + 5) 85 | ,block_size = 12) 86 | ,numcores = 2)} 87 | 88 | } 89 | \references{ 90 | https://docs.awhere.com/knowledge-base-docs/forecast-weather-by-geolocation/ 91 | } 92 | -------------------------------------------------------------------------------- /man/soils_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/soils.R 3 | \name{soils_fields} 4 | \alias{soils_fields} 5 | \title{soils_fields} 6 | \usage{ 7 | soils_fields( 8 | field_id, 9 | day_start = as.character(Sys.Date()), 10 | day_end = "", 11 | block_size = 1, 12 | useLocalTime = TRUE, 13 | keyToUse = awhereEnv75247$uid, 14 | secretToUse = awhereEnv75247$secret, 15 | tokenToUse = awhereEnv75247$token, 16 | apiAddressToUse = awhereEnv75247$apiAddress 17 | ) 18 | } 19 | \arguments{ 20 | \item{field_id}{the field_id associated with the location for which you want to pull data. 21 | Field IDs are created using the create_field function. (string)} 22 | 23 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD 24 | Defaults to system date if left blank. (optional)} 25 | 26 | \item{day_end}{character string of the last day for which you want to retrieve data, in form: YYYY-MM-DD 27 | Returns all available forecast if left blank. (optional)} 28 | 29 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 30 | Defaults to a 1 hour block. This value must divide evenly into 24. (integer - optional)} 31 | 32 | \item{useLocalTime}{whether the data specified is the date specified at the location where data is 33 | being requested from or at UTC = 0. Default is TRUE} 34 | 35 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 36 | 37 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 38 | 39 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 40 | 41 | \item{-}{apiAddressToUse: Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 42 | } 43 | \value{ 44 | data.frame of requested data for dates requested 45 | } 46 | \description{ 47 | \code{soils_fields} pulls forecasted soil temp/moisutre data from aWhere's API based on field id 48 | } 49 | \details{ 50 | This function returns today's soil forecast plus the forecast for up to 15 more days. Forecasts are available 51 | in many sizes of hourly blocks, from hourly to daily. The data this function returns is 52 | the soil's temperature and volumetric moisture content for the location specified by field id for multiple depths 53 | Default units are returned by the API. Latitude and longitude must be in decimal degrees. 54 | 55 | Note that when block_size = 1 the fields min/max will be NA 56 | 57 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 58 | and allows retrieval and integration of data across all different time ranges long term normals, 59 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 60 | allowing you to customize the responses to return just the attributes you need. 61 | 62 | Note about dates: The system does not adjust for any difference in dates between the location of the user 63 | and where data is being requested from. It is the responsibility of the user to ensure a valid 64 | date range is specified given any differences in timezone. These differences can have implications 65 | for whether a given date should be requested from the daily_observed functions or the forecast functions 66 | } 67 | \examples{ 68 | \dontrun{soils_fields(field_id = 'field_test' 69 | ,day_start = as.character(Sys.Date()) 70 | , block_size = 12) 71 | soils_fields('field_test' 72 | ,day_start = as.character(Sys.Date()) 73 | ,day_end = as.character(Sys.Date() + 5))} 74 | } 75 | \references{ 76 | https://docs.awhere.com/knowledge-base-docs/forecast-weather/ 77 | } 78 | -------------------------------------------------------------------------------- /man/soils_latlng.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/soils.R 3 | \name{soils_latlng} 4 | \alias{soils_latlng} 5 | \title{soils_latlng} 6 | \usage{ 7 | soils_latlng( 8 | latitude, 9 | longitude, 10 | day_start = as.character(Sys.Date()), 11 | day_end = "", 12 | block_size = 1, 13 | useLocalTime = TRUE, 14 | keyToUse = awhereEnv75247$uid, 15 | secretToUse = awhereEnv75247$secret, 16 | tokenToUse = awhereEnv75247$token, 17 | apiAddressToUse = awhereEnv75247$apiAddress 18 | ) 19 | } 20 | \arguments{ 21 | \item{latitude}{the latitude of the requested location (double)} 22 | 23 | \item{longitude}{the longitude of the requested locations (double)} 24 | 25 | \item{day_start}{character string of the first day for which you want to retrieve data, in the form: YYYY-MM-DD 26 | Defaults to system date if left blank. (optional)} 27 | 28 | \item{day_end}{character string of the last day for which you want to retrieve data, in form: YYYY-MM-DD 29 | Returns all available forecast if left blank. (optional)} 30 | 31 | \item{block_size}{Integer value that corresponds to the number of hours to include in each time block. 32 | Defaults to a 1 hour block. This value must divide evenly into 24. (integer - optional)} 33 | 34 | \item{useLocalTime}{whether the data specified is the date specified at the location where data is 35 | being requested from or at UTC = 0. Default is TRUE} 36 | 37 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 38 | 39 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 40 | 41 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 42 | 43 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 44 | } 45 | \value{ 46 | data.frame of requested data for dates requested 47 | } 48 | \description{ 49 | \code{soils_latlng} pulls forecasted soil temp/moisutre data from aWhere's API based on latitude & longitude 50 | } 51 | \details{ 52 | This function returns today's soil forecast plus the forecast for up to 15 more days. Forecasts are available 53 | in many sizes of hourly blocks, from hourly to daily. The data this function returns is 54 | the soil's temperature and volumetric moisture content for the location specified by latitude and longitude for multiple depths 55 | Default units are returned by the API. Latitude and longitude must be in decimal degrees. 56 | 57 | Note that when block_size = 1 the fields min/max will be NA 58 | 59 | The Weather APIs provide access to aWhere's agriculture-specific Weather Terrain system, 60 | and allows retrieval and integration of data across all different time ranges long term normals, 61 | daily observed, current weather, and forecasts. These APIs are designed for efficiency, 62 | allowing you to customize the responses to return just the attributes you need. 63 | 64 | Note about dates: The system does not adjust for any difference in dates between the location of the user 65 | and where data is being requested from. It is the responsibility of the user to ensure a valid 66 | date range is specified given any differences in timezone. These differences can have implications 67 | for whether a given date should be requested from the daily_observed functions or the forecast functions 68 | } 69 | \examples{ 70 | \dontrun{soils_latlng(latitude = 39.8282 71 | ,longitude = -98.5795 72 | ,day_start = as.character(Sys.Date()) 73 | ,day_end = as.character(Sys.Date() + 5) 74 | ,block_size = 12)} 75 | } 76 | \references{ 77 | https://docs.awhere.com/knowledge-base-docs/forecast-weather-by-geolocation/ 78 | } 79 | -------------------------------------------------------------------------------- /man/update_field.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/update.R 3 | \name{update_field} 4 | \alias{update_field} 5 | \title{Update Field} 6 | \usage{ 7 | update_field( 8 | field_id, 9 | variable_update, 10 | value_update, 11 | keyToUse = awhereEnv75247$uid, 12 | secretToUse = awhereEnv75247$secret, 13 | tokenToUse = awhereEnv75247$token, 14 | apiAddressToUse = awhereEnv75247$apiAddress 15 | ) 16 | } 17 | \arguments{ 18 | \item{field_id}{the unique field ID for the field you want to update (character string) (required)} 19 | 20 | \item{variable_update}{the variable that needs to be updated, either "farmId", "name", or "acres" 21 | (character string) (required)} 22 | 23 | \item{value_update}{the new value for variable_update, to replace the existing value. The existing 24 | value can be found using get_fields("field_id") (character string) (required)} 25 | 26 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 27 | 28 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 29 | 30 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 31 | 32 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 33 | } 34 | \value{ 35 | - A message confirming the changes have been made 36 | } 37 | \description{ 38 | \code{update_field} To update details (Farm ID or FieldName) of a particular location in the aWhere API. 39 | } 40 | \details{ 41 | Fields are the easiest way to manage locations in the aWhere APIs, providing an easy reference 42 | for tracking weather, agronomics, models, and progress over growing seasons. Once a field is 43 | registered, plantings can also be registered for that field with specific information about the 44 | crop planted at that location, the date of planting, and other optional information. 45 | 46 | Occasionally, you may need to update the details of your field. At this time, only the farm ID, 47 | field Name, and number of acres can be updated using this function. Field details can only be 48 | updated one variable at a time, for one field at a time. If you need to update multiple fields or 49 | multiple variables associated with a field, please pass commands sequentially. 50 | } 51 | \examples{ 52 | \dontrun{update_field(field_id = 'field_test',variable_update = 'farmId', value_update = 'This is my territory')} 53 | } 54 | \references{ 55 | https://docs.awhere.com/knowledge-base-docs/update-a-field-location/ 56 | } 57 | -------------------------------------------------------------------------------- /man/update_planting.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/update.R 3 | \name{update_planting} 4 | \alias{update_planting} 5 | \title{Update Planting} 6 | \usage{ 7 | update_planting( 8 | field_id, 9 | planting_id, 10 | planting_date = "", 11 | proj_yield_amount = "", 12 | proj_yield_units = "", 13 | proj_harvest_date = "", 14 | yield_amount = "", 15 | yield_units = "", 16 | harvest_date = "", 17 | keyToUse = awhereEnv75247$uid, 18 | secretToUse = awhereEnv75247$secret, 19 | tokenToUse = awhereEnv75247$token, 20 | apiAddressToUse = awhereEnv75247$apiAddress 21 | ) 22 | } 23 | \arguments{ 24 | \item{field_id}{ID of field to search for plantings within} 25 | 26 | \item{planting_id}{ID of planting to update} 27 | 28 | \item{planting_date}{new date to update as planting's plant date} 29 | 30 | \item{proj_yield_amount}{new amount to update as planting's projected yield amount} 31 | 32 | \item{proj_yield_units}{new units to update as planting's projected yield units} 33 | 34 | \item{proj_harvest_date}{new projected harvest date to update as planting's projected harvest date} 35 | 36 | \item{yield_amount}{new amount to update as planting's yield amount} 37 | 38 | \item{yield_units}{new units to update as planting's yield units} 39 | 40 | \item{harvest_date}{new actual harvest date to update as planting's harvest date} 41 | 42 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 43 | 44 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 45 | 46 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 47 | 48 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 49 | } 50 | \value{ 51 | - A message confirming the changes have been made 52 | } 53 | \description{ 54 | \code{update_planting} To update details of a particular planting 55 | } 56 | \details{ 57 | Occasionally you will need to update a planting, changing the projections 58 | or recording the end-of-season information for historical tracking and model tuning. 59 | This API supports both partial and complete updates of plantings. When updating an 60 | entire planting, the whole object is replaced in the database. Any properties that 61 | were previously set, and now are not, will be null'd. The required properties must 62 | also be set even if they are changed. 63 | } 64 | \examples{ 65 | \dontrun{update_planting("field_test", "156036", harvest_date = "2016-02-01", yield_amount = "60", yield_units = "Bushels")} 66 | 67 | } 68 | \references{ 69 | https://docs.awhere.com/knowledge-base-docs/update-all-or-part-of-a-planting-in-a-field/ 70 | } 71 | -------------------------------------------------------------------------------- /man/verify_api_calls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/verify-api-calls.R 3 | \name{verify_api_calls} 4 | \alias{verify_api_calls} 5 | \title{Verify User Wants Make API Calls} 6 | \usage{ 7 | verify_api_calls(grid, bypassNumCallCheck) 8 | } 9 | \arguments{ 10 | \item{grid}{data frame returned from create_awhere_grid} 11 | } 12 | \description{ 13 | \code{verify_api_calls} Tells user how many api calls will be made to pull the data requested 14 | } 15 | -------------------------------------------------------------------------------- /man/weather_norms_area.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weather-norms.R 3 | \name{weather_norms_area} 4 | \alias{weather_norms_area} 5 | \title{weather_norms_area} 6 | \usage{ 7 | weather_norms_area( 8 | polygon, 9 | monthday_start, 10 | monthday_end, 11 | year_start, 12 | year_end, 13 | propertiesToInclude = "", 14 | exclude_years = NULL, 15 | includeFeb29thData = TRUE, 16 | numcores = 2, 17 | bypassNumCallCheck = FALSE, 18 | returnSpatialData = FALSE, 19 | verbose = TRUE, 20 | maxTryCount = 3, 21 | keyToUse = awhereEnv75247$uid, 22 | secretToUse = awhereEnv75247$secret, 23 | tokenToUse = awhereEnv75247$token, 24 | apiAddressToUse = awhereEnv75247$apiAddress 25 | ) 26 | } 27 | \arguments{ 28 | \item{polygon}{either a data.frame with column names lat/lon, SpatialPolygons object, 29 | well-known text string, or extent from raster package. If the object contains 30 | multiple polygons, the union of them is used. Information from each individal 31 | polygon can be retrieved by returning spatial data and using 32 | the over function from the sp package} 33 | 34 | \item{monthday_start}{character string of the first month and day for which you want to retrieve data, 35 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) (required)} 36 | 37 | \item{monthday_end}{character string of the last month and day for which you want to retrieve data, 38 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) (required)} 39 | 40 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 41 | you're calculating norms, in the form YYYY. e.g., 2008 (required)} 42 | 43 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 44 | you're calculating norms, in the form YYYY. e.g., 2015 (required)} 45 | 46 | \item{propertiesToInclude}{character vector of properties to retrieve from API. Valid values are meanTemp, maxTemp, minTemp, precipitation, solar, maxHumidity, minHumidity, dailyMaxWind (optional)} 47 | 48 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years. Because weather/agronomics 49 | summary statistics are calculated via the calendar date and 3 years are required 50 | to generate a value, data from this date is more likely to be NA. ALlows user 51 | to drop this data to avoid later problems (defaults to TRUE)} 52 | 53 | \item{numcores}{number of cores to use in parallel loop. To check number of available cores: parallel::detectCores(). 54 | If you receive an error regarding the speed you are making calls, reduce this number} 55 | 56 | \item{bypassNumCallCheck}{set to TRUE to avoid prompting the user to confirm that they want to begin making API calls} 57 | 58 | \item{returnSpatialData}{returns the data as a SpatialPixels object. Can be convered to raster with the command raster::stack 59 | NOTE: if multiple days worth of data is returned, it is necessary to subset to specific day for working with 60 | as spatial data (sp package: optional)} 61 | 62 | \item{verbose}{Set to TRUE tp print messages to console about state of parallization call. Typically only visible if run from console and not GUI} 63 | 64 | \item{maxTryCount}{maximum number of times a call is repeated if the the API returns an error. Random pause between each call} 65 | 66 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 67 | 68 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 69 | 70 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 71 | 72 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 73 | 74 | \item{exclude_year}{Year or years which you'd like to exclude from 75 | your range of years on which to calculate norms. To exclude 76 | multiple years, provide a vector of years. You must include 77 | at least three years of data with which to calculate the norms. (numeric, optional)} 78 | } 79 | \value{ 80 | data.frame of requested data for dates requested 81 | } 82 | \description{ 83 | \code{weather_norms_area} pulls long term norm weather data from aWhere's API based on a data.frame of lat/lon, polygon or extentt 84 | } 85 | \details{ 86 | This function allows you to calculate the averages for weather attributes 87 | across any range of years for which data are available. The data pulled includes 88 | meanTemp, maxTemp, minTemp, precipitation average, solar radiation average, 89 | minHumidity, maxHumidity, maxWind and averageWind, along with the standard deviations 90 | for these variables. The polygon should be either a SpatialPolygons object or 91 | a well-known text character string or an extent. 92 | 93 | The data returned in this function 94 | allow you to compare this year or previous years to the long-term normals, calculated as 95 | the average of those weather conditions on that day in that location over the years specified. 96 | 97 | Note about dates: The system does not adjust for any difference in dates between the location of the user 98 | and where data is being requested from. It is the responsibility of the user to ensure a valid 99 | date range is specified given any differences in timezone. These differences can have implications 100 | for whether a given date should be requested from the daily_observed functions or the forecast functions. 101 | Furthermore, because this function can take as input locations that may be in different timezones, it is 102 | the responsibility of the user to either ensure that the date range specified is valid for all relevant 103 | locations or to break the query into pieces. 104 | } 105 | \examples{ 106 | \dontrun{weather_norms_area(polygon = raster::getData('GADM', country = "Gambia", level = 0, download = T) 107 | ,monthday_start = '02-01' 108 | ,monthday_end = '03-10' 109 | ,year_start = 2008 110 | ,year_end = 2015 111 | ,exclude_years = c(2010,2011) 112 | ,numcores = 2)} 113 | } 114 | \references{ 115 | https://docs.awhere.com/knowledge-base-docs/historical-weather-norms-by-geolocation/ 116 | } 117 | -------------------------------------------------------------------------------- /man/weather_norms_fields.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weather-norms.R 3 | \name{weather_norms_fields} 4 | \alias{weather_norms_fields} 5 | \title{weather_norms_fields} 6 | \usage{ 7 | weather_norms_fields( 8 | field_id, 9 | monthday_start, 10 | monthday_end, 11 | year_start, 12 | year_end, 13 | propertiesToInclude = "", 14 | exclude_years = NULL, 15 | includeFeb29thData = TRUE, 16 | keyToUse = awhereEnv75247$uid, 17 | secretToUse = awhereEnv75247$secret, 18 | tokenToUse = awhereEnv75247$token, 19 | apiAddressToUse = awhereEnv75247$apiAddress 20 | ) 21 | } 22 | \arguments{ 23 | \item{field_id}{the field_id associated with the location for which you want to pull data. 24 | Field IDs are created using the create_field function. (string)} 25 | 26 | \item{monthday_start}{character string of the first month and day for which you want to retrieve data, 27 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) (required)} 28 | 29 | \item{monthday_end}{character string of the last month and day for which you want to retrieve data, 30 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) (required)} 31 | 32 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 33 | you're calculating norms, in the form YYYY. e.g., 2008 (required)} 34 | 35 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 36 | you're calculating norms, in the form YYYY. e.g., 2015 (required)} 37 | 38 | \item{propertiesToInclude}{character vector of properties to retrieve from API. 39 | Valid values are meanTemp, maxTemp, minTemp, precipitation, 40 | solar, maxHumidity, minHumidity, dailyMaxWind (optional)} 41 | 42 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years. Because weather/agronomics 43 | summary statistics are calculated via the calendar date and 3 years are required 44 | to generate a value, data from this date is more likely to be NA. ALlows user 45 | to drop this data to avoid later problems (defaults to TRUE)} 46 | 47 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 48 | 49 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 50 | 51 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 52 | 53 | \item{apiAddressToUse}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 54 | 55 | \item{exclude_year}{Year or years which you'd like to exclude from 56 | your range of years on which to calculate norms. To exclude 57 | multiple years, provide a vector of years. You must include 58 | at least three years of data with which to calculate the norms. (numeric, optional)} 59 | } 60 | \value{ 61 | dataframe of requested data for dates requested 62 | } 63 | \description{ 64 | \code{weather_norms_fields} pulls long term norm weather data from aWhere's API based on field id 65 | } 66 | \details{ 67 | This function allows you to calculate the averages for weather attributes 68 | across any range of years for which data are available. The data pulled includes 69 | meanTemp, maxTemp, minTemp, precipitation average, solar radiation average, 70 | minHumidity, maxHumidity, maxWind and averageWind, along with the standard deviations 71 | for these variables. The data pulled is for the field id identified. 72 | 73 | The data returned in this function 74 | allow you to compare this year or previous years to the long-term normals, calculated as 75 | the average of those weather conditions on that day in that location over the years specified. 76 | 77 | Note about dates: The system does not adjust for any difference in dates between the location of the user 78 | and where data is being requested from. It is the responsibility of the user to ensure a valid 79 | date range is specified given any differences in timezone. These differences can have implications 80 | for whether a given date should be requested from the daily_observed functions or the forecast functions 81 | } 82 | \examples{ 83 | \dontrun{weather_norms_fields(field_id = "field_test" 84 | ,monthday_start = "06-01" 85 | ,monthday_end = "09-01" 86 | ,year_start = 2006 87 | ,year_end = 2015)} 88 | } 89 | \references{ 90 | https://docs.awhere.com/knowledge-base-docs/historical-weather-norms/ 91 | } 92 | -------------------------------------------------------------------------------- /man/weather_norms_latlng.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/weather-norms.R 3 | \name{weather_norms_latlng} 4 | \alias{weather_norms_latlng} 5 | \title{weather_norms_latlng} 6 | \usage{ 7 | weather_norms_latlng( 8 | latitude, 9 | longitude, 10 | monthday_start, 11 | monthday_end, 12 | year_start, 13 | year_end, 14 | propertiesToInclude = "", 15 | exclude_years = NULL, 16 | includeFeb29thData = TRUE, 17 | keyToUse = awhereEnv75247$uid, 18 | secretToUse = awhereEnv75247$secret, 19 | tokenToUse = awhereEnv75247$token, 20 | apiAddressToUse = awhereEnv75247$apiAddress 21 | ) 22 | } 23 | \arguments{ 24 | \item{latitude}{the latitude of the requested location (double, required)} 25 | 26 | \item{longitude}{the longitude of the requested locations (double, required)} 27 | 28 | \item{monthday_start}{character string of the first month and day for which you want to retrieve data, 29 | in the form: MM-DD. This is the start of your date range. e.g. '07-01' (July 1) (required)} 30 | 31 | \item{monthday_end}{character string of the last month and day for which you want to retrieve data, 32 | in the form: MM-DD. This is the end of your date range. e.g. '07-01' (July 1) (required)} 33 | 34 | \item{year_start}{character string of the starting year (inclusive) of the range of years for which 35 | you're calculating norms, in the form YYYY. e.g., 2008 (required)} 36 | 37 | \item{year_end}{character string of the last year (inclusive) of the range of years for which 38 | you're calculating norms, in the form YYYY. e.g., 2015 (required)} 39 | 40 | \item{propertiesToInclude}{character vector of properties to retrieve from API. 41 | Valid values are meanTemp, maxTemp, minTemp, precipitation, 42 | solar, maxHumidity, minHumidity, dailyMaxWind (optional)} 43 | 44 | \item{includeFeb29thData}{Whether to keep data from Feb 29th on leap years. Because weather/agronomics 45 | summary statistics are calculated via the calendar date and 3 years are required 46 | to generate a value, data from this date is more likely to be NA. ALlows user 47 | to drop this data to avoid later problems (defaults to TRUE)} 48 | 49 | \item{keyToUse}{aWhere API key to use. For advanced use only. Most users will not need to use this parameter (optional)} 50 | 51 | \item{secretToUse}{aWhere API secret to use. For advanced use only. Most users will not need to use this parameter (optional)} 52 | 53 | \item{tokenToUse}{aWhere API token to use. For advanced use only. Most users will not need to use this parameter (optional)} 54 | 55 | \item{exclude_year}{Year or years which you'd like to exclude from 56 | your range of years on which to calculate norms. To exclude 57 | multiple years, provide a vector of years. You must include 58 | at least three years of data with which to calculate the norms. (numeric, optional)} 59 | 60 | \item{apiAddressToUse:}{Address of aWhere API to use. For advanced use only. Most users will not need to use this parameter (optional)} 61 | } 62 | \value{ 63 | data.frame of requested data for dates requested 64 | } 65 | \description{ 66 | \code{weather_norms_latlng} pulls long term norm weather data from aWhere's API based on latitude & longitude 67 | } 68 | \details{ 69 | This function allows you to calculate the averages for weather attributes 70 | across any range of years for which data are available. The data pulled includes 71 | meanTemp, maxTemp, minTemp, precipitation average, solar radiation average, 72 | minHumidity, maxHumidity, maxWind and averageWind, along with the standard deviations 73 | for these variables. The data pulled is for the latitude & longitude identified. 74 | 75 | The data returned in this function 76 | allow you to compare this year or previous years to the long-term normals, calculated as 77 | the average of those weather conditions on that day in that location over the years specified. 78 | 79 | Note about dates: The system does not adjust for any difference in dates between the location of the user 80 | and where data is being requested from. It is the responsibility of the user to ensure a valid 81 | date range is specified given any differences in timezone. These differences can have implications 82 | for whether a given date should be requested from the daily_observed functions or the forecast functions 83 | } 84 | \examples{ 85 | \dontrun{weather_norms_latlng(latitude = 39.8282 86 | ,longitude = -98.5795 87 | ,monthday_start = '02-01' 88 | ,monthday_end = '03-10' 89 | ,year_start = 2008 90 | ,year_end = 2015 91 | ,exclude_years = c(2010,2011))} 92 | } 93 | \references{ 94 | https://docs.awhere.com/knowledge-base-docs/historical-weather-norms-by-geolocation/ 95 | } 96 | -------------------------------------------------------------------------------- /previousVignettes/aWhereAPI.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE------------------------------------------------ 2 | knitr::opts_chunk$set(echo = TRUE) 3 | 4 | ## ------------------------------------------------------------------------ 5 | 6 | library(aWhereAPI) 7 | 8 | 9 | ## ------------------------------------------------------------------------ 10 | load_credentials("C:/aWhere/credentials/credentials.txt") 11 | 12 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(aWhereAPI) 3 | 4 | test_check("aWhereAPI") 5 | get_token("yizhexu@awhere.com", "181225tiancai@X") 6 | -------------------------------------------------------------------------------- /tests/testthat/credential.txt: -------------------------------------------------------------------------------- 1 | yizhexu@awhere.com 2 | 181225tiancai@X 3 | -------------------------------------------------------------------------------- /tests/testthat/test-agronomics.R: -------------------------------------------------------------------------------- 1 | load_credentials("credential.txt") 2 | 3 | test_that("get agonomic daily works", { 4 | create_field("field123","39.8282","-98.5795","farmA","Some Field Location","100") 5 | 6 | result <- agronomic_values_fields('field123','2015-07-01','2015-07-31') 7 | expect_is(result, "data.frame") 8 | 9 | result <- agronomic_values_fields('field123', '2015-03-01') 10 | expect_is(result, "data.frame") 11 | 12 | result <- agronomic_values_fields('field123','2015-03-01','2015-05-01','','standard','10','10','30') 13 | expect_is(result, "data.frame") 14 | 15 | result <- agronomic_values_fields("field123", day_start = "2016-07-01", day_end = "2016-07-31", accumulation_start_date = "2016-06-01", gdd_method = "modifiedstandard", gdd_base_temp = "10", gdd_min_boundary = "10", gdd_max_boundary = "30") 16 | expect_is(result, "data.frame") 17 | }) 18 | 19 | test_that("get agonomic daily works", { 20 | result <- agronomic_values_latlng('39.8282', '-98.5795','2015-07-01','2015-07-31') 21 | expect_is(result, "data.frame") 22 | 23 | result <- agronomic_values_latlng('39.8282', '-98.5795', '2015-03-01') 24 | expect_is(result, "data.frame") 25 | 26 | result <- agronomic_values_latlng('39.8282', '-98.5795','2015-03-01','2015-05-01','','standard','10','10','30') 27 | expect_is(result, "data.frame") 28 | 29 | result <- agronomic_values_latlng('39.8282', '-98.5795', day_start = "2016-07-01", day_end = "2016-07-31", accumulation_start_date = "2016-06-01", gdd_method = "modifiedstandard", gdd_base_temp = "10", gdd_min_boundary = "10", gdd_max_boundary = "30") 30 | expect_is(result, "data.frame") 31 | }) 32 | 33 | test_that("get agronomic_norms_fields norm works", { 34 | result <- agronomic_norms_fields('field123','07-01', '07-10', '2008', '2015','2010,2011','','standard','10','10','30') 35 | 36 | expect_is(result, "data.frame") 37 | }) 38 | 39 | test_that("get agronomic_norms_latlng norm works", { 40 | result <- agronomic_norms_latlng('39.8282', '-98.5795','07-01', '07-10', '2008', '2015','2010,2011','','standard','10','10','30') 41 | 42 | expect_is(result, "data.frame") 43 | # clean up 44 | delete_field("field123") 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/test-create-delete-update.R: -------------------------------------------------------------------------------- 1 | load_credentials("credential.txt") 2 | 3 | test_that("create fields works", { 4 | create_field("field123","39.8282","-98.5795","farmA","Some Field Location","100") 5 | result <- get_fields('field123')$field_id %>% as.character() 6 | expect_equal(result, "field123") 7 | }) 8 | 9 | test_that("create planting works", { 10 | id <- create_planting(field_id='field123',crop='corn',planting_date='2015-10-25',proj_yield_amount='100',proj_yield_units='Bushels', proj_harvest_date='2016-02-01',yield_amount='110',yield_units='Bushels',harvest_date='2016-02-01') 11 | result <- get_planting('field123', current = T)$planting_id 12 | expect_equal(result, id) 13 | }) 14 | 15 | # test_that("create jobs works", { 16 | # id <- create_job(c("GET /v2/weather/fields/field123/observations", "GET /v2/weather/fields/field123/observations"), c("field123", "field123"), "job_1") 17 | # expect_type(get_job(id), "list") 18 | # }) 19 | 20 | test_that("update field works", { 21 | update_field(field_id = 'field123', 22 | variable_search = 'farmId', value_search = 'farmA', 23 | variable_update = 'farmId', value_update = 'This is my territory') 24 | expect_equal("This is my territory", get_fields('field123')$farmId %>% as.character()) 25 | }) 26 | 27 | test_that("update planting works", { 28 | id <- get_planting('field123', current = T)$planting_id 29 | update_planting("field123", id, harvest_date = "2016-02-01", yield_amount = "60", yield_units = "Bushels") 30 | expect_equal(get_planting('field123', current = T)$actualHarvestDate %>% as.character(), "2016-02-01") 31 | expect_equal(get_planting('field123', current = T)$yieldAmount %>% as.character(), "60") 32 | }) 33 | 34 | test_that("delete planting works", { 35 | result <- get_planting('field123', current = T)$planting_id 36 | delete_planting("field123", result) 37 | expect_error(get_planting('field123', result)) 38 | }) 39 | 40 | test_that("delete field works", { 41 | delete_field("field123") 42 | expect_error(get_fields('field123')) 43 | }) 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/testthat/test-forecast.R: -------------------------------------------------------------------------------- 1 | load_credentials("credential.txt") 2 | 3 | test_that("get agonomic daily works", { 4 | create_field("field123","39.8282","-98.5795","farmA","Some Field Location","100") 5 | 6 | result <- forecasts_fields('field123') 7 | expect_is(result, "data.frame") 8 | 9 | result <- forecasts_fields('field123', block_size = 12) 10 | expect_is(result, "data.frame") 11 | 12 | result <- forecasts_fields('field123', as.character(Sys.Date()+3), block_size = 12) 13 | expect_is(result, "data.frame") 14 | }) 15 | 16 | 17 | test_that("get weather norm works", { 18 | result <- forecasts_latlng('39.8282', '-98.5795') 19 | expect_is(result, "data.frame") 20 | 21 | result <- forecasts_latlng('39.8282', '-98.5795', block_size = 12) 22 | expect_is(result, "data.frame") 23 | 24 | result <- forecasts_latlng('39.8282', '-98.5795', as.character(Sys.Date()+3), block_size = 12) 25 | expect_is(result, "data.frame") 26 | 27 | # clean up 28 | delete_field("field123") 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-get-token.R: -------------------------------------------------------------------------------- 1 | test_that("get token works as expected", { 2 | load_credentials("credential.txt") 3 | }) 4 | -------------------------------------------------------------------------------- /tests/testthat/test-get.R: -------------------------------------------------------------------------------- 1 | load_credentials("credential.txt") 2 | 3 | test_that("get fields works", { 4 | result <- get_fields('field1')$field_id %>% as.character() 5 | expect_equivalent(result, "field1") 6 | }) 7 | 8 | test_that("get plantings works", { 9 | result <- get_planting(field_id = 'field1', planting_id = '73227')$planting_id 10 | expect_equivalent(result, 73227) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-weather.R: -------------------------------------------------------------------------------- 1 | load_credentials("credential.txt") 2 | 3 | test_that("get weather daily works", { 4 | create_field("field123","39.8282","-98.5795","farmA","Some Field Location","100") 5 | 6 | result <- daily_observed_fields('field123') 7 | expect_is(result, "data.frame") 8 | 9 | result <- daily_observed_fields('field123', '2015-03-01') 10 | expect_is(result, "data.frame") 11 | 12 | result <- daily_observed_fields('field123','2015-03-01','2015-05-01') 13 | expect_is(result, "data.frame") 14 | }) 15 | 16 | test_that("get weather daily works", { 17 | result <- daily_observed_latlng('39.8282', '-98.5795') 18 | expect_is(result, "data.frame") 19 | 20 | result <- daily_observed_latlng('39.8282', '-98.5795', '2015-03-01') 21 | expect_is(result, "data.frame") 22 | 23 | result <- daily_observed_latlng('39.8282', '-98.5795','2015-03-01','2015-05-01') 24 | expect_is(result, "data.frame") 25 | }) 26 | 27 | test_that("get weather norm works", { 28 | result <- weather_norms_fields('field123', monthday_start = '07-01', monthday_end = '07-10', year_start = '2008', year_end = '2015') 29 | expect_is(result, "data.frame") 30 | 31 | result <- weather_norms_fields('field123', monthday_start = '07-01', monthday_end = '07-10', year_start = '2008', year_end = '2015', exclude_years = '2009,2013') 32 | expect_is(result, "data.frame") 33 | }) 34 | 35 | test_that("get weather norm works", { 36 | result <- weather_norms_latlng('39.8282', '-98.5795', monthday_start = '07-01', monthday_end = '07-10', year_start = '2008', year_end = '2015') 37 | expect_is(result, "data.frame") 38 | 39 | result <- weather_norms_latlng('39.8282', '-98.5795', monthday_start = '07-01', monthday_end = '07-10', year_start = '2008', year_end = '2015', exclude_years = '2009,2013') 40 | expect_is(result, "data.frame") 41 | 42 | # clean up 43 | delete_field("field123") 44 | }) 45 | -------------------------------------------------------------------------------- /vignettes/.build.timestamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aWhereAPI/aWhere-R-Library/452e9c6b3b254d8163df09dd0f0adf87f44f5e13/vignettes/.build.timestamp -------------------------------------------------------------------------------- /vignettes/Area_Analysis.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE------------------------------------------------ 2 | knitr::opts_chunk$set(echo = TRUE, 3 | eval=TRUE, 4 | message = FALSE, 5 | warning = FALSE, 6 | results='hide') 7 | 8 | ## ----load_packages------------------------------------------------------- 9 | # load required packages 10 | library(aWhereAPI) 11 | library(dplyr) 12 | 13 | # load credentials to access aWhere API 14 | aWhereAPI::load_credentials("credentials_trial.txt") 15 | 16 | ## ----detectCores, results=TRUE------------------------------------------- 17 | parallel::detectCores() 18 | 19 | -------------------------------------------------------------------------------- /vignettes/Installing_the_aWhere_API_Package.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Installing the aWhere API Package" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Installing the aWhere API Package} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | \usepackage[utf8]{inputenc} 8 | --- 9 | 10 | ```{r setup, include=FALSE} 11 | library(rmarkdown) 12 | knitr::opts_chunk$set(echo = TRUE) 13 | ``` 14 | 15 | ## Installing R and RStudio 16 | 17 | In order to download and use the aWhere API R package, the R programming language will need to be installed on your computer. You can download and install R here: . 18 | 19 | We also recommend installing RStudio for writing and developing your code. RStudio is a free program that includes many useful features and functions including code syntax highlighting, a GUI interface for writing and maintaining code, files, plots, etc. It is not necessary to use RStudio to use R, but it will make it easier. RStudio can be downloaded here: . 20 | 21 | 22 | ## Installing the aWhere API R package 23 | 24 | aWhere's API package for querying our API is hosted on GitHub and not R's central hub for installing packages, CRAN. In order to install the aWhere package directly from GitHub, we need to use a function from the devtools package. If you do not already have the devtools package installed on your computer, or are unsure, you can install it by running ```install.packages("devtools")``` in your R console. 25 | 26 | Once the devtools package is installed, you can install the aWhere API package by running ```devtools::install_github("aWhereAPI/aWhere-R-Library")```. 27 | 28 | The aWhere package references several other R packages in its inner functions. Therefore those packages must also be installed in order for the aWhere package to function as expected. If you run into issues when first installing the aWhere package, try installing these packages: ```install.packages(c('chron', 'magrittr', 'btcops', 'DBI', 'assertthat', 'Rcpp', 'tibble'))```, and then re-install the aWhere package. 29 | 30 | Upon re-install, if you are still presented with an error message stating that a certain package is not installed, use the ```install.packages()``` function to install the specified package. 31 | 32 | 33 | ```{r installPackages, eval=FALSE} 34 | library(devtools) 35 | 36 | #Run if packages are not already installed 37 | #install.packages(c('chron', 'magrittr', 'btcops', 'DBI', 'assertthat', 'Rcpp', 'tibble') 38 | 39 | devtools::install_github("aWhereAPI/aWhere-R-Library") 40 | 41 | ``` 42 | -------------------------------------------------------------------------------- /vignettes/credentials_trial.txt: -------------------------------------------------------------------------------- 1 | GkCWPxcGwcGhfRQv1tTDqO06NM9WecZE 2 | yg1g8a3SPtoc26FI 3 | https://api.awhere.com/v2/weather 4 | 5 | 6 | --------------------------------------------------------------------------------