{ "cells": [ { "cell_type": "markdown", "id": "cb0c350e", "metadata": {}, "source": [ "# Other Features\n", "## What haven't we covered\n" ] }, { "cell_type": "markdown", "id": "6b067d09", "metadata": {}, "source": [ "## Saving data\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "020ec7c9", "metadata": {}, "outputs": [], "source": [ "# we need imports\n", "from datetime import datetime\n", "import pandas as pd\n", "\n", "from metloom.pointdata import CDECPointData\n", "from metloom.variables import CdecStationVariables, SensorDescription" ] }, { "cell_type": "code", "execution_count": null, "id": "ec5c174d", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Let's save some timeseries data\n", "pt = CDECPointData(\"SLI\", \"Slide Canyon\")\n", "\n", "# start data and end date\n", "start_date = datetime(2019, 3, 1)\n", "end_date = datetime(2019, 4, 1)\n", "variables = [pt.ALLOWED_VARIABLES.SNOWDEPTH]\n", "\n", "# request the data\n", "df = pt.get_daily_data(start_date, end_date, variables)\n", "df.head(10)\n", "df.to_csv(\"./data/sli_data.csv\")\n", "\n", "# if you want to read it back in\n", "df2 = pd.read_csv(\"./data/sli_data.csv\")\n", "df2.head(10)" ] }, { "cell_type": "code", "execution_count": null, "id": "707aa772", "metadata": {}, "outputs": [], "source": [ "# Imports\n", "import geopandas as gpd\n", "from pathlib import Path\n", "\n", "from metloom.pointdata import SnotelPointData" ] }, { "cell_type": "code", "execution_count": null, "id": "67b80581", "metadata": {}, "outputs": [], "source": [ "# Let's save some points\n", "# Find your area\n", "sf_path = Path(\"./data/outline.shp\").expanduser()\n", "sf = gpd.read_file(str(sf_path))\n", "variables = [SnotelPointData.ALLOWED_VARIABLES.SNOWDEPTH]\n", "\n", "points = SnotelPointData.points_from_geometry(sf, variables)\n", "# convert to geodataframe and save\n", "points_df = points.to_dataframe()\n", "points_df.to_file(\"./data/my_points.geojson\")" ] }, { "cell_type": "markdown", "id": "1fa59ba8", "metadata": {}, "source": [ "## Extending classes\n", "\n", "What if we want a new variable?" ] }, { "cell_type": "code", "execution_count": null, "id": "45610366", "metadata": {}, "outputs": [], "source": [ "# Extend the variables to add our new sensor(s)\n", "# http://cdec4gov.water.ca.gov/reportapp/javareports?name=SensList\n", "class ExtendedCDECVars(CdecStationVariables):\n", " PEAKGUST = SensorDescription(\"77\", \"WIND GUST\", \"WIND, PEAK GUST\")\n", " \n", "# Extend the class to redefine the varaibles\n", "class ExtendedCDECPoints(CDECPointData):\n", " ALLOWED_VARIABLES = ExtendedCDECVars" ] }, { "cell_type": "code", "execution_count": null, "id": "369efdf4", "metadata": {}, "outputs": [], "source": [ "# use our new class to retrieve the data\n", "pt = ExtendedCDECPoints(\"GIN\", \"Gin Flat\")\n", "data = pt.get_daily_data(start_date, end_date, [pt.ALLOWED_VARIABLES.PEAKGUST])\n", "data" ] }, { "cell_type": "markdown", "id": "a552366d", "metadata": {}, "source": [ "## mesowest\n" ] }, { "cell_type": "markdown", "id": "604ecc62", "metadata": {}, "source": [ "Mesowest is a great resource to find an even wider selection of sensors.\n", "\n", "The metloom documentation has instructions for setting up your free API token that allows you to read data from the mesonet API with the `MesowestPointData` class. \n", "\n", "See the resources below:\n", "\n", "https://metloom.readthedocs.io/en/latest/usage.html#mesowest\n", "\n", "https://developers.synopticdata.com/mesonet/" ] }, { "cell_type": "code", "execution_count": null, "id": "e3ecd762", "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.9.18" } }, "nbformat": 4, "nbformat_minor": 5 }