{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Download NWM Retrospective Point Data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Import the required packages.\n", "import os\n", "\n", "import teehr.loading.nwm.retrospective_points as nwm_retro\n", "from pathlib import Path\n", "from datetime import datetime\n", "\n", "from dask.distributed import Client" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set Variables \n", "Set variables to specify what NWM version to download, the time period, location IDs, and where to save the files." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "NWM_VERSION = \"nwm20\"\n", "VARIABLE_NAME = \"streamflow\"\n", "START_DATE = datetime(2000, 1, 1)\n", "END_DATE = datetime(2000, 1, 2, 23)\n", "LOCATION_IDS = [7086109, 7040481]\n", "\n", "OUTPUT_ROOT = Path(Path().home(), \"temp\")\n", "OUTPUT_DIR = Path(OUTPUT_ROOT, \"nwm20_retrospective\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Start a dask cluster to improve performance.\n", "n_workers = max(os.cpu_count() - 1, 1)\n", "client = Client(n_workers=n_workers)\n", "client" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fetch and Load to the Data Model" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "%%time\n", "nwm_retro.nwm_retro_to_parquet(\n", " nwm_version=NWM_VERSION,\n", " variable_name=VARIABLE_NAME,\n", " start_date=START_DATE,\n", " end_date=END_DATE,\n", " location_ids=LOCATION_IDS,\n", " output_parquet_dir=OUTPUT_DIR\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12" } }, "nbformat": 4, "nbformat_minor": 4 }