{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nWork with Crops in aWherePy\n===========================\n\nLearn how to get crop information with aWherePy.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Get Crop Information with aWherePy.\n-----------------------------------\n\n<div class=\"alert alert-info\"><h4>Note</h4><p>The example below will show you how to use the ``get_crops()`` function to\n   get a list of all available crops or a single crop from the aWhere API.</p></div>\n\nIn this vignette, you will first get all crops, and then you will get a\nsingle crop by random choice from the list of available crops.\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Import Packages\n---------------\n\nIn order to use the functionality in this example, the following packages\nneed to be imported.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os\nimport random\nimport awherepy.crops as awc"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Prerequisites\n-------------\n\nIn order to make calls to any aWhere API, you must provide a valid API key\nand secret. The key and secret used in this example are stored as\nenvironment variables.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Define aWhere API key and secret\nawhere_api_key = os.environ.get(\"AWHERE_API_KEY\")\nawhere_api_secret = os.environ.get(\"AWHERE_API_SECRET\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Get All Crops\n-------------\n\nTo get a dataframe with all available aWhere crops, you use the\n``get_crops()`` function with default parameters. This can be useful for\ncases when you need information about all crops, in the aWhere API, as\nopposed to a single crop.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Get all crops\nall_crops = awc.get_crops(key=awhere_api_key, secret=awhere_api_secret)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Get a Single Crop\n-----------------\n\nTo get a dataframe with a single aWhere crop, you use the ``get_crops()``\nfunction and include the specific crop ID. This example selects a random crop\nID from the list of all available crops.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Get single crop\nsingle_crop = awc.get_crops(\n    key=awhere_api_key,\n    secret=awhere_api_secret,\n    crop_id=random.choice(awc.CROPS_LIST),\n)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}