Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions examples/forecast/forecast_instance.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ab7dc6e0",
"metadata": {},
"source": [
"# Forecast Examples\n"
]
},
{
"cell_type": "markdown",
"id": "aebb03ba",
"metadata": {},
"source": [
"**Example generated from:** [/tests/forecast/forecast_instance_test.py](https://github.com/HydrologicEngineeringCenter/cwms-python/tree/main/tests/forecast/forecast_instance_test.py)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ef634ce",
"metadata": {},
"outputs": [],
"source": [
"from cwms.api import init_session\n",
"from datetime import datetime\n",
"import pytz\n",
"import cwms.api\n",
"import cwms.forecast.forecast_instance as forecast_instance"
]
},
{
"cell_type": "markdown",
"id": "5f4f811e",
"metadata": {},
"source": [
"### Initializing the database and write access\n",
"cwms-python will connect by default to the USACE public database available through [CWMS Data](https://cwms-data.usace.army.mil/cwms-data/). \n",
"\n",
"https://cwms-data.usace.army.mil/cwms-data/\n",
"\n",
"The apiRoot can be updated to access data directly from a USACE district database.\n",
"* Endpoints on the [Swagger Docs page](https://cwms-data.usace.army.mil/cwms-data/swagger-ui.html) with a 🔒 icon require the apiKey be set."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7d282050",
"metadata": {},
"outputs": [],
"source": [
"api_root = \"https://cwms-data-test.cwbi.us/cwms-data/\"\n",
"api = init_session(api_root=api_root)"
]
},
{
"cell_type": "markdown",
"id": "96092ed1",
"metadata": {},
"source": [
"# GET Requests"
]
},
{
"cell_type": "markdown",
"id": "1488d21f",
"metadata": {},
"source": [
"## get forecast instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "646f90e3",
"metadata": {},
"outputs": [],
"source": [
"forecast = forecast_instance.get_forecast_instances(\"test-spec\", \"SWT\", \"designator\")\n"
]
},
{
"cell_type": "markdown",
"id": "afa15099",
"metadata": {},
"source": [
"## retrieve forecast instance json"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "76b2ffcd",
"metadata": {},
"outputs": [],
"source": [
"forecast_date = datetime.utcfromtimestamp(1624284010000 / 1000)\n",
"issue_date = datetime.utcfromtimestamp(1653221020000 / 1000)\n",
"forecast = forecast_instance.get_forecast_instance(\n",
" \"test-spec\", \"SWT\", \"designator\", forecast_date, issue_date\n",
")\n"
]
},
{
"cell_type": "markdown",
"id": "ed9bce32",
"metadata": {},
"source": [
"# STORE Requests"
]
},
{
"cell_type": "markdown",
"id": "3ce6a6e1",
"metadata": {},
"source": [
"## store forecast instance json"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "659193b8",
"metadata": {},
"outputs": [],
"source": [
"forecast_instance.store_forecast_instance(_FORECAST_INSTANCE_JSON)\n"
]
},
{
"cell_type": "markdown",
"id": "b733cbf7",
"metadata": {},
"source": [
"# DELETE Requests"
]
},
{
"cell_type": "markdown",
"id": "cfc52b02",
"metadata": {},
"source": [
"## delete forecast instance json"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55b01423",
"metadata": {},
"outputs": [],
"source": [
"forecast_date = datetime.utcfromtimestamp(1624284010000 / 1000)\n",
"issue_date = datetime.utcfromtimestamp(1653221020000 / 1000)\n",
"forecast_instance.delete_forecast_instance(\n",
" \"test-spec\", \"SWT\", \"designator\", forecast_date, issue_date\n",
")\n"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
162 changes: 162 additions & 0 deletions examples/forecast/forecast_spec.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5a0412fa",
"metadata": {},
"source": [
"# Forecast Examples\n"
]
},
{
"cell_type": "markdown",
"id": "e807fd07",
"metadata": {},
"source": [
"**Example generated from:** [/tests/forecast/forecast_spec_test.py](https://github.com/HydrologicEngineeringCenter/cwms-python/tree/main/tests/forecast/forecast_spec_test.py)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f27357f",
"metadata": {},
"outputs": [],
"source": [
"from cwms.api import init_session\n",
"import pytz\n",
"import cwms.api\n",
"import cwms.forecast.forecast_spec as forecast_spec\n",
"from cwms.cwms_types import DeleteMethod"
]
},
{
"cell_type": "markdown",
"id": "b901d06f",
"metadata": {},
"source": [
"### Initializing the database and write access\n",
"cwms-python will connect by default to the USACE public database available through [CWMS Data](https://cwms-data.usace.army.mil/cwms-data/). \n",
"\n",
"https://cwms-data.usace.army.mil/cwms-data/\n",
"\n",
"The apiRoot can be updated to access data directly from a USACE district database.\n",
"* Endpoints on the [Swagger Docs page](https://cwms-data.usace.army.mil/cwms-data/swagger-ui.html) with a 🔒 icon require the apiKey be set."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "45d5fbce",
"metadata": {},
"outputs": [],
"source": [
"api_root = \"https://cwms-data-test.cwbi.us/cwms-data/\"\n",
"api = init_session(api_root=api_root)"
]
},
{
"cell_type": "markdown",
"id": "6c35dcd9",
"metadata": {},
"source": [
"# GET Requests"
]
},
{
"cell_type": "markdown",
"id": "38156106",
"metadata": {},
"source": [
"## get forecast specs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "036cbba3",
"metadata": {},
"outputs": [],
"source": [
"forecast = forecast_spec.get_forecast_specs(\n",
" \"id_mask\", \"office_mask\", \"designator_mask\", \"source_entity\"\n",
")\n"
]
},
{
"cell_type": "markdown",
"id": "56ed6dd6",
"metadata": {},
"source": [
"## get forecast spec"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e701b235",
"metadata": {},
"outputs": [],
"source": [
"forecast = forecast_spec.get_forecast_spec(\"test-spec\", \"SWT\", \"designator\")\n"
]
},
{
"cell_type": "markdown",
"id": "c4beea74",
"metadata": {},
"source": [
"# STORE Requests"
]
},
{
"cell_type": "markdown",
"id": "be5bb3d5",
"metadata": {},
"source": [
"## store forecast spec json"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6b04f28",
"metadata": {},
"outputs": [],
"source": [
"forecast_spec.store_forecast_spec(_FORECAST_SPEC_JSON)\n"
]
},
{
"cell_type": "markdown",
"id": "4ccfb97b",
"metadata": {},
"source": [
"# DELETE Requests"
]
},
{
"cell_type": "markdown",
"id": "6ad09e7a",
"metadata": {},
"source": [
"## delete forecast spec"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c8f256e6",
"metadata": {},
"outputs": [],
"source": [
"forecast_spec.delete_forecast_spec(\n",
" \"test-spec\", \"SWT\", \"designator\", DeleteMethod.DELETE_KEY\n",
")\n"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
Loading