Skip to content

Instantly share code, notes, and snippets.

@KMarkert
Last active April 8, 2024 12:08
Show Gist options
  • Select an option

  • Save KMarkert/21b5b45e72d3f091592cac0f2fee5cba to your computer and use it in GitHub Desktop.

Select an option

Save KMarkert/21b5b45e72d3f091592cac0f2fee5cba to your computer and use it in GitHub Desktop.

Revisions

  1. KMarkert revised this gist Apr 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nwm_api_demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@
    {
    "cell_type": "code",
    "source": [
    "'# change api_endpoint to what was deployed in your env'\n",
    "# change api_endpoint to what was deployed in your env\n",
    "api_endpoint = 'https://nwm-api.ciroh.org/forecast'\n",
    "\n",
    "api_key = 'YOUR-API-KEY'"
  2. KMarkert revised this gist Apr 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nwm_api_demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@
    {
    "cell_type": "code",
    "source": [
    "# change api_endpoint to what was deployed in your env",
    "'# change api_endpoint to what was deployed in your env'\n",
    "api_endpoint = 'https://nwm-api.ciroh.org/forecast'\n",
    "\n",
    "api_key = 'YOUR-API-KEY'"
  3. KMarkert revised this gist Apr 8, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nwm_api_demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@
    {
    "cell_type": "code",
    "source": [
    "# change api_endpoint to what was deployed in your env
    "# change api_endpoint to what was deployed in your env",
    "api_endpoint = 'https://nwm-api.ciroh.org/forecast'\n",
    "\n",
    "api_key = 'YOUR-API-KEY'"
  4. KMarkert revised this gist Apr 8, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion nwm_api_demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -30,9 +30,10 @@
    {
    "cell_type": "code",
    "source": [
    "# change api_endpoint to what was deployed in your env
    "api_endpoint = 'https://nwm-api.ciroh.org/forecast'\n",
    "\n",
    "api_key = 'AIzaSyDEEsdo0lm2aOmPX9NxGEncyVYGtwhsfMc'"
    "api_key = 'YOUR-API-KEY'"
    ],
    "metadata": {
    "id": "8duLVmFjx722",
  5. KMarkert created this gist Apr 8, 2024.
    215 changes: 215 additions & 0 deletions nwm_api_demo.ipynb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,215 @@
    {
    "cells": [
    {
    "cell_type": "code",
    "id": "HekFLPPAksz5uQith0kBakhg",
    "metadata": {
    "tags": [],
    "id": "HekFLPPAksz5uQith0kBakhg",
    "executionInfo": {
    "status": "ok",
    "timestamp": 1712542342938,
    "user_tz": 300,
    "elapsed": 3,
    "user": {
    "displayName": "",
    "userId": ""
    }
    }
    },
    "source": [
    "import pandas as pd\n",
    "import requests\n",
    "from io import StringIO\n",
    "\n",
    "pd.options.plotting.backend = \"plotly\""
    ],
    "execution_count": 1,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "api_endpoint = 'https://nwm-api.ciroh.org/forecast'\n",
    "\n",
    "api_key = 'AIzaSyDEEsdo0lm2aOmPX9NxGEncyVYGtwhsfMc'"
    ],
    "metadata": {
    "id": "8duLVmFjx722",
    "executionInfo": {
    "status": "ok",
    "timestamp": 1712542350457,
    "user_tz": 300,
    "elapsed": 200,
    "user": {
    "displayName": "",
    "userId": ""
    }
    }
    },
    "id": "8duLVmFjx722",
    "execution_count": 2,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "reference_time = '2023-03-05'\n",
    "ensemble_member = 0\n",
    "reach_id = 15039097"
    ],
    "metadata": {
    "id": "44hsjh02yFGu",
    "executionInfo": {
    "status": "ok",
    "timestamp": 1712542351780,
    "user_tz": 300,
    "elapsed": 2,
    "user": {
    "displayName": "",
    "userId": ""
    }
    }
    },
    "id": "44hsjh02yFGu",
    "execution_count": 3,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "header = {\n",
    " 'x-api-key': api_key\n",
    "}\n",
    "\n",
    "params = {\n",
    " 'forecast_type': 'long_range',\n",
    " 'reference_time': reference_time,\n",
    " 'ensemble': ensemble_member,\n",
    " 'comids': reach_id,\n",
    " 'output_format': 'csv'\n",
    "}"
    ],
    "metadata": {
    "id": "-QZDOfXHx969",
    "executionInfo": {
    "status": "ok",
    "timestamp": 1712542352817,
    "user_tz": 300,
    "elapsed": 2,
    "user": {
    "displayName": "",
    "userId": ""
    }
    }
    },
    "id": "-QZDOfXHx969",
    "execution_count": 4,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "r = requests.get(api_endpoint, params=params, headers=header)\n",
    "df = pd.read_csv(StringIO(r.text))"
    ],
    "metadata": {
    "id": "pJFQeTalyKUn",
    "executionInfo": {
    "status": "ok",
    "timestamp": 1712542354722,
    "user_tz": 300,
    "elapsed": 1141,
    "user": {
    "displayName": "",
    "userId": ""
    }
    }
    },
    "id": "pJFQeTalyKUn",
    "execution_count": 5,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "df.set_index('time',inplace=True)"
    ],
    "metadata": {
    "id": "SY0P6bqp0slb",
    "executionInfo": {
    "status": "ok",
    "timestamp": 1712542355922,
    "user_tz": 300,
    "elapsed": 2,
    "user": {
    "displayName": "",
    "userId": ""
    }
    }
    },
    "id": "SY0P6bqp0slb",
    "execution_count": 6,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "df"
    ],
    "metadata": {
    "id": "pZaIvB1pyPS6"
    },
    "id": "pZaIvB1pyPS6",
    "execution_count": null,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [
    "df['streamflow'].plot(labels=dict(value=\"streamflow [cms]\"))"
    ],
    "metadata": {
    "id": "W19nja6gyRmj"
    },
    "id": "W19nja6gyRmj",
    "execution_count": null,
    "outputs": []
    },
    {
    "cell_type": "code",
    "source": [],
    "metadata": {
    "id": "bOxJtu-tyqEs"
    },
    "id": "bOxJtu-tyqEs",
    "execution_count": null,
    "outputs": []
    }
    ],
    "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.10.10"
    },
    "colab": {
    "provenance": [],
    "name": "nwm-api-demo"
    }
    },
    "nbformat": 4,
    "nbformat_minor": 5
    }