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.
Note: These functions will only return metric units
Note: Prior to installation you will need a working installation of R.
Note: You will need to have the devtools library installed in R. Consult documentation if necessary.
This package can be installed directly from GitHub with the following command:
devtools::install_github("aWhereAPI/aWhere-R-Library")
Download this Github repo and keep the aWhere-R-Library-master
folder somewhere useful on your computer, such as your Desktop or My Documents.
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:
setwd("C:\Users\USERNAME\Desktop")
Run the following set of commands to install and add the library to your environment:
library(devtools)
install("aWhere-R-Library-master")
library(aWhereAPI)
In order to use any of the functions in this package, or the APIs in general, you will need API credentials provided by aWhere. These keys are used to generate an Access Token, which is then passed to each API to authenticate the request. This R package will handle token generation and usage automatically, but you will need to get API keys first.
To get API keys, follow these instructions at the aWhere Developer Community. Note that normally the API Key and Secret are made up of random characters.
Prior to using of the any other functions, you'll need to use get_token()
function to generate a token. Pass the API Key and API Secret from aWhere as the two parameters to this function. For example:
get_token("JFKL24JF290FJSKAFDF","jf0afsd9af0a")
You could also save the key and secret as variables. This function saves the token to a direct child of the base environment for use by any other aWhere function.
An alternative approach is to save your credentials to an external text file and use the load_credentials()
function to load them into the environment and generate a token.
First, create a text file on your computer. Enter your API Key on the first line, and your Secret on the second, then press return/enter to create an empty third line. Save the file and note the complete path to it. For example, this might be C:\Users\USERNAME\Desktop\credentials.txt
.
In R, supply the path to the credentials file to the function:
load_credentials("C:\Users\USERNAME\Desktop\credentials.txt")
This function invokes get_token()
so no further work is needed to generate an Access Token.
Contents
By default, aWhere's APIs use Field Locations to reference the locations you wish to request data for. This is most common for tracking agricultural values over a growing season. Learn more at the aWhere Developer Community.
Use this function to create a Field Location in the aWhere Platform. You'll use the ID for this field when referencing the location in other functions. API Documentation
create_field(field_id, latitude, longitude, farm_id, field_name, acres)
field
(character)latitude
(numeric)longitude
(numeric)farm_id
(character) field_name
(character)acres
(numeric)create_field("field456","40.8282","-100.5795","farmA","Some Field Location","100")
This function will return the field information saved in the aWhere Platform. API Documentation
get_fields(field_id)
field_id
(character)get_fields('field123')
If you want to change certain properties about the Field Location, use this function. Note that at this time only the name or farm ID can be changed. API Documentation
update_field(field_id, variable_search, value_search, variable_update, value_update)
field_id
(character)variable_search
(character)value_search
(character)variableToSearch
matches this value, then the next property will be changed. Otherwise no update will happen.variable_update
(character)variableToSearch
, but you could opt to change one property only if the other matches valueToSearch
value_update
(character)variableToChange
This example will change the farmId to "TestFarmA" only if it current matches "ABC":
update_field('fieldId', 'ABC', 'farmId', 'TestFarmA')
This example will change the name of the field only if the farm ID matches "TestFarmA":
update_field('fieldId', 'TestFarmA', 'name', 'Primary Test Farm')
To delete a Field Location created with create_field(). API Documentation
delete_field(field_id, variable_search, value_search, variable_update, value_update)
field_id
(character)delete_field('fieldId')
Whereas Field Locations define a physical location, Planting records record information about the crop and growing season. They are used when automatically calculating agronomic values since the start of a growing season. Learn more at the aWhere Developer Community.
Use this function to create a Planting for a Field Location. API Documentation
create_planting(field_id, crop, planting_date, proj_yield_amount, proj_yield_units, proj_harvest_date, yield_amount, yield_units, harvest_date)
field_id
(character)crop
(character)planting_date
(character) proj_yield_amount
(numeric)proj_yield_units
(character)proj_yield_amount
such as "bushels"proj_yield_amount
is supplied.proj_harvest_date
(character)yield_amount
yield_units
yield_amount
, such as "bushels"amount
is suppliedharvest_date
create_planting('field123', 'corn', '2015-07-01')
Use this function to retrieve information about the planting. API Documentation
get_planting(field_id, planting_id, current)
field_id
(character)planting_id
(numeric)current
(boolean)This example returns the most current (most recent) planting for field123:
get_planting('field123','',T)
Use this function to update the details about a Planting record. Note that once a planting is created the crop information cannot be changed (delete a the Planting record and create a new one instead). API Documentation
update_planting(field_id, crop, planting_date, proj_yield_amount, proj_yield_units, proj_harvest_date, yield_amount, yield_units, harvest_date)
field_id
(character)planting_id
(numeric)planting_date
(character) proj_yield_amount
(numeric)proj_yield_units
(character)proj_yield_amount
such as "bushels"proj_yield_amount
is supplied.proj_harvest_date
(character)yield_amount
yieldUnits
yield_amount
, such as "bushels"yield_amount
is suppliedharvest_date
If you want to keep your planting records clean for reporting and historical tracking purposes you can delete errant or incorrect plantings using this function. API Documentation
delete_planting(field_id, planting_id)
field_id
(character)planting_id
(numeric)delete_planting("field123", 32481941)
The aWhere Platform provides agriculturally relevant weather data globally. There are two approaches to retrieving weather data for a location: either use the Field Location ID created with the functions above, or you can request weather data by latitude-longitude. Either is acceptable depending on the terms of your agreement with aWhere. If you intend to use aWhere's modeling capabilities in the future, you should create Field Locations and Plantings.
All weather data requests are requested point by point. There is not a way to download regional data in a single API call. Use the batch jobs system when requesting a large amount of data (e.g., many hundreds or thousands of points).
Learn more about the weather data we provide and our Weather Data APIs at the aWhere Developer Community.
This function uses the Observations API to retrieve observed weather data for any given day. By default, you can request daily data from up to 30 months ago. For data beyond that, use the Norms API (function below) to calculate long-term norms. Or, speak with your aWhere representative for access to more of the daily data archive. API Documentation
This function uses the Field Location ID to reference a location:
daily_observed_fields(field_id, day_start, day_end)
This function uses just a latitude-longitude (no Field Location required):
daily_observed_latlng(latitude, longitude, day_start, day_end)
field_id
(character)latitude
and longitude
(numerics)day_start
(character)day_end
(character)day_start
is, then the API returns data only for a single dayday_start
Return a single day of data for a Field Location ID:
daily_observed_fields("field123", "2015-07-01")
Return two weeks of data for a geolocation:
daily_observed_latlng('39.8282', '-98.5795', '2015-07-01','2015-07-14')
Retrieve the forecast for today plus up to the next 8 days with this function. The forecast is available at multiple temporal resolutions - in 1, 2, 3, 4, 6, 8, 12, or 24-hour summary blocks. API Documentation
This function uses the Field Location ID to reference a location:
forecasts_fields(field_id, day_start, day_end, block_size)
This function uses just a latitude-longitude (no Field Location required):
forecasts_latlng(latitude, longitude, day_start, day_end, block_size)
field_id
(character)latitude
and longitude
(numerics)day_start
(character)day_end
(character)day_start
is, then the API returns data only for a single dayday_start
block_size
(numeric)Return a single day of data for a Field Location ID (hourly resolution)
forecasts_fields("field123", "2016-02-29")
Return the daily forecast for the next three days, requested for a geolocation:
forecasts_latlng('39.8282', '-98.5795', '2016-02-29','2016-03-02', 24)
The Weather Norms API allows you to offload the calculation of multi-year averages for any days of the year across any number of years for which we have data (minimum 3). This eliminates the need, most of the time, to download years and years of daily data just to calculate averages. The results also include the standard deviation for each average. API Documentation
This function uses the Field Location ID to reference a location:
weather_norms_fields(field_id, monthday_start, monthday_end, year_start, year_end, exclude_years)
This function uses just a latitude-longitude (no Field Location required):
weather_norms_latlng(latitude, longitude, monthday_start, monthday_end, year_start, year_end, exclude_years)
field_id
(character)latitude
and longitude
(numerics)monthday_start
(character)monthday_end
(character)monthday_start
is, then the API returns data only for a single dayyear_start
(character)year_end
(character)year_start
is used then this is requiredexclude_years
(character)weather_norms_latlng('39.8282', '-98.5795','07-01','07-31','2010','2015')
The Current Conditions API returns a snapshot of area weather for a location using recent data from the nearest available station. While the data is QA'd before delivery, this service does not do the same advanced processing or interpolation as Daily Observed data. API Documentation
This function uses the Field Location ID to reference a location:
current_conditions_fields(field_id, sources)
This function uses just a latitude-longitude (no Field Location required):
current_conditions_latlng(latitude, longitude, sources)
field_id
(character)latitude
and longitude
(numerics)sources
(character)This example excludes personal weather stations and returns the data from nearest METAR or MESONET station:
current_conditions_latlng('39.8282', '-98.5795', 'metar-mesonet')
aWhere provides a rich set of agronomic values that adds deeper layers of insight on top of weather data alone. These functions provide quick access to derived values like GDD or PET, and the long-term norms for each value. Like the Weather APIs there are two approaches to retrieving weather data for a location: either use the Field Location ID created with the functions above, or you can request weather data by latitude-longitude. Either is acceptable depending on the terms of your agreement with aWhere. If you intend to use aWhere's modeling capabilities in the future, you should create Field Locations and Plantings.
All weather data requests are requested point by point. There is not a way to download regional data in a single API call. Use the batch jobs system when requesting a large amount of data (e.g., many hundreds or thousands of points).
Learn more at the aWhere Developer Community
Agronomic Values are calculated numbers that can be used to show the agronomic status of a field or crop. The aWhere platform can calculate GDD (using a variety of different equations), PET (using the Penman-Monteith Equation), P/PET, and accumulated precipitation, accumulated GDD, accumulated PET, and P/PET over a range of days. API Documentation
This function uses the Field Location ID to reference a location:
agronomic_values_fields(field_id, day_start, day_end, accumulation_start_date, gdd_method, gdd_base_temp, gdd_min_boundary, gdd_max_boundary)
This function uses just a latitude-longitude (no Field Location required):
agronomic_values_latlng(field_id, day_start, day_end, accumulation_start_date, gdd_method, gdd_base_temp, gdd_min_boundary, gdd_max_boundary)
field_id
(character)latitude
and longitude
(numerics)day_start
(character)day_end
(character)day_start
is, then the API returns data only for a single dayday_start
accumulation_start_date
(character)day_start
enter that date hereday_start
, and cannot be more than a year before the current date.gdd_method
(character)gdd_base_temp
(numeric)gdd_min_boundary
(numeric)gdd_max_boundary
(numeric)agronomic_values_latlng('39.8282', '-98.5795','2015-07-01','2015-07-31','2015-06-01','modifiedstandard','10','10','30')
The Agronomic Norms API returns the long-term normals for the agronomic values on any given set of days across any range of years for which we have data. This allows you to calculate the desired averages without having to download huge data sets. API Documentation.
This function uses the Field Location ID to reference a location:
agronomic_norms_fields(field_id, monthday_start, monthday_end, year_start, year_end, exclude_years, accumulation_start_date, gdd_method, gdd_base_temp, gdd_min_boundary, gdd_max_boundary)
This function uses just a latitude-longitude (no Field Location required):
agronomic_norms_latlng(latitude, longitude, monthday_start, monthday_end, year_start, year_end, exclude_years, accumulation_start_date, gdd_method, gdd_base_temp, gdd_min_boundary, gdd_max_boundary)
field_id
(character)latitude
and longitude
(numerics)monthday_start
(character)monthday_end
(character)monthday_start
is, then the API returns data only for a single dayyear_start
(character)year_end
(character)year_start
is used then this is requiredexclude_years
(character)gdd_method
(character)gdd_base_temp
(numeric)gdd_min_boundary
(numeric)gdd_max_boundary
(numeric)agronomic_norms_latlng('39.8282', '-98.5795','07-01','07-31','2010','2015')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.