|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## Get the stations" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": null, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "from searvey._chs_api import get_chs_stations\n", |
| 17 | + "\n", |
| 18 | + "all_stations = get_chs_stations()" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "## Plot them in a map" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "code", |
| 30 | + "execution_count": null, |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "import geopandas as gpd\n", |
| 35 | + "import hvplot.pandas\n", |
| 36 | + "import pandas as pd\n", |
| 37 | + "def plot_map(data, title):\n", |
| 38 | + " # Plot the world map\n", |
| 39 | + " world_plot = data.hvplot(geo=True, tiles=True, hover_cols=[\"id\",\"officialName\"], title=title)\n", |
| 40 | + " return world_plot.opts(width=800, height=500)\n", |
| 41 | + "\n", |
| 42 | + "plot_map(all_stations, 'CHS Stations')" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "markdown", |
| 47 | + "metadata": {}, |
| 48 | + "source": [ |
| 49 | + "## Get stations from a specific region and plot them" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "from shapely.geometry import box\n", |
| 59 | + "# Define a rectangular region\n", |
| 60 | + "region = box(-150, 40, -110, 60) # Longitude range, Latitude range\n", |
| 61 | + "\n", |
| 62 | + "# Get stations within the region\n", |
| 63 | + "east_coast_stations = get_chs_stations(region=region)\n", |
| 64 | + "plot_map(east_coast_stations, 'CHS Stations on the East Coast of Canada')" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "markdown", |
| 69 | + "metadata": {}, |
| 70 | + "source": [ |
| 71 | + "## Get data from a specific CHS station\n", |
| 72 | + "To get data from a specific station you need to input one of the codes below:\n", |
| 73 | + "\n", |
| 74 | + "- wlo - Observed water level\n", |
| 75 | + "- wlf or wlf-spine - predicted water levels (at operational stations only)\n", |
| 76 | + "- wlp - Predicted water levels\n", |
| 77 | + "- wlp-hilo High and low sea predictions (Tide tables)\n", |
| 78 | + "\n", |
| 79 | + "Note: Some stations may not support a specific code/type of data" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": null, |
| 85 | + "metadata": {}, |
| 86 | + "outputs": [], |
| 87 | + "source": [ |
| 88 | + "from searvey._chs_api import fetch_chs_station\n", |
| 89 | + "# Get data for selected stations\n", |
| 90 | + "data_df = fetch_chs_station(\n", |
| 91 | + " station_id=\"5cebf1e33d0f4a073c4bc23e\",\n", |
| 92 | + " time_series_code=\"wlo\",\n", |
| 93 | + " start_date=\"2023-01-08\",\n", |
| 94 | + " end_date=\"2023-01-10\",\n", |
| 95 | + ")\n", |
| 96 | + "\n", |
| 97 | + "data_df" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "metadata": {}, |
| 103 | + "source": [ |
| 104 | + "## Get data from multiple stations" |
| 105 | + ] |
| 106 | + }, |
| 107 | + { |
| 108 | + "cell_type": "code", |
| 109 | + "execution_count": null, |
| 110 | + "metadata": {}, |
| 111 | + "outputs": [], |
| 112 | + "source": [ |
| 113 | + "import pandas as pd\n", |
| 114 | + "from searvey._chs_api import _fetch_chs\n", |
| 115 | + "\n", |
| 116 | + "multiple_data_df = _fetch_chs(\n", |
| 117 | + " station_ids=[\"5cebf1de3d0f4a073c4bbad5\",\"5cebf1e33d0f4a073c4bc23e\"],\n", |
| 118 | + " time_series_code=\"wlo\",\n", |
| 119 | + " start_dates=pd.DatetimeIndex([\"2023-01-08\"]*2),\n", |
| 120 | + " end_dates=pd.DatetimeIndex([\"2023-01-11\"]*2),\n", |
| 121 | + ")\n", |
| 122 | + "\n", |
| 123 | + "multiple_data_df[\"5cebf1de3d0f4a073c4bbad5\"]" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "markdown", |
| 128 | + "metadata": {}, |
| 129 | + "source": [ |
| 130 | + "## Plot the data" |
| 131 | + ] |
| 132 | + }, |
| 133 | + { |
| 134 | + "cell_type": "code", |
| 135 | + "execution_count": null, |
| 136 | + "metadata": {}, |
| 137 | + "outputs": [], |
| 138 | + "source": [ |
| 139 | + "data_df[\"value\"].hvplot(title=\"CHS values\", xlabel=\"Index\", ylabel=\"Value\")\n" |
| 140 | + ] |
| 141 | + } |
| 142 | + ], |
| 143 | + "metadata": { |
| 144 | + "kernelspec": { |
| 145 | + "display_name": "Python 3 (ipykernel)", |
| 146 | + "language": "python", |
| 147 | + "name": "python3" |
| 148 | + }, |
| 149 | + "language_info": { |
| 150 | + "codemirror_mode": { |
| 151 | + "name": "ipython", |
| 152 | + "version": 3 |
| 153 | + }, |
| 154 | + "file_extension": ".py", |
| 155 | + "mimetype": "text/x-python", |
| 156 | + "name": "python", |
| 157 | + "nbconvert_exporter": "python", |
| 158 | + "pygments_lexer": "ipython3", |
| 159 | + "version": "3.10.16" |
| 160 | + } |
| 161 | + }, |
| 162 | + "nbformat": 4, |
| 163 | + "nbformat_minor": 4 |
| 164 | +} |
0 commit comments