@azure-rest/agrifood-farming
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.2 • Public • Published

Microsoft Azure Data Manager for Agriculture REST client library for JavaScript

Microsoft Azure Data Manager for Agriculture is a B2B PaaS offering from Microsoft that makes it easy for AgriFood companies to build intelligent digital agriculture solutions on Azure.Data Manager for Agriculture acquire, aggregate, and process agricultural data from various sources (farm equipment, weather, satellite) without the need to invest in deep data engineering resources.  Customers can build SaaS solutions on top of Data Manager for Agriculture and leverage first class support for model building to generate insights at scale.

Use Data Manager for Agriculture client library for JavaScript to do the following.

  • Create & update parties, farms, fields, seasonal fields and boundaries.
  • Ingest satellite and weather data for areas of interest.
  • Ingest farm operations data covering tilling, planting, harvesting and application of farm inputs.

Please rely heavily on the service's documentation and our REST client docs to use this library

Key links:

Getting started

Currently supported environments

  • Node.js version 14.x.x or higher

Prerequisites

Install the @azure-rest/agrifood-farming package

Install the Data Manager for Agriculture rest client library for JavaScript with npm:

npm install @azure-rest/agrifood-farming

Create and authenticate a Microsoft Azure Data Manager for Agriculture REST Client

To use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the @azure/identity library.

To authenticate with AAD, you must first npm install @azure/identity.

After setup, you can choose which type of credential from @azure/identity to use. As an example, DefaultAzureCredential can be used to authenticate the client:

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

Use the returned token credential to authenticate the client:

import FarmBeats from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";

const client = FarmBeats(
  "https://<farmbeats resource name>.farmbeats.azure.net",
  new DefaultAzureCredential()
);

Key concepts

REST Client

This client is one of our REST clients. We highly recommend you read how to use a REST client here.

Farm Hierarchy

Farm hierarchy is a collection of below entities.

  • Party - is the custodian of all the agronomic data.
  • Farm - is a logical collection of fields and/or seasonal fields. They do not have any area associated with them.
  • Field - is a multi-polygon area. This is expected to be stable across seasons.
  • Seasonal field - is a multi-polygon area. To define a seasonal boundary we need the details of area (boundary), time (season) and crop. New seasonal fields are expected to be created for every growing season.
  • Boundary - is the actual multi-polygon area expressed as a geometry (in geojson). It is normally associated with a field or a seasonal field. Satellite, weather and farm operations data is linked to a boundary.
  • Cascade delete - Agronomic data is stored hierarchically with party as the root. The hierarchy includes Party -> Farms -> Fields -> Seasonal Fields -> Boundaries -> Associated data (satellite, weather, farm operations). Cascade delete refers to the process of deleting any node and its subtree.

Scenes

Scenes refers to images normally ingested using satellite APIs. This includes raw bands and derived bands (Ex: NDVI). Scenes may also include spatial outputs of an inference or AI/ML model (Ex: LAI).

Farm Operations

Fam operations includes details pertaining to tilling, planting, application of pesticides & nutrients, and harvesting. This can either be manually pushed into FarmBeats using APIs or the same information can be pulled from farm equipment service providers like John Deere.

Examples

Create a Party

Once you have authenticated and created the client object as shown in the Authenticate the client section, you can create a party within the Data Manager for Agriculture resource like this:

import FarmBeats, { isUnexpected } from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";

const client = FarmBeats(
  "https://<farmbeats resource name>.farmbeats.azure.net",
  new DefaultAzureCredential()
);

const partyId = "test_party";
const result = await farmbeatsClient.path("/parties/{partyId}", partyId).patch({
  body: {
    name: "Contoso Party",
    description: "Your custom party description here",
    status: "Active",
    properties: { foo: "bar", "numeric one": 1, "1": "numeric key" },
  },
  // Set the content-type of the request
  contentType: "application/merge-patch+json",
});

if (isUnexpected(result)) {
  throw result.body.error;
}

const party = result.body;
console.log(`Created Party: ${party.name}`);

List Parties

import FarmBeats, { isUnexpected } from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";

const client = FarmBeats(
  "https://<farmbeats resource name>.farmbeats.azure.net",
  new DefaultAzureCredential()
);

const response = await farmbeatsClient.path("/parties").get();

if (isUnexpected(response)) {
  throw response.body.error;
}

const parties = paginate(farmbeatsClient, response);

// Log each party id
for await (const party of parties) {
  const partyOutput = party;
  console.log(partyOutput.id);
}

Additional Samples

For additional samples, please refer to the [samples folder][samples_folder]

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

import { setLogLevel } from "@azure/logger";

setLogLevel("info");

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.

Next steps

Additional documentation

For more extensive documentation on the FarmBeats, see the FarmBeats documentation on docs.microsoft.com.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

Related projects

Impressions

Package Sidebar

Install

npm i @azure-rest/agrifood-farming

Weekly Downloads

64

Version

1.0.0-beta.2

License

MIT

Unpacked Size

1.47 MB

Total Files

27

Last publish

Collaborators

  • microsoft1es
  • azure-sdk