aWhere API R Package (Complete Documentation)

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

Installation

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.

Automatically Install

This package can be installed directly from GitHub with the following command:

devtools::install_github("aWhereAPI/aWhere-R-Library")

Manually Install

  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.

  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:

    • setwd("C:\Users\USERNAME\Desktop")
  3. Run the following set of commands to install and add the library to your environment:

    • library(devtools)
    • install("aWhere-R-Library-master")
    • library(aWhereAPI)

Usage

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.

Using Credentials Directly

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.

Loading Credentials from a Saved File

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.

API Functions Available

Contents

___________

Field Locations

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.


Create a Field

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

Function Signature
create_field(field_id, latitude, longitude, farm_id, field_name, acres)
Parameters
Example
create_field("field456","40.8282","-100.5795","farmA","Some Field Location","100")

Get Field Information

This function will return the field information saved in the aWhere Platform. API Documentation

Function Signature
get_fields(field_id)
Parameters
Example
get_fields('field123')

Update Field Information

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

Function Signature
update_field(field_id, variable_search, value_search, variable_update, value_update)
Parameters
Examples

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')

Delete Field Information

To delete a Field Location created with create_field(). API Documentation

Function Signature
delete_field(field_id, variable_search, value_search, variable_update, value_update)
Parameters
Examples
delete_field('fieldId')

___________

Plantings

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.


Create a Planting

Use this function to create a Planting for a Field Location. API Documentation

Function Signature
create_planting(field_id, crop, planting_date, proj_yield_amount, proj_yield_units, proj_harvest_date, yield_amount, yield_units, harvest_date)
Parameters
Example
create_planting('field123', 'corn', '2015-07-01')

Get Planting Information

Use this function to retrieve information about the planting. API Documentation

Function Signature
get_planting(field_id, planting_id, current)
Parameters
Example

This example returns the most current (most recent) planting for field123:

get_planting('field123','',T)

Update Planting Information

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

Function Signature
update_planting(field_id, crop, planting_date, proj_yield_amount, proj_yield_units, proj_harvest_date, yield_amount, yield_units, harvest_date)
Parameters

Delete a Planting

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

Function Signature
delete_planting(field_id, planting_id)
Parameters
Example
delete_planting("field123", 32481941)

___________

Weather Data

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.


Observations (Daily History)

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

Function Signatures

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)
Parameters
Examples

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')

Forecast

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

Function Signatures

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)
Parameters
Examples

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)

Long Term Norms

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

Function Signatures

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)
Parameters
Example
weather_norms_latlng('39.8282', '-98.5795','07-01','07-31','2010','2015')

Current Conditions

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

Function Signatures

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)
Parameters
Example

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')

___________

Agronomic Data

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

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

Function Signatures

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)
Parameters
Example
agronomic_values_latlng('39.8282', '-98.5795','2015-07-01','2015-07-31','2015-06-01','modifiedstandard','10','10','30')

Agronomic Norms

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.

Function Signatures

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)
Parameters
Example
agronomic_norms_latlng('39.8282', '-98.5795','07-01','07-31','2010','2015')


aWhereAPI/aWhere-R-Library documentation built on Nov. 5, 2021, 3:35 a.m.