Skip to content

Instantly share code, notes, and snippets.

@KMarkert
Last active April 8, 2024 12:08
Show Gist options
  • Save KMarkert/21b5b45e72d3f091592cac0f2fee5cba to your computer and use it in GitHub Desktop.
Save KMarkert/21b5b45e72d3f091592cac0f2fee5cba to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"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": [
"# 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'"
],
"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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment