|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/docs/notebooks/152_extract_timeseries_to_points.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n", |
| 9 | + "\n", |
| 10 | + "Uncomment the following line to install [geemap](https://geemap.org) if needed." |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "id": "1", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "# %pip install -U geemap" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "markdown", |
| 25 | + "id": "2", |
| 26 | + "metadata": {}, |
| 27 | + "source": [ |
| 28 | + "## Import libraries" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": null, |
| 34 | + "id": "3", |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "import matplotlib.pyplot as plt\n", |
| 39 | + "import ee\n", |
| 40 | + "import geemap" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "id": "4", |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [], |
| 49 | + "source": [ |
| 50 | + "Map = geemap.Map()\n", |
| 51 | + "Map" |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "markdown", |
| 56 | + "id": "5", |
| 57 | + "metadata": {}, |
| 58 | + "source": [ |
| 59 | + "## Specify Latitude, Longitude, & Date" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": null, |
| 65 | + "id": "6", |
| 66 | + "metadata": {}, |
| 67 | + "outputs": [], |
| 68 | + "source": [ |
| 69 | + "# Define the latitude and longitude\n", |
| 70 | + "lat = 28.60\n", |
| 71 | + "lon = 77.22\n", |
| 72 | + "\n", |
| 73 | + "# Define time range\n", |
| 74 | + "start_date = \"2000-01-01\"\n", |
| 75 | + "end_date = \"2015-12-31\"" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "id": "7", |
| 81 | + "metadata": {}, |
| 82 | + "source": [ |
| 83 | + "## Extract ERA5-Land Daily Timeseries" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "code", |
| 88 | + "execution_count": null, |
| 89 | + "id": "8", |
| 90 | + "metadata": {}, |
| 91 | + "outputs": [], |
| 92 | + "source": [ |
| 93 | + "# Initialize image collection\n", |
| 94 | + "image_collection = ee.ImageCollection(\"ECMWF/ERA5_LAND/DAILY_AGGR\")\n", |
| 95 | + "\n", |
| 96 | + "# Define bands of interest (must match available band names exactly)\n", |
| 97 | + "band_names = [\"temperature_2m_min\", \"temperature_2m_max\", \"total_precipitation_sum\"]\n", |
| 98 | + "\n", |
| 99 | + "# Define the scale\n", |
| 100 | + "scale = 11132\n", |
| 101 | + "\n", |
| 102 | + "# Extract time series at specified latitude and longitude\n", |
| 103 | + "result = geemap.extract_timeseries_to_point(\n", |
| 104 | + " lat=lat,\n", |
| 105 | + " lon=lon,\n", |
| 106 | + " image_collection=image_collection,\n", |
| 107 | + " band_names=band_names,\n", |
| 108 | + " start_date=start_date,\n", |
| 109 | + " end_date=end_date,\n", |
| 110 | + " scale=scale,\n", |
| 111 | + ")\n", |
| 112 | + "\n", |
| 113 | + "# Preview results\n", |
| 114 | + "print(result.shape)\n", |
| 115 | + "result.head()" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "markdown", |
| 120 | + "id": "9", |
| 121 | + "metadata": {}, |
| 122 | + "source": [ |
| 123 | + "## Extract CHIRPS Daily Precipitation Timeseries" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "id": "10", |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [], |
| 132 | + "source": [ |
| 133 | + "# Initialize image collection\n", |
| 134 | + "image_collection = ee.ImageCollection(\"UCSB-CHG/CHIRPS/DAILY\")\n", |
| 135 | + "\n", |
| 136 | + "# Define the band name\n", |
| 137 | + "band_names = [\"precipitation\"]\n", |
| 138 | + "\n", |
| 139 | + "# Define the scale\n", |
| 140 | + "scale = 5566\n", |
| 141 | + "\n", |
| 142 | + "# Extract time series at specified latitude and longitude\n", |
| 143 | + "result = geemap.extract_timeseries_to_point(\n", |
| 144 | + " lat=lat,\n", |
| 145 | + " lon=lon,\n", |
| 146 | + " image_collection=image_collection,\n", |
| 147 | + " band_names=band_names,\n", |
| 148 | + " start_date=start_date,\n", |
| 149 | + " end_date=end_date,\n", |
| 150 | + " scale=scale,\n", |
| 151 | + ")\n", |
| 152 | + "\n", |
| 153 | + "# Preview results\n", |
| 154 | + "print(result.shape)\n", |
| 155 | + "result.head()" |
| 156 | + ] |
| 157 | + }, |
| 158 | + { |
| 159 | + "cell_type": "markdown", |
| 160 | + "id": "11", |
| 161 | + "metadata": {}, |
| 162 | + "source": [ |
| 163 | + "## Extract MODIS Terra Vegetation Indices Timeseries" |
| 164 | + ] |
| 165 | + }, |
| 166 | + { |
| 167 | + "cell_type": "code", |
| 168 | + "execution_count": null, |
| 169 | + "id": "12", |
| 170 | + "metadata": {}, |
| 171 | + "outputs": [], |
| 172 | + "source": [ |
| 173 | + "# Initialize image collection\n", |
| 174 | + "image_collection = ee.ImageCollection(\"MODIS/061/MOD13Q1\")\n", |
| 175 | + "\n", |
| 176 | + "# Define the band names\n", |
| 177 | + "band_names = [\"NDVI\", \"EVI\"]\n", |
| 178 | + "\n", |
| 179 | + "# Define the scale\n", |
| 180 | + "scale = 250\n", |
| 181 | + "\n", |
| 182 | + "# Extract time series at specified latitude and longitude\n", |
| 183 | + "result = geemap.extract_timeseries_to_point(\n", |
| 184 | + " lat=28.60,\n", |
| 185 | + " lon=77.22,\n", |
| 186 | + " image_collection=image_collection,\n", |
| 187 | + " band_names=band_names,\n", |
| 188 | + " start_date=start_date,\n", |
| 189 | + " end_date=end_date,\n", |
| 190 | + " scale=scale,\n", |
| 191 | + ")\n", |
| 192 | + "\n", |
| 193 | + "# Preview results\n", |
| 194 | + "print(result.shape)\n", |
| 195 | + "result.head()" |
| 196 | + ] |
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "markdown", |
| 200 | + "id": "13", |
| 201 | + "metadata": {}, |
| 202 | + "source": [ |
| 203 | + "## Plot the Timeseries" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "code", |
| 208 | + "execution_count": null, |
| 209 | + "id": "14", |
| 210 | + "metadata": {}, |
| 211 | + "outputs": [], |
| 212 | + "source": [ |
| 213 | + "# Simple plot\n", |
| 214 | + "plt.figure(figsize=(12, 5))\n", |
| 215 | + "\n", |
| 216 | + "for band in [\"NDVI\", \"EVI\"]:\n", |
| 217 | + " plt.plot(\n", |
| 218 | + " result[\"time\"], result[band] * 0.0001, label=band\n", |
| 219 | + " ) # apply scale factor of 0.0001\n", |
| 220 | + "\n", |
| 221 | + "plt.title(f\"NDVI & EVI Time Series at {lat, lon}\")\n", |
| 222 | + "plt.xlabel(\"Date\")\n", |
| 223 | + "plt.ylabel(\"Value\")\n", |
| 224 | + "plt.legend()\n", |
| 225 | + "plt.tight_layout()\n", |
| 226 | + "plt.show()" |
| 227 | + ] |
| 228 | + } |
| 229 | + ], |
| 230 | + "metadata": { |
| 231 | + "kernelspec": { |
| 232 | + "display_name": "geo", |
| 233 | + "language": "python", |
| 234 | + "name": "geo" |
| 235 | + }, |
| 236 | + "language_info": { |
| 237 | + "codemirror_mode": { |
| 238 | + "name": "ipython", |
| 239 | + "version": 3 |
| 240 | + }, |
| 241 | + "file_extension": ".py", |
| 242 | + "mimetype": "text/x-python", |
| 243 | + "name": "python", |
| 244 | + "nbconvert_exporter": "python", |
| 245 | + "pygments_lexer": "ipython3", |
| 246 | + "version": "3.12.11" |
| 247 | + } |
| 248 | + }, |
| 249 | + "nbformat": 4, |
| 250 | + "nbformat_minor": 5 |
| 251 | +} |
0 commit comments