{ "cells": [ { "cell_type": "markdown", "id": "39a8c83c-4d90-498a-b1e0-078df578db42", "metadata": {}, "source": [ "# Geosphere Austria tutorial\n", "This tutorial walks through the use of a point data class for accessing station data in Austria\n", "A video tutorial of this notebook can be found [here](https://www.loom.com/share/fcced7c00c47400e9a2b8b7b017949e5?sid=6a4cc255-48d0-48f0-8e14-a8aed0ef4bb3)" ] }, { "cell_type": "code", "execution_count": null, "id": "da7e02c8-6932-4310-8108-7ad7f6bfbade", "metadata": {}, "outputs": [], "source": [ "# import metloom class https://data.hub.geosphere.at/dataset/\n", "from metloom.pointdata import GeoSphereHistPointData" ] }, { "cell_type": "code", "execution_count": null, "id": "ee565b4d-e25d-4f43-8d85-f3b9fef5b31b", "metadata": {}, "outputs": [], "source": [ "# import packages\n", "import geopandas as gpd\n", "import pandas as pd\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "id": "16111f97-d305-4358-9088-eccb5b18cf99", "metadata": {}, "outputs": [], "source": [ "# Install mapclassify and folium for gdf.explore()\n", "!pip install mapclassify\n", "!pip install folium" ] }, { "cell_type": "code", "execution_count": null, "id": "31656640-c479-4a2a-aa11-2ada3b5d6194", "metadata": {}, "outputs": [], "source": [ "# read and explore shape\n", "gdf = gpd.read_file(\"./data/geosphere_test.kml\")\n", "gdf.explore()" ] }, { "cell_type": "code", "execution_count": null, "id": "2fe8a969-ff71-4beb-8259-556c66309f25", "metadata": {}, "outputs": [], "source": [ "# Define variable of interest https://github.com/M3Works/metloom/blob/main/metloom/variables.py\n", "variable = GeoSphereHistPointData.ALLOWED_VARIABLES.TEMP\n", "# Get the points within our region of interest\n", "points = GeoSphereHistPointData.points_from_geometry(gdf, [variable])\n", "print(len(points))" ] }, { "cell_type": "code", "execution_count": null, "id": "028e0a56-aa66-43a7-b554-16dcfe2c35bc", "metadata": {}, "outputs": [], "source": [ "# Explore the points we located\n", "points_df = points.to_dataframe()\n", "points_df = points_df.set_crs(\"EPSG:4326\")\n", "\n", "points_df.explore()" ] }, { "cell_type": "code", "execution_count": null, "id": "bb075ff5-50a5-4de2-8362-511c669e61b5", "metadata": {}, "outputs": [], "source": [ "# define start and end date of interest\n", "start = pd.to_datetime(\"2023-01-01\")\n", "end = pd.to_datetime(\"2023-01-11\")" ] }, { "cell_type": "code", "execution_count": null, "id": "18544661-2f36-4097-b26f-2d6508acdc52", "metadata": {}, "outputs": [], "source": [ "# dataframe for storing combined data\n", "final_df = pd.DataFrame()\n", "\n", "# loop through first 15 points and store the data\n", "for p in points.points[:15]:\n", " result = p.get_daily_data(start, end, [variable])\n", " if result is None:\n", " print(f\"{p.name} did not return data\")\n", " else:\n", " # reset the index to just be datetime\n", " result = result.reset_index().set_index(\"datetime\")\n", " # store off the data in the final dataframe\n", " final_df[p.name + p.id] = result[variable.name]\n", "final_df" ] }, { "cell_type": "code", "execution_count": null, "id": "55be4633-430d-46bb-8c8d-9792bca0c365", "metadata": {}, "outputs": [], "source": [ "# Plot the timeseries\n", "final_df.plot(ylabel=variable.name)" ] }, { "cell_type": "code", "execution_count": null, "id": "73cde7e4-2e99-4a3d-a19a-5a2b909737b1", "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.12.9" } }, "nbformat": 4, "nbformat_minor": 5 }